def alterTable(database: str, tableOld: str, tableNew: str) -> int: try: if not database.isidentifier() \ or not tableOld.isidentifier() \ or not tableNew.isidentifier(): raise Exception() baseDatos = __getDatabase(database) if baseDatos is False: return 2 tabla = __getTable(database, tableOld) if tabla is False: return 3 existe = __getTable(database, tableNew) if existe: return 4 # Fase 2 modo = tabla["mode"] res = 1 # esperando que la respuesta sea exitosa if modo == "avl": res = avl.alterTable(database, tableOld, tableNew) elif modo == "b": res = b.alterTable(database, tableOld, tableNew) elif modo == "bplus": res = bplus.alterTable(database, tableOld, tableNew) elif modo == "hash": res = ha.alterTable(database, tableOld, tableNew) elif modo == "isam": res = isam.alterTable(database, tableOld, tableNew) elif modo == "json": res = j.alterTable(database, tableOld, tableNew) elif modo == "dict": res = d.alterTable(database, tableOld, tableNew) if res == 0: # fue satisfactoria la operacion # Pedir la lista de diccionarios de base de datos listaDB = __rollback("data") for db in listaDB: if db["nameDb"] == database: for tb in db["tables"]: if tb["nameTb"] == tableOld: tb["foreign_keys"].alterTable(tableNew) tb["unique_index"].alterTable(tableNew) tb["index"].alterTable(tableNew) tb["nameTb"] = tableNew break # Se guarda la lista de base de datos ya actualizada en el archivo data __commit(listaDB, "data") return res except: return 1
def alterTable(database, tableOld, tableNew): try: database = str(database) tableOld = str(tableOld) tableNew = str(tableNew) dictionary = load('metadata') value_base = dictionary.get(database) if not value_base: return 2 mode = dictionary.get(database)[0] j = checkMode(mode) value_return = j.alterTable(database, tableOld, tableNew) if value_return == 0: dict_tables = dictionary.get(database)[2] infoTabla = dict_tables[tableOld] dict_tables.pop(tableOld) dict_tables[tableNew] = infoTabla save(dictionary, 'metadata') return value_return except: return 1