Beispiel #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)
Beispiel #2
0
    def from_source(name, type):
        groups = re.match(r'(\w+)(?:\((\d+)(?:, (\d+)) * \))*\s*(NOT NULL)?',
                          type)

        if (groups.group(1) == 'struct'):
            return Column(name,
                          groups.group(1),
                          fields=GlueTranslator.parse_struct(type))
        else:
            nullable = False if groups.group(4) else True

            if groups.group(2) and groups.group(3):
                return Column(
                    name,
                    GlueTranslator.TRANSLATION[groups.group(1)]['translation'],
                    numeric_precision=groups.group(2),
                    scale=groups.group(3),
                    nullable=nullable)
            elif groups.group(2):
                return Column(
                    name,
                    GlueTranslator.TRANSLATION[groups.group(1)]['translation'],
                    length=groups.group(2),
                    nullable=nullable)
            else:
                return Column(
                    name,
                    GlueTranslator.TRANSLATION[groups.group(1)]['translation'],
                    nullable=nullable)
def deletecolonne():
    rowid = request.form['rowid']
    column = Column(rowid)
    db = get_db()
    cur = db.cursor()
    column.delete(cur, rowid)
    db.commit()
    return redirect(url_for('home'))
def addcolonne():
    col = request.form['column']
    idtab = request.form['idtabe']
    column = Column(title=col, table_id=idtab)
    db = get_db()
    cur = db.cursor()
    column.insert(cur)
    db.commit()

    return redirect(url_for('home'))
Beispiel #5
0
 def generateHiddenPK(self, nombreTabla):
     typeChecker = TypeChecker()
     tipoEscondido = {
         '_tipoColumna': 'HIDDEN',
         '_paramOne': None,
         '_paramTwo': None
     }
     columnaEscondida = Column('HIDDEN', tipoEscondido)
     columnaEscondida._primaryKey = True
     tableToInsert = typeChecker.searchTable(SymbolTable().useDatabase,
                                             nombreTabla)
     typeChecker.createColumnTable(tableToInsert, columnaEscondida, 0, 0)
     print('### SE HA GENERADO UNA LLAVE PRIMARIA ESCONDIDA')
Beispiel #6
0
    def generateColumns(self, nombreTabla, typeChecker):
        for columna in self._column_list:
            if isinstance(columna, CreateCol):
                # columna._paramOne
                # columna._paraTwos
                # columna._tipoColumna
                tipoFinal = {
                    '_tipoColumna': str(columna._type_column._tipoColumna),
                    '_paramOne': columna._type_column._paramOne,
                    '_paramTwo': columna._type_column._paramTwo
                }
                columnaFinal = Column(columna._column_name, tipoFinal)
                if columna._properties != None:
                    for prop in columna._properties:
                        columnaFinal = self.addPropertyes(prop, columnaFinal)

                tableToInsert = typeChecker.searchTable(
                    SymbolTable().useDatabase, nombreTabla)
                validateCol = typeChecker.createColumnTable(
                    tableToInsert, columnaFinal, 0, 0)

                # if return None an error ocurrio
                if validateCol == None:
                    self._can_create_flag = False
                    return
Beispiel #7
0
def add_column_post():
    name = request.form.get('columnName')

    column = Column(name=name, idTable='newcol')
    db = get_db()
    cur = db.cursor()
    try:
        user.insert(cur)
    except sqlite3.IntegrityError:
        return render_template(
            'index.html',
            error_msg="This column  is already created.",
        )
    db.commit()
Beispiel #8
0
    def agregarCol(self, columna, nombreTabla):
        typeChecker = TypeChecker()

        tipoFinal = {
            '_tipoColumna': str(columna._type_column._tipoColumna),
            '_paramOne': columna._type_column._paramOne,
            '_paramTwo': columna._type_column._paramTwo
        }

        columnaFinal = Column(columna._column_name, tipoFinal)
        tableToInsert = typeChecker.searchTable(SymbolTable().useDatabase,
                                                nombreTabla)
        validateCol = typeChecker.createColumnTable(tableToInsert,
                                                    columnaFinal, 0, 0)
        # if return None an error ocurrio
        if validateCol == None:
            return
