Beispiel #1
0
def alterAddPK(database: str, table: str, columns: list) -> int:
    try:
        retorno = 1
        db = __buscarLlaveBaseDato(database)
        if db is not None:
            modoDB = db[0]
            tablas = db[2]
            if tablas:
                if tablas.get(table) is not None:
                    modoDB = tablas[table]
            if modoDB == "avl":
                retorno = avl.alterAddPK(database, table, columns)
            elif modoDB == "b":
                retorno = b.alterAddPK(database, table, columns)
            elif modoDB == "bplus":
                retorno = bPlus.alterAddPK(database, table, columns)
            elif modoDB == "dict":
                retorno = dic.alterAddPK(database, table, columns)
            elif modoDB == "isam":
                retorno = isam.alterAddPK(database, table, columns)
            elif modoDB == "json":
                retorno = json.alterAddPK(database, table, columns)
            elif modoDB == "hash":
                retorno = hash.alterAddPK(database, table, columns)
            if retorno == 0:
                pk = generalDict[database][3]
                pk.setdefault(table, columns)
                generalDict[database][3] = pk
                ser("data/info/datos.bin", generalDict)
            return retorno
        else:
            return 2

    except Exception:
        return 1
Beispiel #2
0
def alterAddPK(database, table, columns):
    if searchInMode(database) != None:
        currentMode = searchInMode(database)
        if currentMode == 'avl':
            # avlList.append(tableNew)
            return avl.alterAddPK(database, table, columns)
        elif currentMode == 'b':
            # bList.append(tableNew)
            return b.alterAddPK(database, table, columns)
        elif currentMode == 'bplus':
            # bplusList.append(tableNew)
            return bplus.alterAddPK(database, table, columns)
        elif currentMode == 'dict':
            # dictList.append(tableNew)
            return DM.alterAddPK(database, table, columns)
        elif currentMode == 'isam':
            # isamList.append(tableNew)
            return isam.alterAddPK(database, table, columns)
        elif currentMode == 'json':
            # jsonList.append(tableNew)
            return j.alterAddPK(database, table, columns)
        elif currentMode == 'hash':
            # hashList.append(tableNew)
            return Hash.alterAddPK(database, table, columns)
    else:
        return 2
Beispiel #3
0
def alterAddPK(database, table, columns):
    dbs = databases.find_all(database)
    if dbs == []:
        return 2
    for db in dbs:
        if db.mode == "avl":
            result = avlMode.alterAddPK(database, table, columns)
        elif db.mode == "b":
            result = BMode.alterAddPK(database, table, columns)
        elif db.mode == "bplus":
            result = BPlusMode.alterAddPK(database, table, columns)
        elif db.mode == "dict":
            result = DictMode.alterAddPK(database, table, columns)
        elif db.mode == "isam":
            result = ISAMMode.alterAddPK(database, table, columns)
        elif db.mode == "json":
            result = jsonMode.alterAddPK(database, table, columns)
        elif db.mode == "hash":
            result = HashMode.alterAddPK(database, table, columns)
        if result != 3:
            if result == 0:
                db.tables.search(table).pk += columns
                for x in range(5):
                    try:
                        Serializable.commit(databases, "lista_bases_de_datos")
                        return result
                    except:
                        break
                return 1
            break
    return result
Beispiel #4
0
def alterAddPK(database: str, table: str, columns: list) -> int:
    """Adds a PK to a table in a database

        Parameters:\n
            database (str): name of the database
            table (str): name of the table
            columns (list): list with PK columns

        Returns:\n
            0: successful operation
            1: an error ocurred
            2: non-existent database
            3: non-existent table
            4: existent PK
            5: PK out of bounds
    """

    bd = _Buscar(database)

    if bd:

        mode = bd[1]

        val = -1

        if mode == "avl":
            val = avl.alterAddPK(database, table, columns)

        elif mode == "b":
            val = b.alterAddPK(database, table, columns)

        elif mode == "bplus":
            val = bplus.alterAddPK(database, table, columns)

        elif mode == "hash":
            val = hash.alterAddPK(database, table, columns)

        elif mode == "isam":
            val = isam.alterAddPK(database, table, columns)

        elif mode == "json":
            val = json.alterAddPK(database, table, columns)

        elif mode == "dict":
            val = dict.alterAddPK(database, table, columns)

        return val

    else:
        return 2
Beispiel #5
0
def __alter_add_pk_sp(database: str, table: str, columns: list,
                      mode: str) -> int:
    dbs = databases.find_all(database)
    if dbs == []:
        return 2
    if databases.find_table(database, table) == None:
        return 3
    for db in dbs:
        if db.mode != mode:
            continue
        if db.mode == "avl":
            result = avlMode.alterAddPK(database, table, columns)
        elif db.mode == "b":
            result = BMode.alterAddPK(database, table, columns)
        elif db.mode == "bplus":
            result = BPlusMode.alterAddPK(database, table, columns)
        elif db.mode == "dict":
            result = DictMode.alterAddPK(database, table, columns)
        elif db.mode == "isam":
            result = ISAMMode.alterAddPK(database, table, columns)
        elif db.mode == "json":
            result = jsonMode.alterAddPK(database, table, columns)
        elif db.mode == "hash":
            result = HashMode.alterAddPK(database, table, columns)
        else:
            continue
        if result != 3:
            if result == 0:
                db.tables.search(table).pk += columns
                for x in range(5):
                    try:
                        Serializable.commit(databases, "lista_bases_de_datos")
                        return result
                    except:
                        continue
                return 1
            break
    return result
