Exemplo n.º 1
0
    def loadData(self):
        self._typeCheckerList = []
        self.openFile()

        for db in self._dataFile:
            self._typeCheckerList.append(Database(db['_name']))
            database = self.searchDatabase(db['_name'])

            for tb in db['_tables']:
                table = Table(tb['_name'])
                database.tables.append(table)

                for col in tb['_colums']:
                    column = Column(col['_name'], col['_dataType'])
                    column.number = col['_number']
                    column.length = col['_length']
                    column.default = col['_default']
                    column.notNull = col['_notNull']
                    column.unique = col['_unique']
                    column.constraint = col['_constraint']
                    column.check = col['_check']
                    column.primaryKey = col['_primaryKey']
                    # column.autoincrement = col['_autoincrement']
                    # TODO FOREIGN KEY implementation column.foreignKey = col['_foreignKey']
                    table.columns.append(column)
Exemplo n.º 2
0
    def createColumnTable(self, table: Table, column: Column, noLine,
                          noColumn):
        """
        Method to create a column in table

        :param table: The name of table
        :param column: Number of columns
        :param noLine: The instruction line
        :param noColumn: The instruction column
        :return: Returns nothing
        """
        database = SymbolTable().useDatabase
        if not database:
            desc = f": Database not selected"
            ErrorController().add(4, 'Execution', desc, noLine, noColumn)
            return

        if self.searchColumn(table, column.name):
            desc = f": Column {column.name} already exists"
            ErrorController().add(29, 'Execution', desc, noLine, noColumn)
            return

        dbStatement = data_mode.mode(database.mode).alterAddColumn(
            database.name.lower(), table.name.lower(), column.default)

        if dbStatement == 0:
            if len(table.columns) > 0:
                column.number = table.columns[-1].number + 1

            table.columns.append(column)
            self.writeFile()
            DataWindow().consoleText(
                'Query returned successfully: Table updated')
            return True

        elif dbStatement == 1:
            desc = f": Can't update table {table.name}"
            ErrorController().add(34, 'Execution', desc, noLine, noColumn)

        elif dbStatement == 2:
            desc = f": Database {database.name} does not exist"
            ErrorController().add(35, 'Execution', desc, noLine, noColumn)

        elif dbStatement == 3:
            desc = f": Table {table.name} does not exist"
            ErrorController().add(27, 'Execution', desc, noLine, noColumn)
Exemplo n.º 3
0
    def createColumnTable(self, database: Database, table: Table,
                          column: Column, noLine, noColumn):
        """
        Method to create a column in table

        :param database: Table database
        :param table: The name of table
        :param column: Number of columns
        :param noLine: The instruction line
        :param noColumn: The instruction column
        :return: Returns nothing
        """
        dbStatement = jsonMode.alterAddColumn(database.name, table.name,
                                              column.default)

        if dbStatement == 0:
            if not self.searchColumn(table, column.name):
                if len(table.columns) > 0:
                    column.number = table.columns[-1].number + 1

                table.columns.append(column)
                self.writeFile()
                print('Table updated successfully')
                return

            jsonMode.alterDropColumn(database.name, table.name, column.number)
            desc = f": Column {column.name} already exists"
            ErrorController().addExecutionError(29, 'Execution', desc, noLine,
                                                noColumn)

        elif dbStatement == 1:
            desc = f": Can't update table {table.name}"
            ErrorController().addExecutionError(34, 'Execution', desc, noLine,
                                                noColumn)

        elif dbStatement == 2:
            desc = f": Database {database.name} does not exist"
            ErrorController().addExecutionError(35, 'Execution', desc, noLine,
                                                noColumn)

        elif dbStatement == 3:
            desc = f": Table {table.name} does not exist"
            ErrorController().addExecutionError(27, 'Execution', desc, noLine,
                                                noColumn)