Beispiel #9
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)
Beispiel #10
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)
Beispiel #11
0
    def generateColumns(self, nombreTabla, typeChecker):
        for columna in self._column_list:
            if isinstance(columna, CreateCol):
                #columna._paramOne
                #columna._paraTwos
                #columna._tipoColumna
                tipoFinal = {
                    '_tipoColumna': str(columna._type_column._tipoColumna),
                    '_paramOne': columna._type_column._paramOne,
                    '_paramTwo': columna._type_column._paramTwo
                }
                columnaFinal = Column(columna._column_name, tipoFinal)
                if columna._properties != None:
                    for prop in columna._properties:
                        columnaFinal = self.addPropertyes(prop, columnaFinal)

                tableToInsert = typeChecker.searchTable(
                    SymbolTable().useDatabase, nombreTabla)
                typeChecker.createColumnTable(
                    tableToInsert, columnaFinal, 0,
                    0)  #TODO add name of Database, line and column
Beispiel #12
0
def columnreplacer(wort: str, cols: list):
    #it checks, if the word is one of the columns and replaces it
    if wort.lower() in cols:
        return Column(wort)
    else:
        return wort
Beispiel #13
0
 def get_columns(self):
     adql_columns = self.__adql_table.select_columns()
     column_list = [Column(col) for col in adql_columns]
     return column_list
Beispiel #14
0
 def get_column_by_name(self, name):
     return Column(self.__adql_table.select_column_by_name(name))
Beispiel #15
0
from models.work import Work


def make_dicts(cursor, row):
    return dict(
        (cursor.description[idx][0], value) for idx, value in enumerate(row))


db = sqlite3.connect('.data/db.sqlite')
db.row_factory = make_dicts

cur = db.cursor()

User.create_table(cur)
Task.create_table(cur)
Column.create_table(cur)
Work.create_table(cur)

users = [
    User("Rida", "*****@*****.**", "12345"),
    User("Pavel", "*****@*****.**", "12345"),
    User("Toto", "*****@*****.**", "12345"),
]

tasks = [
    Task(content="Conception", author_id="*****@*****.**", column_id=1),
    Task(content="Analysis", author_id="*****@*****.**", column_id=2),
    Task(content="Test", author_id="*****@*****.**", column_id=1),
    Task(content="Repport", author_id="*****@*****.**", column_id=1),
    Task(content="Algorithms", author_id="*****@*****.**", column_id=3),
]
Beispiel #16
0
from models.task import Task


def make_dicts(cursor, row):
    return dict(
        (cursor.description[idx][0], value) for idx, value in enumerate(row))


db = sqlite3.connect('.data/db.sqlite')
db.row_factory = make_dicts

cur = db.cursor()

User.create_table(cur)
Table.create_table(cur)
Column.create_table(cur)
Task.create_table(cur)

users = [
    User("Ford", "zda", "*****@*****.**", "12345"),
    User("Arthur", "firero", "*****@*****.**", "12345"),
    User("ismail", "Aissami", "[email protected]", "12345"),
    User("sana", "kriaa", "*****@*****.**", "aaa")
]

tables = [Table("Table1", "[email protected]"), Table("Table2", "[email protected]")]

columns = [Column("colonne1", "Table1"), Column("colonne2", "Table1")]

tasks = [Task("descrep1", "colonne1"), Task("descrep2", "colonne1")]
Beispiel #17
0
 def from_source(name, type, length, numeric_precision, precision_radix,
                 scale, default, nullable):
     return Column(name,
                   RedshiftTranslator.TRANSLATION[type]['translation'],
                   length, numeric_precision, precision_radix, scale,
                   default, nullable)