def execute(self, table: SymbolTable, tree): super().execute(table, tree) result_table_name = self.table_name.execute(table, tree) old_symbol = table.get(result_table_name, SymbolType.TABLE) old_symbol.check_exp = self.validation # Change for append if needed to handle multiple ones table.update(old_symbol) return True
def execute(self, table: SymbolTable, tree): super().execute(table, tree) # result_owner = self.owner.execute(table, tree) old_symbol = table.get(self.name, SymbolType.DATABASE) old_symbol.owner = self.owner.val table.update(old_symbol) return True
def execute(self, table: SymbolTable, tree): super().execute(table, tree) result_field_name = self.field_name result_table_name = self.table_name # Obtaining all fields because are gonna be needed to get correct field 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) column_symbol.allows_null = self.allows_null table.update(column_symbol) return True
def execute(self, table: SymbolTable, tree): super().execute(table, tree) result_field_name = self.old_name result_new_name = self.new_name result_table_name = self.table_name # Obtaining all fields because are gonna be needed to get correct field 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) column_symbol.field_name = result_new_name column_symbol.name = result_new_name table.update(column_symbol) return f'Column {self.old_name} renamed to {self.new_name}'
def execute(self, table: SymbolTable, tree): super().execute(table, tree) result_table_name = self.table_name.execute(table, tree) result_table_column = self.table_column.execute(table, tree) result_table_reference = self.table_reference.execute(table, tree) result_column_reference = self.column_reference.execute(table, tree) # Obtaining all fields because are gonna be needed to get correct field 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_table_column), None) # Obtaining table and column itself, since we need to store id table_reference = table.get(result_table_reference, SymbolType.TABLE) column_reference = table.get(result_column_reference, SymbolType.FIELD) column_symbol.fk_table = table_reference.id column_symbol.fk_field = column_reference.id table.update(column_symbol) return True
def execute(self, table: SymbolTable, tree): super().execute(table, tree) result = alterDatabase(self.name, self.new_name) if result == 1: raise Error(0, 0, ErrorType.RUNTIME, '5800: system_error') elif result == 2: raise Error(0, 0, ErrorType.RUNTIME, '42P04: old_database_does_not_exists') elif result == 3: raise Error(0, 0, ErrorType.RUNTIME, '42P04: new_database_already_exists') else: old_symbol = table.get(self.name, SymbolType.DATABASE) old_symbol.name = self.new_name table.update(old_symbol) return "You renamed table " + str(self.name) + " to " + str( self.new_name)
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