def dropDatabase(name_db): ModeDB, indexDB = exist_Alter(name_db) if ModeDB: mode = ModeDB.get_mode() if mode.lower().strip() == "avl": return avl.dropDatabase(name_db) elif mode.lower().strip() == "b": return b.dropDatabase(name_db) elif mode.lower().strip() == "bPlus".lower(): return bPlus.dropDatabase(name_db) elif mode.lower().strip() == "dict": return diccionario.dropDatabase(name_db) elif mode.lower().strip() == "hash": return hash.dropDatabase(name_db) elif mode.lower().strip() == "isam": return isam.dropDatabase(name_db) elif mode.lower().strip() == "json": return json.dropDatabase(name_db)
def alterAddColumn(database, name_table, default): ModeDB, indexDB = exist_Alter(database) if ModeDB: mode = ModeDB.get_mode() if mode.lower().strip() == "avl": return avl.alterAddColumn(database, name_table, default) elif mode.lower().strip() == "b": return b.alterAddColumn(database, name_table, default) elif mode.lower().strip() == "bPlus".lower(): return bPlus.alterAddColumn(database, name_table, default) elif mode.lower().strip() == "dict": return diccionario.alterAddColumn(database, name_table, default) elif mode.lower().strip() == "hash": return hash.alterAddColumn(database, name_table, default) elif mode.lower().strip() == "isam": return isam.alterAddColumn(database, name_table, default) elif mode.lower().strip() == "json": return json.alterAddColumn(database, name_table, default)
def showTables(database: str) -> list: """Show stored tables in a database Parameters:\n database (str): name of the database Returns:\n list: successful operation None: non-existent database """ bd = _Buscar(database) if bd: mode = bd[1] val = -1 if mode == "avl": val = avl.showTables(database) elif mode == "b": val = b.showTables(database) elif mode == "bplus": val = bplus.showTables(database) elif mode == "hash": val = hash.showTables(database) elif mode == "isam": val = isam.showTables(database) elif mode == "json": val = json.showTables(database) elif mode == "dict": val = dict.showTables(database) return val else: return 2
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
def update(database, table, register, columns): db = databases.search(database) if db == None: return 2 if db.mode == "avl": result = avlMode.update(database, table, register, columns) elif db.mode == "b": result = BMode.update(database, table, register, columns) elif db.mode == "bplus": result = BPlusMode.update(database, table, register, columns) elif db.mode == "dict": result = DictMode.update(database, table, register, columns) elif db.mode == "isam": result = ISAMMode.update(database, table, register, columns) elif db.mode == "json": result = jsonMode.update(database, table, register, columns) elif db.mode == "hash": result = HashMode.update(database, table, register, columns) return result
def truncate(database, table): db = databases.search(database) if db == None: return 2 if db.mode == "avl": result = avlMode.truncate(database, table) elif db.mode == "b": result = BMode.truncate(database, table) elif db.mode == "bplus": result = BPlusMode.truncate(database, table) elif db.mode == "dict": result = DictMode.truncate(database, table) elif db.mode == "isam": result = ISAMMode.truncate(database, table) elif db.mode == "json": result = jsonMode.truncate(database, table) elif db.mode == "hash": result = HashMode.truncate(database, table) return result
def alterDatabase(old_db, new_db): modeDB, indexDB = exist_Alter(old_db) modeDB_new, indexDB_newDB = exist_Alter(new_db) if modeDB and modeDB_new is None: mode = modeDB.get_mode() if mode.lower().strip() == "avl": return avl.alterDatabase(old_db, new_db) elif mode.lower().strip() == "b": return b.alterDatabase(old_db, new_db) elif mode.lower().strip() == "bPlus".lower(): return bPlus.alterDatabase(old_db, new_db) elif mode.lower().strip() == "dict": return diccionario.alterDatabase(old_db, new_db) elif mode.lower().strip() == "hash": return hash.alterDatabase(old_db, new_db) elif mode.lower().strip() == "isam": return isam.alterDatabase(old_db, new_db) elif mode.lower().strip() == "json": return json.alterDatabase(old_db, new_db)
def createDatabase(database: str, mode: str, encoding: str) -> int: if encoding not in VALID_ENCODING: return 4 if databases.search(database) != None: return 2 if mode == "avl": code = avlMode.createDatabase(database) elif mode == "b": code = BMode.createDatabase(database) elif mode == "bplus": code = BPlusMode.createDatabase(database) elif mode == "dict": code = DictMode.createDatabase(database) elif mode == "isam": code = ISAMMode.createDatabase(database) elif mode == "json": code = jsonMode.createDatabase(database) elif mode == "hash": code = HashMode.createDatabase(database) else: return 3 if code == 0: databases.create(database, mode, encoding) databases.search(database).main_db = True try: for i in range(5): try: Serializable.commit(databases, "lista_bases_de_datos") except: continue except: code_drop = dropDatabase(database) if code_drop == 0: databases.delete(database) return 1 else: for i in range(4): code_drop = dropDatabase(database) if code_drop == 0: databases.delete(database) break return 1 return code
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
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 extractRow(database, name_table, columns): ModeDB, indexDB = exist_Alter(database) if ModeDB: mode = ModeDB.get_mode() if mode.lower().strip() == "avl": return avl.extractRow(database, name_table, columns) elif mode.lower().strip() == "b": return b.extractRow(database, name_table, columns) elif mode.lower().strip() == "bPlus".lower(): return bPlus.extractRow(database, name_table, columns) elif mode.lower().strip() == "dict": return diccionario.extractRow(database, name_table, columns) elif mode.lower().strip() == "hash": return hash.extractRow(database, name_table, columns) elif mode.lower().strip() == "isam": return isam.extractRow(database, name_table, columns) elif mode.lower().strip() == "json": return json.extractRow(database, name_table, columns) # return db.extractRow(database, name_table, columns) Revisar persona quien lo realizo return None
def showTables(database: str) -> list: dbs = databases.find_all(database) if dbs == []: return None result = [] for db in dbs: if db.mode == "avl": result += avlMode.showTables(database) elif db.mode == "b": result += BMode.showTables(database) elif db.mode == "bplus": result += BPlusMode.showTables(database) elif db.mode == "dict": result += DictMode.showTables(database) elif db.mode == "isam": result += ISAMMode.showTables(database) elif db.mode == "json": result += jsonMode.showTables(database) elif db.mode == "hash": result += HashMode.showTables(database) return result
def obtenerContenidoTabla(database, table, estructura): val = [] if estructura == 0: val = avl_mode.extractTable(database, table) elif estructura == 1: val = b_mode.extractTable(database, table) elif estructura == 2: val = bplus_mode.extractTable(database, table) elif estructura == 3: val = dict_mode.extractTable(database, table) elif estructura == 4: val = isam_mode.extractTable(database, table.lower()) elif estructura == 5: val = json_mode.extractTable(database, table) elif estructura == 6: val = hash_mode.extractTable(database, table) if val == []: return "" contenido = "" for i in range(len(val)): contenido += str(val[i]) return contenido
def insert(database: str, table: str, register: list): dbs = databases.find_all(database) if dbs == []: return 2 for db in dbs: if db.mode == "avl": result = avlMode.insert(database, table, register) elif db.mode == "b": result = BMode.insert(database, table, register) elif db.mode == "bplus": result = BPlusMode.insert(database, table, register) elif db.mode == "dict": result = DictMode.insert(database, table, register) elif db.mode == "isam": result = ISAMMode.insert(database, table, register) elif db.mode == "json": result = jsonMode.insert(database, table, register) elif db.mode == "hash": result = HashMode.insert(database, table, register) if result != 3: break return result
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
def obtenerBase(database, estructura): val = [] if estructura == 0: val = avl_mode.showDatabases() elif estructura == 1: val = b_mode.showDatabases() elif estructura == 2: val = bplus_mode.showDatabases() elif estructura == 3: val = dict_mode.showDatabases() elif estructura == 4: val = isam_mode.showDatabases() elif estructura == 5: val = json_mode.showDatabases() elif estructura == 6: val = hash_mode.showDatabases() if val == []: return val else: for i in range(len(val)): if val[i].lower() == database.lower(): return estructura return []
def alterAddIndex(database: str, table: str, references: dict) -> int: """ DOCSTRING """ bd = _Buscar(database) if bd: mode = bd[1] val = -1 if mode == "avl": val = avl.alterAddIndex(database, table, references) elif mode == "b": val = b.alterAddIndex(database, table, references) elif mode == "bplus": val = bplus.alterAddIndex(database, table, references) elif mode == "hash": val = hash.alterAddIndex(database, table, references) elif mode == "isam": val = isam.alterAddIndex(database, table, references) elif mode == "json": val = json.alterAddIndex(database, table, references) elif mode == "dict": val = dict.alterAddIndex(database, table, references) return val else: return 2
def __drop_table_sp(database, table, mode): 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.dropTable(database, table) elif db.mode == "b": result = BMode.dropTable(database, table) elif db.mode == "bplus": result = BPlusMode.dropTable(database, table) elif db.mode == "dict": result = DictMode.dropTable(database, table) elif db.mode == "isam": result = ISAMMode.dropTable(database, table) elif db.mode == "json": result = jsonMode.dropTable(database, table) elif db.mode == "hash": result = HashMode.dropTable(database, table) else: continue if result != 3: if result == 0: db.tables.delete(table) for x in range(5): try: Serializable.commit(databases, "lista_bases_de_datos") return result except: continue return 1 break return result
def __drop_database_sp(database: str, mode: str) -> int: if re.search(DB_NAME_PATTERN, database): 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": code = avlMode.dropDatabase(database) elif db.mode == "b": code = BMode.dropDatabase(database) elif db.mode == "bplus": code = BPlusMode.dropDatabase(database) elif db.mode == "dict": code = DictMode.dropDatabase(database) elif db.mode == "isam": code = ISAMMode.dropDatabase(database) elif db.mode == "json": code = jsonMode.dropDatabase(database) elif db.mode == "hash": code = HashMode.dropDatabase(database) else: continue if code == 0: databases.delete_sp(db.name, db.mode) for x in range(5): try: Serializable.commit(databases, "lista_bases_de_datos") return 0 except: continue return 1 else: return 1
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 alterTableMode(database: str, table: str, databaseRef: str, mode: str): if exist_Alter(database) and exist_Alter(databaseRef) and exist_Alter( databaseRef)[0].get_mode() == mode: ModeDB, indice = exist_Alter(database) if ModeDB: oldMode = ModeDB.get_mode() if oldMode.lower().strip() == "avl": tables = avl.showTables(database) for tabla in tables: if tabla == table: listaDatos = get_Data( database, tabla, oldMode) # UNA LISTA VACIA NO EJECUTA EL FOR numberColumns = len(listaDatos[0]) insertAlter(databaseRef, tabla, numberColumns, mode, listaDatos) avl.dropTable(database, table) elif oldMode.lower().strip() == "b": tables = b.showTables(database) for tabla in tables: if tabla == table: listaDatos = get_Data(database, tabla, oldMode) numberColumns = len(listaDatos[0]) insertAlter(databaseRef, tabla, numberColumns, mode, listaDatos) b.dropTable(database, table) elif oldMode.lower().strip() == "bPlus".lower(): tables = bPlus.showTables(database) for tabla in tables: if tabla == table: listaDatos = get_Data(database, tabla, oldMode) numberColumns = len(listaDatos[0]) insertAlter(databaseRef, tabla, numberColumns, mode, listaDatos) bPlus.dropTable(database, table) elif oldMode.lower().strip() == "dict": tables = diccionario.showTables(database) for tabla in tables: if tabla == table: listaDatos = get_Data(database, tabla, oldMode) numberColumns = len(listaDatos[0]) insertAlter(databaseRef, tabla, numberColumns, mode, listaDatos) diccionario.dropTable(database, table) elif oldMode.lower().strip() == "isam": tables = isam.showTables(database) for tabla in tables: if tabla == table: listaDatos = get_Data(database, tabla, oldMode) numberColumns = len(listaDatos[0]) insertAlter(databaseRef, tabla, numberColumns, mode, listaDatos) isam.dropTable(database, table) elif oldMode.lower().strip() == "hash": tables = hash.showTables(database) for tabla in tables: if tabla == table: listaDatos = get_Data(database, tabla, oldMode) numberColumns = len(listaDatos[0]) insertAlter(databaseRef, tabla, numberColumns, mode, listaDatos) hash.dropTable(database, table) elif oldMode.lower().strip() == "json": tables = json.showTables(database) for tabla in tables: if tabla == table: listaDatos = get_Data(database, tabla, oldMode) numberColumns = len(listaDatos[0]) insertAlter(databaseRef, tabla, numberColumns, mode, listaDatos) json.dropTable(database, table) else: return None
def dropDatabase(database): 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.dropDatabase(database) elif mode == "b": # Grupo 17 val = b_mode.dropDatabase(database) elif mode == "bplus": # Grupo 18 val = bplus_mode.dropDatabase(database) elif mode == "dict": # Auxiliar val = dict_mode.dropDatabase(database) elif mode == "isam": # Grupo 14 val = isam_mode.dropDatabase(database) elif mode == "json": # Ingeniero val = json_mode.dropDatabase(database) elif mode == "hash": # Grupo 15 val = hash_mode.dropDatabase(database) else: val = 3 if val == 0: global Bases global Tablas try: # Leemos el archivo binario de los registros de bases de datos fichero_lectura = open("BD_register", "rb") Bases = pickle.load(fichero_lectura) Bases.pop(database) # 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() try: # Leemos el archivo binario de los registros de tablas fichero_lectura = open("TB_register", "rb") Tablas = pickle.load(fichero_lectura) try: Tablas.pop(database) except: """""" # Actualizamos el archivo binario de los registros de tablas fichero_escritura = open("TB_register", "wb") pickle.dump(Tablas, fichero_escritura) fichero_escritura.close() except: try: Tablas.pop(database) except: """""" # Actualizamos el archivo binario de los registros de tablas fichero_escritura = open("TB_register", "wb") pickle.dump(Tablas, fichero_escritura) fichero_escritura.close() except: Bases.pop(database) # 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() try: # Leemos el archivo binario de los registros de tablas fichero_lectura = open("TB_register", "rb") Tablas = pickle.load(fichero_lectura) try: Tablas.pop(database) except: """""" # Actualizamos el archivo binario de los registros de tablas fichero_escritura = open("TB_register", "wb") pickle.dump(Tablas, fichero_escritura) fichero_escritura.close() except: try: Tablas.pop(database) except: """""" # Actualizamos el archivo binario de los registros de tablas fichero_escritura = open("TB_register", "wb") pickle.dump(Tablas, fichero_escritura) fichero_escritura.close() return val
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 extractRangeTable(database: str, table: str, columnNumber: int, lower: any, upper: any) -> list: try: retorno = [] 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.extractRangeTable( database, table, columnNumber, lower, upper ) elif modoDB == "b": retorno = b.extractRangeTable( database, table, columnNumber, lower, upper ) elif modoDB == "bplus": retorno = bPlus.extractRangeTable( database, table, columnNumber, lower, upper ) elif modoDB == "dict": retorno = dic.extractRangeTable( database, table, columnNumber, lower, upper ) elif modoDB == "isam": retorno = isam.extractRangeTable( database, table, columnNumber, lower, upper ) elif modoDB == "json": retorno = json.extractRangeTable( database, table, columnNumber, lower, upper ) elif modoDB == "hash": retorno = hash.extractRangeTable( database, table, columnNumber, lower, upper ) return retorno else: return None except Exception: return None
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
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 = _database(database) if bd: tb = _table(database, table) if tb: mode = tb["modo"] 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) if val==0: _table(database, table)["pk"]=columns _Guardar() return val else: return 3 else: return 2
def alterDropColumn(database: str, table: str, columnNumber: int) -> int: """Deletes a column of a table in a database Parameters:\n database (str): name of the database table (str): name of the table columnNumber (int): target column index Returns:\n 0: successful operation 1: an error ocurred 2: non-existent database 3: non-existent table 4: column cannot be deleted 5: column index out of bounds """ bd = _database(database) if bd: tb = _table(database, table) if tb: mode = tb["modo"] val = -1 if mode == "avl": val = avl.alterDropColumn(database, table, columnNumber) elif mode == "b": val = b.alterDropColumn(database, table, columnNumber) elif mode == "bplus": val = bplus.alterDropColumn(database, table, columnNumber) elif mode == "hash": val = hash.alterDropColumn(database, table, columnNumber) elif mode == "isam": val = isam.alterDropColumn(database, table, columnNumber) elif mode == "json": val = json.alterDropColumn(database, table, columnNumber) elif mode == "dict": val = dict.alterDropColumn(database, table, columnNumber) if val == 0: _table(database, table)["columnas"]-=1 _Guardar() return val else: return 3 else: return 2
def checksumTable(database, table: str, mode: str): object_mode, index = get_object_mode(database) if object_mode: mode_db = object_mode.get_mode() if mode.lower().strip() == "sha256": data = "" if mode_db.lower().strip() == "avl": if table.strip() in avl.showTables(database): data = table else: return None elif mode_db.lower().strip() == "b": if table.strip() in b.showTables(database): data = b.extractTable(database, table) else: return None elif mode_db.lower().strip() == "bPlus".lower(): if table.strip() in bPlus.showTables(database): data = table else: return None elif mode_db.lower().strip() == "dict": if table.strip() in diccionario.showTables(database): data = table else: return None elif mode_db.lower().strip() == "hash": if table.strip() in hash.showTables(database): data = table else: return None elif mode_db.lower().strip() == "isam": if table.strip() in isam.showTables(database): data = table else: return None elif mode_db.lower().strip() == "json": if table.strip() in json.showTables(database): data = table else: return None return checksum_table(1, database, mode_db, data) elif mode.lower().strip() == "md5": data = "" if mode_db.lower().strip() == "avl": if table.strip() in avl.showTables(database): data = table else: return None elif mode_db.lower().strip() == "b": if table.strip() in b.showTables(database): data = b.extractTable(database, table) else: return None elif mode_db.lower().strip() == "bPlus".lower(): if table.strip() in bPlus.showTables(database): data = table else: return None elif mode_db.lower().strip() == "dict": if table.strip() in diccionario.showTables(database): data = table else: return None elif mode_db.lower().strip() == "hash": if table.strip() in hash.showTables(database): data = table else: return None elif mode_db.lower().strip() == "isam": if table.strip() in isam.showTables(database): data = table else: return None elif mode_db.lower().strip() == "json": if table.strip() in json.showTables(database): data = table else: return None return checksum_table(2, database, mode_db, data) else: return None else: return None
db[2] = en return 0 except: return 1 def Codtexto(database , texto): for db in lista_db: if database == db[0]: try: texto.encode(db[2]) return True except: return False avl.dropDatabase("pruebaya1") hash.dropDatabase("pruebaya1") bplus.dropDatabase("pruebaya1") dropDatabase("pruebaya1") #print(createDatabase("pruebaya1","avl","utf8")) #print(createTable("pruebaya1","tabla1",3)) #print(createTable("pruebaya1","tabla2",3)) #print(createTable("pruebaya1","tabla3",3)) #print(createTable("pruebaya1","tabla4",3)) #print(createTable("pruebaya1","tabla5",3)) #print(createTable("pruebaya1","tabla6",3)) #print(insert("pruebaya1","tabla1",["jola1","jola","jola"])) #print(insert("pruebaya1","tabla1",["jola2","jola","jola"])) #print(insert("pruebaya1","tabla1",["jola3","jola","jola"])) #print(insert("pruebaya1","tabla1",["jola4","jola","jola"])) #print(insert("pruebaya1","tabla1",["jola5","jola","jola"])) #print(insert("pruebaya1","tabla1",["jola6","jola","jola"]))