示例#1
0
 def ejecutar(self):
     global resultadotxt
     global cont
     global tabla
     global NombreDB
     for alteracion in self.altertb2:
         if alteracion.texto and alteracion.texto.lower() == "add":
             if alteracion.addprop.texto and alteracion.addprop.texto.lower(
             ) == "column":
                 NuevaColumna = alteracion.addprop.lista
                 try:
                     resultado = func.alterAddColumn(
                         NombreDB, self.iden, NuevaColumna.iden)
                     if resultado == 2:
                         resultadotxt += "No existe la base de datos " + NombreDB + "\n"
                     elif resultado == 3:
                         resultadotxt += "No existe la tabla " + self.iden + "\n"
                     else:
                         BuscarTabla = tabla.BuscarNombre(self.iden)
                         BuscarTabla.coltab += 1
                         tabla.actualizar(BuscarTabla)
                         NuevoSimboloColumna = TS.Simbolo(
                             cont, NuevaColumna.iden, TS.TIPO.COLUMN,
                             BuscarTabla.id, 0, NuevaColumna.tipo, 0, "",
                             "", False, "", (BuscarTabla.coltab - 1))
                         cont += 1
                         tabla.agregar(NuevoSimboloColumna)
                         resultadotxt += "Se agrego la columna " + NuevoSimboloColumna.nombre + " a la tabla " + self.iden + "\n"
                 except:
                     """ERROR SEMANTICO"""
         if alteracion.texto and alteracion.texto.lower() == "drop column":
             try:
                 ColumnaABorrar = tabla.BuscarNombre(alteracion.iden)
                 resultado = func.alterDropColumn(NombreDB, self.iden,
                                                  ColumnaABorrar.numcol)
                 if resultado == 2:
                     resultadotxt += "La base de datos " + NombreDB + " No existe \n"
                 elif resultado == 3:
                     resultadotxt += "No se encontro la tabla " + self.iden + " en la base de datos " + NombreDB + "\n"
                 elif resultado == 4:
                     resultadotxt += "La columna " + ColumnaABorrar.nombre + " Es llave primaria" + "\n"
                 elif resultado == 5:
                     resultadotxt += "La columna " + ColumnaABorrar.nombre + " No existe" + "\n"
                 else:
                     tabla.simbolos.pop(ColumnaABorrar.id)
                     resultadotxt += "Se elimino la columna " + ColumnaABorrar.nombre + " de la tabla " + self.iden + "\n"
             except:
                 """ERROR SEMANTICO"""
示例#2
0
 def ejecutar(self):
     global resultadotxt
     global cont
     global tabla
     global NombreDB
     if self.altertb2.text.lower() == "add column":
         try:
             resultado = func.alterAddColumn(NombreDB, self.iden,
                                             self.altertb2.iden)
             if resultado == 2:
                 resultadotxt += "No existe la base de datos " + NombreDB + "\n"
             elif resultado == 3:
                 resultadotxt += "No existe la tabla " + self.iden + "\n"
             else:
                 buscar = tabla.BuscarNombre(self.iden)
                 columna = self.altertb2
                 buscar.coltab += 1
                 tabla.actualizar(buscar)
                 NuevaColumna = TS.Simbolo(cont, columna.iden,
                                           TS.TIPO.COLUMN, buscar.id, 0,
                                           columna.tipo, 0, "", "", False,
                                           "", (buscar.coltab - 1))
                 cont += 1
                 tabla.agregar(NuevaColumna)
                 resultadotxt += "Se agrego la columna " + self.altertb2.iden + " a la tabla " + self.iden + "\n"
         except:
             """ERROR SEMANTICO"""
     elif self.altertb2.text.lower() == "drop column":
         try:
             delcolumna = tabla.BuscarNombre(self.altertb2.iden)
             resultado = func.alterDropColumn(NombreDB, self.iden,
                                              delcolumna.numcol)
             if resultado == 2:
                 resultadotxt += "La base de datos " + NombreDB + " No existe \n"
             elif resultado == 3:
                 resultadotxt += "No se encontro la tabla " + self.iden + " en la base de datos " + NombreDB + "\n"
             elif resultado == 4:
                 resultadotxt += "La columna " + self.altertb2.iden + " Es llave primaria" + "\n"
             elif resultado == 5:
                 resultadotxt += "La columna " + self.altertb2.iden + " No existe" + "\n"
             else:
                 tabla.simbolos.pop(delcolumna.id)
                 resultadotxt += "Se elimino la columna " + self.altertb2.iden + " de la tabla " + self.iden + "\n"
         except:
             """ERROR SEMANTICO"""
示例#3
0
文件: alter.py 项目: edgarJ91/tytus
 def execute(self, table: SymbolTable, tree):
     super().execute(table, tree)
     result_table_name = self.table_name.execute(table, tree)
     result_field_name = self.field_name.execute(table, tree)
     # Obtaining all fields because are gonna be needed to get correct field and update indexes later
     all_fields_symbol = table.get_fields_from_table(result_table_name)
     column_symbol = next((sym for sym in all_fields_symbol
                           if sym.field_name == result_field_name), None)
     result = alterDropColumn(table.get_current_db(), result_field_name,
                              column_symbol.field_index)
     if result == 1:
         raise Error(0, 0, ErrorType.RUNTIME, '5800: system_error')
         return False
     elif result == 2:
         # log error, old database name does not exists
         raise Error(0, 0, ErrorType.RUNTIME,
                     '42P04: database_does_not_exists')
         return False
     elif result == 3:
         # log error, table does not exists
         raise Error(0, 0, ErrorType.RUNTIME,
                     '42P04: table_does_not_exists')
         return False
     elif result == 4:
         # log error, PK cannot be deleted or table to be empty
         raise Error(0, 0, ErrorType.RUNTIME,
                     '2300: integrity_constraint_violation')
         return False
     elif result == 4:
         # log error, column out of index
         raise Error(0, 0, ErrorType.RUNTIME, '2300: column_out_of_index')
         return False
     else:
         for field in all_fields_symbol:
             # Update indexes for higher fields
             if field.field_index > column_symbol:
                 field.field_index -= 1
                 table.update(field)
         # TODO just realized it's needed to check for FKs in other tables
         # finally delete symbol of column removed
         table.delete(column_symbol.id)
         return True
示例#4
0
 def execute(self, table, tree):
     super().execute(table, tree)
     result_table_name = self.table_name.execute(table, tree)
     result_field_name = self.field_name.execute(table, tree)
     result = alterDropColumn('db_name_from_st', result_field_name, 'column_number_from_st')
     if result == 1:
         # log error on operation
         return False
     elif result == 2:
         # log error, old database name does not exists
         return False
     elif result == 3:
         # log error, table does not exists
         return False
     elif result == 4:
         # log error, PK cannot be deleted or table to be empty
         return False
     elif result == 4:
         # log error, column out of index
         return False
     else:
         return True