def insertAlter(database, tabla, numberColumns, mode, listaDatos): if mode.lower().strip() == "avl": avl.createTable(database, tabla, numberColumns) for data in listaDatos: avl.insert(database, tabla, data) elif mode.lower().strip() == "b": b.createTable(database, tabla, numberColumns) for data in listaDatos: b.insert(database, tabla, data) elif mode.lower().strip() == "bPlus".lower(): bPlus.createTable(database, tabla, numberColumns) for data in listaDatos: bPlus.insert(database, tabla, data) elif mode.lower().strip() == "dict": diccionario.createTable(database, tabla, numberColumns) for data in listaDatos: diccionario.insert(database, tabla, data) elif mode.lower().strip() == "isam": isam.createTable(database, tabla, numberColumns) for data in listaDatos: isam.insert(database, tabla, data) elif mode.lower().strip() == "hash": hash.createTable(database, tabla, numberColumns) for data in listaDatos: hash.insert(database, tabla, data) elif mode.lower().strip() == "json": json.createTable(database, tabla, numberColumns) for data in listaDatos: json.insert(database, tabla, data)
def createTable(database: str, table: str, numberColumns: int) -> int: try: retorno = 1 db = __buscarLlaveBaseDato(database) if db is not None: modoDB = db[0] if modoDB == "avl": retorno = avl.createTable(database, table, numberColumns) elif modoDB == "b": retorno = b.createTable(database, table, numberColumns) elif modoDB == "bplus": retorno = bPlus.createTable(database, table, numberColumns) elif modoDB == "dict": retorno = dic.createTable(database, table, numberColumns) elif modoDB == "isam": retorno = isam.createTable(database, table, numberColumns) elif modoDB == "json": retorno = json.createTable(database, table, numberColumns) elif modoDB == "hash": retorno = hash.createTable(database, table, numberColumns) return retorno else: return 2 except Exception: return 1
def createTable(database, table, numbercolumns): if searchInMode(database) != None: currentMode = searchInMode(database) if currentMode == 'avl': avlList.append(table) return avl.createTable(database, table, numbercolumns) elif currentMode == 'b': bList.append(table) return b.createTable(database, table, numbercolumns) elif currentMode == 'bplus': bplusList.append(table) return bplus.createTable(database, table, numbercolumns) elif currentMode == 'dict': dictList.append(table) return DM.createTable(database, table, numbercolumns) elif currentMode == 'isam': isamList.append(table) return isam.createTable(database, table, numbercolumns) elif currentMode == 'json': jsonList.append(table) return j.createTable(database, table, numbercolumns) elif currentMode == 'hash': hashList.append(table) return Hash.createTable(database, table, numbercolumns) else: return 2
def createTable(database: str, table: str, numberColumns: int) -> int: db = databases.search(database) if db == None: return 2 if table in showTables(database): return 3 if db.mode == "avl": result = avlMode.createTable(database, table, numberColumns) elif db.mode == "b": result = BMode.createTable(database, table, numberColumns) elif db.mode == "bplus": result = BPlusMode.createTable(database, table, numberColumns) elif db.mode == "dict": result = DictMode.createTable(database, table, numberColumns) elif db.mode == "isam": result = ISAMMode.createTable(database, table, numberColumns) elif db.mode == "json": result = jsonMode.createTable(database, table, numberColumns) elif db.mode == "hash": result = HashMode.createTable(database, table, numberColumns) if result == 0: if db.tables.create(table, numberColumns) == 0: for x in range(5): try: Serializable.commit(databases, "lista_bases_de_datos") return result except: continue return 1 return result
def _createTable(database, table, numberColumns, mode): val = -1 if mode == "avl": val = avl.createTable(database, table, numberColumns) elif mode == "b": val = b.createTable(database, table, numberColumns) elif mode == "bplus": val = bplus.createTable(database, table, numberColumns) elif mode == "hash": val = hash.createTable(database, table, numberColumns) elif mode == "isam": val = isam.createTable(database, table, numberColumns) elif mode == "json": val = json.createTable(database, table, numberColumns) elif mode == "dict": val = dict.createTable(database, table, numberColumns) if val == 0: _database(database)["tablas"].append({"nombre": table, "modo":mode, "columnas": numberColumns, "pk": []}) _Guardar() return val
def createTable(database: str, table: str, numberColumns: int) -> int: """Creates a table Parameters:\n database (str): name of the database table (str): name of the table numberColumns (int): number of table columns Returns:\n 0: successful operation 1: an error ocurred 2: non-existent database 3: table name ocuppied """ bd = _Buscar(database) if bd: mode = bd[1] val = -1 if mode == "avl": val = avl.createTable(database, table, numberColumns) elif mode == "b": val = b.createTable(database, table, numberColumns) elif mode == "bplus": val = bplus.createTable(database, table, numberColumns) elif mode == "hash": val = hash.createTable(database, table, numberColumns) elif mode == "isam": val = isam.createTable(database, table, numberColumns) elif mode == "json": val = json.createTable(database, table, numberColumns) elif mode == "dict": val = dict.createTable(database, table, numberColumns) return val else: return 2
def createTable(database, name_table, number_columns): ModeDB, indexDB = exist_Alter(database) if ModeDB: mode = ModeDB.get_mode() if mode.lower().strip() == "avl": return avl.createTable(database, name_table, number_columns) elif mode.lower().strip() == "b": return b.createTable(database, name_table, number_columns) elif mode.lower().strip() == "bPlus".lower(): return bPlus.createTable(database, name_table, number_columns) elif mode.lower().strip() == "dict": return diccionario.createTable(database, name_table, number_columns) elif mode.lower().strip() == "hash": return hash.createTable(database, name_table, number_columns) elif mode.lower().strip() == "isam": return isam.createTable(database, name_table, number_columns) elif mode.lower().strip() == "json": return json.createTable(database, name_table, number_columns) else: return "f"
def __create_table_sp(database: str, table: str, numberColumns: int, mode: str) -> int: dbs = databases.find_all(database) if dbs == []: return 2 if mode not in MODES: return 4 for db in dbs: if db.mode != mode: continue if db.mode == "avl": result = avlMode.createTable(database, table, numberColumns) elif db.mode == "b": result = BMode.createTable(database, table, numberColumns) elif db.mode == "bplus": result = BPlusMode.createTable(database, table, numberColumns) elif db.mode == "dict": result = DictMode.createTable(database, table, numberColumns) elif db.mode == "isam": result = ISAMMode.createTable(database, table, numberColumns) elif db.mode == "json": result = jsonMode.createTable(database, table, numberColumns) elif db.mode == "hash": result = HashMode.createTable(database, table, numberColumns) else: continue if result == 0: if db.tables.create(table, numberColumns) == 0: for x in range(5): try: Serializable.commit(databases, "lista_bases_de_datos") return result except: continue return 1 return result
def createTable(database, table, numColumns): 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.createTable(database, table, numColumns) elif mode == "b": # Grupo 17 val = b_mode.createTable(database, table, numColumns) elif mode == "bplus": # Grupo 18 val = bplus_mode.createTable(database, table, numColumns) elif mode == "dict": # Auxiliar val = dict_mode.createTable(database, table, numColumns) elif mode == "isam": # Grupo 14 val = isam_mode.createTable(database, table, numColumns) elif mode == "json": # Ingeniero val = json_mode.createTable(database, table, numColumns) elif mode == "hash": # Grupo 15 val = hash_mode.createTable(database, table, numColumns) else: val = 3 if val == 0: global Tablas try: # Leemos el archivo binario de los registros de bases de datos lectura = open("TB_register", "rb") Tablas = pickle.load(lectura) try: Tablas[database].update({table: {"PK": None, "FK": None}}) except: Tablas.update({database: {table: {"PK": None, "FK": None}}}) # Actualizamos el archivo binario de los registros de bases de datos escritura = open("TB_register", "wb") pickle.dump(Tablas, escritura) escritura.close() except: try: Tablas[database].update({table: {"PK": None, "FK": None}}) except: Tablas.update({database: {table: {"PK": None, "FK": None}}}) # Actualizamos el archivo binario de los registros de bases de datos fichero_escritura = open("TB_register", "wb") pickle.dump(Tablas, fichero_escritura) fichero_escritura.close() return val
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