def EAltTbRenameTable(): cargarMemoria() #llamar la funcion de EDD if (len(listaMemoria) > 0): res = EDD.alterTable(listaMemoria[0][0], listaMemoria[0][1], listaMemoria[0][2]) print("Modificando en Tabla:" + listaMemoria[0][1]) print("\tRENAME TABLE:" + listaMemoria[0][2]) print("\tResultado de renombrar tabla:" + str(res)) listaMemoria.pop(0)
def AlterRenameTable(nodo, tablaSimbolos): global useActual global consola base = tablaSimbolos.get(useActual) op = base.renameTable(nodo.idactual, nodo.idnuevo) if op == 0: lib = jBase.alterTable(useActual, nodo.idactual, nodo.idnuevo) if lib == 0: for fk in listaFK: if fk.idtfk == nodo.idactual: fk.idtfk = nodo.idnuevo tablaRF = base.getTabla(fk.idtlocal) columnaRF = tablaRF.getColumna(fk.idclocal) columnaRF.foreign_key["tabla"] = nodo.idnuevo elif fk.idtlocal == nodo.idactual: fk.idtlocal = nodo.idnuevo for cons in listaConstraint: if cons.idtabla == nodo.idactual: cons.idtabla = nodo.idnuevo consola += "La tabla " + nodo.idactual + " se cambio a " + nodo.idnuevo + " exitosamente \n" elif lib == 1: listaSemanticos.append( Error.ErrorS("Error Semantico", "Error en la operacion.")) elif lib == 2: listaSemanticos.append( Error.ErrorS("Error Semantico", "La base de datos " + useActual + " no existe")) elif lib == 3: listaSemanticos.append( Error.ErrorS("Error Semantico", "La tabla " + nodo.idactual + " no existe")) elif lib == 4: listaSemanticos.append( Error.ErrorS("Error Semantico", "La tabla " + nodo.idnuevo + " ya existe")) elif op == 1: listaSemanticos.append( Error.ErrorS("Error Semantico", "La tabla con nombre " + nodo.idnuevo + " ya existe")) elif op == 2: listaSemanticos.append( Error.ErrorS("Error Semantico", "La tabla con nombre " + nodo.idactual + " no existe"))
def updateTable(self, database: Database, tableOld: str, tableNew: str, line, column): """ Method to update the name of a table in database :param database: Table database :param tableOld: The old name of the table :param tableNew: The new name of the table :param line: The instruction line :param column: The instruction column :return: Returns nothing """ dbStatement = jsonMode.alterTable(database.name, tableOld, tableNew) if dbStatement == 0: table = self.searchTable(database, tableOld) table.name = tableNew self.writeFile() print('Table updated successfully') elif dbStatement == 1: desc = f": Can't update Table {tableOld}" ErrorController().addExecutionError(34, 'Execution', desc, line, column) elif dbStatement == 2: desc = f": Database {database.name} does not exist" ErrorController().addExecutionError(35, 'Execution', desc, line, column) elif dbStatement == 3: desc = f": Table {tableOld} does not exist" ErrorController().addExecutionError(27, 'Execution', desc, line, column) elif dbStatement == 4: desc = f": Table {tableNew} already exists" ErrorController().addExecutionError(31, 'Execution', desc, line, column)
def cmd_alterTable(self, database, tableOld, tableNew): if existeTabla(tableOld, database) == 1: self.tabla.modificarNombreTabla_TS(database, tableOld, tableNew) EDDResp.alterTable(condb.alterTable(database, tableOld, tableNew))
print(j.showDatabases()) # drop db3 and db1, return two 0's print(j.dropDatabase("db3")) print(j.dropDatabase("db1")) # show empty-list of databases print(j.showDatabases()) # again create db1 and db2, return two 0's and show return list of databases print(j.createDatabase("db1")) print(j.createDatabase("db2")) print(j.showDatabases()) # create two table in db1 and show return tables list of db1 database print(j.createTable("db1", "table1", 5)) print(j.createTable("db1", "table2", 8)) print(j.showTables("db1")) # rename table1 to table 3 and show return tables list of db1 database print(j.alterTable("db1", "table1","table3")) print(j.showTables("db1")) # drop table3 of db1 and show return tables list of db1 database print(j.dropTable("db1", "table3")) print(j.showTables("db1")) # drop db1 with tables, first return 0 and second return None print(j.dropDatabase("db1")) print(j.showTables("db1"))
# test Databases CRUD print(j.createDatabase('db1')) # 0 print(j.createDatabase('db1')) # 2 print(j.createDatabase('db4')) # 0 print(j.createDatabase('db5')) # 0 print(j.createDatabase(0)) # 1 print(j.alterDatabase('db5', 'db1')) # 3 print(j.alterDatabase('db5', 'db2')) # 0 print(j.dropDatabase('db4')) # 0 print(j.showDatabases()) # ['db1','db2'] # test Tables CRUD print(j.createTable('db1', 'tb4', 3)) # 0 print(j.createTable('db1', 'tb4', 3)) # 3 print(j.createTable('db1', 'tb1', 3)) # 0 print(j.createTable('db1', 'tb2', 3)) # 0 print(j.alterTable('db1', 'tb4', 'tb3')) # 0 print(j.dropTable('db1', 'tb3')) # 0 print(j.alterAddPK('db1', 'tb1', 0)) # 1 print(j.alterAddPK('db1', 'tb1', [0])) # 0 print(j.showTables('db1')) # ['tb1', 'tb2'] # test Registers CRUD print(j.insert('db1', 'tb1', [1, 1])) # 5 print(j.insert('db1', 'tb1', ['1', 'line', 'one'])) # 0 print(j.loadCSV('tb1.csv', 'db1', 'tb1')) # [0, 0, 0, 0, 0] print(j.extractTable('db1', 'tb1')) # [['1', 'line', 'one'], ['2', 'line', 'two'], # ['3', 'line', 'three'], ['4', 'line', 'four'], # ['5', 'line', 'five'], ['6', 'line', 'six']]