Beispiel #1
0
def createDatabase(database: str, mode: str, encoding: str) -> int:
    try:
        retorno = 3
        if encoding in ["ascii", "iso-8859-1", "utf8"]:
            if __buscarLlaveBaseDato(database) is None: 
                if mode ==  "avl":
                    retorno = avl.createDatabase(database)
                elif mode ==  "b":
                    retorno = b.createDatabase(database)
                elif mode ==  "bplus":
                    retorno = bPlus.createDatabase(database)
                elif mode ==  "dict":
                    retorno = dic.createDatabase(database)
                elif mode ==  "isam":
                    retorno = isam.createDatabase(database)
                elif mode ==  "json":
                    retorno = json.createDatabase(database)
                elif mode ==  "hash":
                    retorno = hash.createDatabase(database)
                else:
                    retorno = 3
                if retorno == 0:
                    generalDict.setdefault(database, [mode, encoding, {}, {}])
                    ser("data/info/datos.bin", generalDict)
                return retorno
            else:
                return 2
        else:
            return 4
    except Exception:
        return 1
Beispiel #2
0
def __createDatabase(database: str, mode: str, encoding: str) -> int:
    try:
        retorno = 3
        if encoding in ["ascii", "iso-8859-1", "utf8"]:
            if __buscarLlaveBaseDato(database) is not None: 
                if mode ==  "avl":
                    retorno = avl.createDatabase(database)
                elif mode ==  "b":
                    retorno = b.createDatabase(database)
                elif mode ==  "bplus":
                    retorno = bPlus.createDatabase(database)
                elif mode ==  "dict":
                    retorno = dic.createDatabase(database)
                elif mode ==  "isam":
                    retorno = isam.createDatabase(database)
                elif mode ==  "json":
                    retorno = json.createDatabase(database)
                elif mode ==  "hash":
                    retorno = hash.createDatabase(database)
                else:
                    retorno = 3
                
                return retorno
            else:
                return 2
        else:
            return 4
    except Exception:
        return 1
Beispiel #3
0
def createDatabase(database: str, mode: str, encoding: str):
    if verify_string(database):
        if exist(database): return 2
        if encoding.lower().strip() is "ascii" or encoding.lower().strip() is "iso-8859-1" \
                or encoding.lower().strip() is "utf8":
            status = -1
            if mode.lower().strip() is "avl":
                status = avl.createDatabase(database)
            elif mode.lower().strip() is "b":
                status = b.createDatabase(database)
            elif mode.lower().strip() is "bplus":
                status = bPlus.createDatabase(database)
            elif mode.lower().strip() is "dict":
                status = diccionario.createDatabase(database)
            elif mode.lower().strip() is "isam":
                status = isam.createDatabase(database)
            elif mode.lower().strip() is "json":
                status = json.createDatabase(database)
            elif mode.lower().strip() is "hash":
                status = hash.createDatabase(database)
            else:
                return 3
            if status == 0:
                save_mode(database, mode, encoding)
            return status
        else:
            return 4
    else:
        return 1
Beispiel #4
0
def createdatabase(db, modo, cod):
    if not modo in modos:
        return 3
    if not cod in encoding:
        return 4
    if buscar(db) == None:
        if modo == "avl":
            tmp = avl.createDatabase(db)

        elif modo == "b":
            tmp = b.createDatabase(db)

        elif modo == "bplus":
            tmp = bplus.createDatabase(db)

        elif modo == "hash":
            tmp = hash.createDatabase(db)

        elif modo == "isam":
            tmp = isam.createDatabase(db)

        elif modo == "json":
            tmp = json.createDatabase(db)

        elif modo == "dict":
            tmp = dict.createDatabase(db)
    else:
        return 2

    if tmp == 0:
        lista_db.append([db, modo, cod])
        return 0
    else:
        return 1
Beispiel #5
0
def chooseMode(mode, database):
    if mode == 'avl':
        if avl.createDatabase(database) == 0:
            avlList.append(database)
            return 0
        else:
            return avl.createDatabase(database)
    elif mode == 'b':
        if b.createDatabase(database) == 0:
            bList.append(database)
            return 0
        else:
            return b.createDatabase(database)
    elif mode == 'bplus':
        if bplus.createDatabase(database) == 0:
            bplusList.append(database)
            return 0
        else:
            return bplus.createDatabase(database)
    elif mode == 'dict':
        if DM.createDatabase(database) == 0:
            dictList.append(database)
            return 0
        else:
            return DM.createDatabase(database)
    elif mode == 'isam':
        if isam.createDatabase(database) == 0:
            isamList.append(database)
            return 0
        else:
            return isam.createDatabase(database)
    elif mode == 'json':
        if j.createDatabase(database) == 0:
            jsonList.append(database)
            return 0
        else:
            return j.createDatabase(database)
    elif mode == 'hash':
        if Hash.createDatabase(database) == 0:
            hashList.append(database)
            return 0
        else:
            return Hash.createDatabase(database)
