Exemplo n.º 1
0
 def execute(self, table: SymbolTable, tree):
     super().execute(table, tree)
     result_table_name = self.table_name
     result_field_name = self.field_name
     result_field_type = self.field_type.val
     result_field_length = self.field_length
     result = alterAddColumn(table.get_current_db().name, result_table_name,
                             None)
     if result == 1:
         raise Error(0, 0, ErrorType.RUNTIME, '5800: system_error')
     elif result == 2:
         raise Error(0, 0, ErrorType.RUNTIME,
                     '42P04: database_does_not_exists')
     elif result == 3:
         raise Error(0, 0, ErrorType.RUNTIME,
                     '42P04: table_does_not_exists')
     else:
         total_fields = len(table.get_fields_from_table(result_table_name))
         column_symbol = FieldSymbol(table.get_current_db().name,
                                     result_table_name, total_fields + 1,
                                     result_field_name, result_field_type,
                                     result_field_length, self.allows_null,
                                     False, None, None)
         table.add(column_symbol)
         return True
Exemplo n.º 2
0
 def execute(self, table: SymbolTable, tree):
     super().execute(table, tree)
     result_name = self.name.execute(table, tree)
     result_field_type = self.field_type.execute(table, tree)
     result_length = self.length.execute(table, tree)
     return FieldSymbol(table.get_current_db().name, None, 0, result_name,
                        result_field_type, result_length, self.allows_null,
                        self.is_pk, None, None)
Exemplo n.º 3
0
    def execute(self, table: SymbolTable, tree):
        super().execute(table, tree)
        result_name = self.name
        result_inherits_from = self.inherits_from.val if self.inherits_from else None
        result_fields = self.fields
        if result_inherits_from:
            # get inheritance table, if doesn't exists throws semantic error, else append result
            result_fields += table.get_fields_from_table(result_inherits_from)

        result = createTable(table.get_current_db().name, result_name,
                             len(result_fields))

        if result == 1:
            raise Error(self.line, self.column, ErrorType.RUNTIME,
                        '5800: system_error')
        elif result == 2:
            raise Error(self.line, self.column, ErrorType.RUNTIME,
                        '42P04: database_does_not_exists')
        elif result == 3:
            raise Error(self.line, self.column, ErrorType.RUNTIME,
                        '42P07: duplicate_table')
        else:
            # add primary keys, jsonMode needs the number of the column to set it to primarykey
            keys = list(
                map(lambda x: result_fields.index(x),
                    filter(lambda key: key.is_pk is True, result_fields)))
            if len(keys) > 0:
                result = alterAddPK(table.get_current_db().name, result_name,
                                    keys)

            table.add(
                TableSymbol(table.get_current_db().id, result_name,
                            self.check_exp))

        field_index = 0
        for field in result_fields:
            nuevo = FieldSymbol(table.get_current_db().name, result_name,
                                field_index, field.name, field.field_type,
                                field.length, field.allows_null, field.is_pk,
                                None, None)
            field_index += 1
            table.add(nuevo)

        return "Table: " + str(result_name) + " created."