Beispiel #6
0
def __insertarDatosTablas(tablas: list, mode: str, modeOld: str, 
                        database: str, codificacion: str) -> int:
    try:
        val = 1
        retorno = 1
        contador = 0
        diccionarioLlaves = db =__buscarLlaveBaseDato(database)
        diccionarioLlaves = diccionarioLlaves[3]
        pk = 6
        for x in tablas:
            
            tablas = db[2] #Por si están en un modo nuevo de una tabla
            if tablas:
                if tablas.get(x) is not None:
                    modeOld = tablas[x] #fin de lo anterior
            
            valor = __extraerContenidoTabla(x, modeOld, database)
            eliminaTabla = dropTable(database, x)
            columns = len(valor[0])
            if valor is not None:
                if valor != []:
                    cv = __CrearCsvTabla(valor, codificacion)
                    if cv == 0 and eliminaTabla == 0:
                        if mode == "avl":
                            val = avl.createTable(database, x, columns)
                            if diccionarioLlaves.get(x) is not None:
                                pk =avl.alterAddPK(database, x, diccionarioLlaves[x])
                            retorno = avl.loadCSV("data/tablaValor.csv", database, x)
                        elif mode == "b":
                            val = b.createTable(database, x, columns)
                            if diccionarioLlaves.get(x) is not None:
                                pk =b.alterAddPK(database, x, diccionarioLlaves[x])
                            retorno = b.loadCSV("data/tablaValor.csv", database, x)
                        elif mode == "bplus":
                            val = bPlus.createTable(database, x, columns)
                            if diccionarioLlaves.get(x) is not None:
                                pk =bPlus.alterAddPK(database, x, diccionarioLlaves[x])
                            retorno = bPlus.loadCSV("data/tablaValor.csv", database, x)
                        elif mode == "dict":
                            val = dic.createTable(database, x, columns)
                            if diccionarioLlaves.get(x) is not None:
                                pk =dic.alterAddPK(database, x, diccionarioLlaves[x])
                            retorno = dic.loadCSV("data/tablaValor.csv", database, x)
                        elif mode == "isam":
                            val = isam.createTable(database, x, columns)
                            if diccionarioLlaves.get(x) is not None:
                                pk =isam.alterAddPK(database, x, diccionarioLlaves[x])
                            retorno = isam.loadCSV("data/tablaValor.csv", database, x)
                        elif mode == "json":
                            val = json.createTable(database, x, columns)
                            if diccionarioLlaves.get(x) is not None:
                                pk =json.alterAddPK(database, x, diccionarioLlaves[x])
                            retorno = json.loadCSV("data/tablaValor.csv", database, x)
                        elif mode == "hash":
                            val = hash.createTable(database, x, columns)
                            if diccionarioLlaves.get(x) is not None:
                                pk =avl.alterAddPK(database, x, diccionarioLlaves[x])
                            retorno = hash.loadCSV("data/tablaValor.csv", database, x)
                        contador = contador + 1
                else:
                    if mode == "avl":
                        val = avl.createTable(database, x, columns)
                        if diccionarioLlaves.get(x) is not None:
                                pk =avl.alterAddPK(database, x, diccionarioLlaves[x])
                        retorno = [1]
                    elif mode == "b":
                        val = b.createTable(database, x, columns)
                        if diccionarioLlaves.get(x) is not None:
                                pk =b.alterAddPK(database, x, diccionarioLlaves[x])
                        retorno = [1]
                    elif mode == "bplus":
                        val = bPlus.createTable(database, x, columns)
                        if diccionarioLlaves.get(x) is not None:
                                pk =bPlus.alterAddPK(database, x, diccionarioLlaves[x])
                        retorno = [1]
                    elif mode == "dict":
                        val = dic.createTable(database, x, columns)
                        if diccionarioLlaves.get(x) is not None:
                                pk =dic.alterAddPK(database, x, diccionarioLlaves[x])
                        retorno = [1]
                    elif mode == "isam":
                        val = isam.createTable(database, x, columns)
                        if diccionarioLlaves.get(x) is not None:
                                pk =isam.alterAddPK(database, x, diccionarioLlaves[x])
                        retorno = [1]
                    elif mode == "json":
                        val = json.createTable(database, x, columns)
                        if diccionarioLlaves.get(x) is not None:
                                pk =json.alterAddPK(database, x, diccionarioLlaves[x])
                        retorno = [1]
                    elif mode == "hash":
                        val = hash.createTable(database, x, columns)
                        retorno = [1]
        if (val == 0 and len(retorno) != 0 and (pk == 6 or pk == 0)) \
                                    or (contador == 0 and val == 0  and (pk == 6 or pk == 0)):
            return 0
        elif val == 3 and pk == 4:
            return 0
        else:
            return 1
    except Exception:
        return 1