Beispiel #6
0
def createDatabase(database: str, mode: str, encoding: str) -> int:
    """Creates a database

        Parameters:\n
            database (str): name of the database

        Returns:\n
            0: successful operation
            1: an error ocurred
            2: database name occupied
    """

    if not _Buscar(database):

        if encoding not in ["utf8", "ascii", "iso-8859-1"]:
            return 4

        if mode == "avl":
            val = avl.createDatabase(database)

        elif mode == "b":
            val = b.createDatabase(database)

        elif mode == "bplus":
            val = bplus.createDatabase(database)

        elif mode == "hash":
            val = hash.createDatabase(database)

        elif mode == "isam":
            val = isam.createDatabase(database)

        elif mode == "json":
            val = json.createDatabase(database)

        elif mode == "dict":
            val = dict.createDatabase(database)

        else:
            return 3

        if val == 0:
            lista_general.append([database, mode, encoding])
            serealizar.commit(lista_general, "data", _main_path)

        return val

    else:
        return 2
Beispiel #7
0
def createDatabase(database, mode, encoding):
    val = 1
    if encoding != "ascii" and encoding != "iso-8859-1" and encoding != "utf8":
        val = 4
    else:
        if mode == "avl":
            # Grupo 16
            val = avl_mode.createDatabase(database)
        elif mode == "b":
            # Grupo 17
            val = b_mode.createDatabase(database)
        elif mode == "bplus":
            # Grupo 18
            val = bplus_mode.createDatabase(database)
        elif mode == "dict":
            # Auxiliar
            val = dict_mode.createDatabase(database)
        elif mode == "isam":
            # Grupo 14
            val = isam_mode.createDatabase(database)
        elif mode == "json":
            # Ingeniero
            val = json_mode.createDatabase(database)
        elif mode == "hash":
            # Grupo 15
            val = hash_mode.createDatabase(database)
        else:
            val = 3
        if val == 0:
            global Bases
            try:
                # Leemos el archivo binario de los registros de bases de datos
                fichero_lectura = open("BD_register", "rb")
                Bases = pickle.load(fichero_lectura)
                Bases.update({database: {"mode": mode, "encoding": encoding}})
                # Actualizamos el archivo binario de los registros de bases de datos
                fichero_escritura = open("BD_register", "wb")
                pickle.dump(Bases, fichero_escritura)
                fichero_escritura.close()
            except:
                Bases.update({database: {"mode": mode, "encoding": encoding}})
                # Actualizamos el archivo binario de los registros de bases de datos
                fichero_escritura = open("BD_register", "wb")
                pickle.dump(Bases, fichero_escritura)
                fichero_escritura.close()
    return val
Beispiel #8
0
def _createDatabase(database, mode, encoding) -> int:
    """Creates a database

        Parameters:\n
            database (str): name of the database
            mode (str): mode of the database
            encoding (str): encoding of the database

        Returns:\n
            0: successful operation
            1: an error ocurred
            2: database name occupied
            3: non-valid mode
            4: non-valid encoding
    """

    if encoding not in ["utf8", "ascii", "iso-8859-1"]:
        return 4

    if mode == "avl":
        val = avl.createDatabase(database)

    elif mode == "b":
        val = b.createDatabase(database)

    elif mode == "bplus":
        val = bplus.createDatabase(database)

    elif mode == "hash":
        val = hash.createDatabase(database)

    elif mode == "isam":
        val = isam.createDatabase(database)

    elif mode == "json":
        val = json.createDatabase(database)

    elif mode == "dict":
        val = dict.createDatabase(database)

    else:
        return 3

    return val
Beispiel #9
0
def alterDatabaseMode(database: str, mode: str) -> int:
    try:
        valor = 1
        db = __buscarLlaveBaseDato(database)
        retorno = 1
        if db is not None:
            modeOld = db[0]
            tablas = showTables(database)
            codificacion = db[1]
                
            if mode == "avl":
                retorno = avl.createDatabase(database)
            elif mode == "b":
                retorno = b.createDatabase(database)
            elif mode == "bplus":
                retorno = bPlus.createDatabase(database)
            elif mode == "dict":
                retorno = dic.createDatabase(database)
            elif mode == "isam":
                retorno = isam.createDatabase(database)
            elif mode == "json":
                retorno = json.createDatabase(database)
            elif mode == "hash":
                retorno = hash.createDatabase(database)
            else:
                retorno = 4
            
            if retorno == 0 or retorno == 2:
                valor = __insertarDatosTablas(tablas, mode, modeOld, database, codificacion)
                retorno = valor
                dicc = db[2]
                if valor == 0:
                    dropDatabase(database)
                    db[0] = mode
                    db[2] = {}
                    generalDict[database] = db
                    ser("data/info/datos.bin", generalDict)
            return retorno
        else:
            return 2
    except Exception:
        return 1