示例#1
0
def loadCSV(file: str, database: str, table: str) -> list:
    try:
        retorno = 1
        db = __buscarLlaveBaseDato(database)
        if db is not None:
            modoDB = db[0]
            if modoDB == "avl":
                retorno = avl.loadCSV(file, database, table)
            elif modoDB == "b":
                retorno = b.loadCSV(file, database, table)
            elif modoDB == "bplus":
                retorno = bPlus.loadCSV(file, database, table)
            elif modoDB == "dict":
                retorno = dic.loadCSV(file, database, table)
            elif modoDB == "isam":
                retorno = isam.loadCSV(file, database, table)
            elif modoDB == "json":
                retorno = json.loadCSV(file, database, table)
            elif modoDB == "hash":
                retorno = hash.loadCSV(file, database, table)
            return retorno
        else:
            return None

    except Exception:
        return None
示例#2
0
文件: Bases.py 项目: GleyP/Test
def loadCSV(file, database, table):
    if searchInMode(database) != None:
        currentMode = searchInMode(database)
        if currentMode == 'avl':
            # avlList.append(tableNew)
            return avl.loadCSV(file, database, table)
        elif currentMode == 'b':
            # bList.append(tableNew)
            return b.loadCSV(file, database, table)
        elif currentMode == 'bplus':
            # bplusList.append(tableNew)
            return bplus.loadCSV(file, database, table)
        elif currentMode == 'dict':
            # dictList.append(tableNew)
            return DM.loadCSV(file, database, table)
        elif currentMode == 'isam':
            # isamList.append(tableNew)
            return isam.loadCSV(file, database, table)
        elif currentMode == 'json':
            # jsonList.append(tableNew)
            return j.loadCSV(file, database, table)
        elif currentMode == 'hash':
            # hashList.append(tableNew)
            return Hash.loadCSV(file, database, table)
    else:
        return 2
示例#3
0
def loadCSV(file: str, database: str, table: str) -> list:
    try:
        result = []
        dbs = databases.find_all(database)
        for db in dbs:
            tb = db.tables.search(table)
            if tb == None:
                continue
            if db.mode == "avl":
                result = avlMode.loadCSV(file, database, table)
            elif db.mode == "b":
                result = BMode.loadCSV(file, database, table)
            elif db.mode == "bplus":
                result = BPlusMode.loadCSV(file, database, table)
            elif db.mode == "dict":
                result = DictMode.loadCSV(file, database, table)
            elif db.mode == "isam":
                result = ISAMMode.loadCSV(file, database, table)
            elif db.mode == "json":
                result = jsonMode.loadCSV(file, database, table)
            elif db.mode == "hash":
                result = HashMode.loadCSV(file, database, table)
        return result
    except:
        return []
示例#4
0
def loadCSV(file: str, database: str, table: str) -> list:
    """Loads a csv file and inserts its content into a table in a database

        Parameters:\n
            file (str): csv file path
            file (str): csv file path
            database (str): name of the database
            table (str): name of the table

        Returns:\n
            list: return values of each insert
            empty list: non-existent database, non-existent table, an error occured, csv file is empty
    """

    bd = _database(database)

    if bd:

        tb = _table(database, table)

        if tb:

            mode = tb["modo"]

            val = -1

            if mode == "avl":
                val = avl.loadCSV(file, database, table)

            elif mode == "b":
                val = b.loadCSV(file, database, table)

            elif mode == "bplus":
                val = bplus.loadCSV(file, database, table)

            elif mode == "hash":
                val = hash.loadCSV(file, database, table)

            elif mode == "isam":
                val = isam.loadCSV(file, database, table)

            elif mode == "json":
                val = json.loadCSV(file, database, table)

            elif mode == "dict":
                val = dict.loadCSV(file, database, table)

            return val

        else:
            return 3

    else:
        return 2
示例#5
0
文件: app.py 项目: cesargp45/tytus
def loadCSV(file, database, table):
    mode = None
    for i in range(7):
        mode = obtenerBase(database, i)
        if mode == []:
            continue
        else:
            if mode == 0:
                mode = "avl"
            elif mode == 1:
                mode = "b"
            elif mode == 2:
                mode = "bplus"
            elif mode == 3:
                mode = "dict"
            elif mode == 4:
                mode = "isam"
            elif mode == 5:
                mode = "json"
            elif mode == 6:
                mode = "hash"
            break
    if mode == None:
        return 2
    if mode == "avl":
        # Grupo 16
        val = avl_mode.loadCSV(file, database, table)
    elif mode == "b":
        # Grupo 17
        val = b_mode.loadCSV(file, database, table)
    elif mode == "bplus":
        # Grupo 18
        val = bplus_mode.loadCSV(file, database, table)
    elif mode == "dict":
        # Auxiliar
        val = dict_mode.loadCSV(file, database, table)
    elif mode == "isam":
        # Grupo 14
        val = isam_mode.loadCSV(file, database, table)
    elif mode == "json":
        # Ingeniero
        val = json_mode.loadCSV(file, database, table)
    elif mode == "hash":
        # Grupo 15
        val = hash_mode.loadCSV(file, database, table)
    else:
        val = 3
    return val
示例#6
0
def loadCSV(file, database, name_table):
    ModeDB, indexDB = exist_Alter(database)
    if ModeDB:
        mode = ModeDB.get_mode()
        if mode.lower().strip() == "avl":
            return avl.loadCSV(file, database, name_table)
        elif mode.lower().strip() == "b":
            return b.loadCSV(file, database, name_table)
        elif mode.lower().strip() == "bPlus".lower():
            return bPlus.loadCSV(file, database, name_table)
        elif mode.lower().strip() == "dict":
            return diccionario.loadCSV(file, database, name_table)
        elif mode.lower().strip() == "hash":
            return hash.loadCSV(file, database, name_table)
        elif mode.lower().strip() == "isam":
            return isam.loadCSV(file, database, name_table)
        elif mode.lower().strip() == "json":
            return json.loadCSV(file, database, name_table)
示例#7
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