Example #1
0
    def agregarNuevoTipo(self, tablaAMod, colAMod, nuevoTipo):
        typeChecker = TypeChecker()
        bandera = False
        tableToAlter = typeChecker.searchTable(SymbolTable().useDatabase,
                                               tablaAMod)

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

        for columna in tableToAlter.columns:
            if (columna._name == colAMod):
                bandera = True
                columna._dataType = tipoFinal
                break

        if not bandera:
            desc = f": Undefined column in alter type ()"
            ErrorController().add(26, 'Execution', desc, 0, 0)
            return
        bandera = False
        typeChecker.writeFile()
        pass
Example #2
0
    def agregarCheck(self, conditionColumn, tablaId):
        typeChecker = TypeChecker()
        bandera = False
        tableToAlter = typeChecker.searchTable(SymbolTable().useDatabase,
                                               tablaId)

        #                           L (L|D)*
        whatColumnIs = re.search('[a-zA-z]([a-zA-z]|[0-9])*',
                                 conditionColumn.alias)

        if whatColumnIs != None:
            whatColumnIs = whatColumnIs.group(0)
            for columna in tableToAlter.columns:
                if (columna._name == whatColumnIs):
                    bandera = True
                    columna._check = conditionColumn.alias
                    break
            if not bandera:
                desc = f": Undefined column in alter check ()"
                ErrorController().add(26, 'Execution', desc, 0, 0)
                return
            bandera = False

        else:
            desc = f": column not given in check()"
            ErrorController().add(26, 'Execution', desc, 0, 0)
            return
        typeChecker.writeFile()
Example #3
0
    def agregarFk(self, listaCols, nombreTabla, listaTablasCols, tablaAAlter):

        typeChecker = TypeChecker()

        # the len of the cols must be de same
        if len(listaCols) != len(listaTablasCols):
            desc = f": cantidad of params in foreign() != "
            ErrorController().add(36, 'Execution', desc, 0, 0)
            return

        existForeingTable = typeChecker.searchTable(SymbolTable().useDatabase,
                                                    nombreTabla)
        tableToAlter = typeChecker.searchTable(SymbolTable().useDatabase,
                                               tablaAAlter)

        # validate if the foreign table exists
        if existForeingTable == None:
            desc = f": Undefined table in foreign key ()"
            ErrorController().add(27, 'Execution', desc, 0, 0)
            return

        # validate if the columns exists in the foreign table
        for coli in listaTablasCols:
            if typeChecker.searchColumn(existForeingTable, coli) == None:
                desc = f": Undefined col in table in foreign key ()"
                ErrorController().add(26, 'Execution', desc, 0, 0)
                return

        bandera = False
        for x in range(0, len(listaCols)):
            for columna in tableToAlter.columns:
                if (columna._name == listaCols[x]):
                    bandera = True
                    columna._foreignKey = {
                        '_refTable': nombreTabla,
                        '_refColumn': listaTablasCols[x]
                    }
                    break
            if not bandera:
                desc = f": Undefined column in alter foreign key ()"
                ErrorController().add(26, 'Execution', desc, 0, 0)
                return
            bandera = False

        typeChecker.writeFile()
Example #4
0
    def existsPK(self, tableCreated):
        indicesPrimarios = 0
        typeChecker = TypeChecker()
        tablaToExtract = typeChecker.searchTable(SymbolTable().useDatabase,
                                                 tableCreated)

        for colExt in tablaToExtract._colums:
            if colExt._primaryKey == True:
                indicesPrimarios += 1

        return indicesPrimarios
Example #5
0
    def addInherits(self, nameChildTable, nameParentTable):
        typeChecker = TypeChecker()
        tablaPadre = typeChecker.searchTable(SymbolTable().useDatabase,
                                             nameParentTable)
        tablaHija = typeChecker.searchTable(SymbolTable().useDatabase,
                                            nameChildTable)

        # La tabla de la que hereda no existe
        if tablaPadre == None:
            desc = f": parent table dont exists"
            ErrorController().add(27, 'Execution', desc, 0, 0)
            self._can_create_flag = False
            return

        for colPar in tablaPadre._colums:
            # Vamos a insertar en la hija
            validarCol = typeChecker.createColumnTable(tablaHija, colPar, 0, 0)
            # Si es una columna repetida entonces no puede crear la tabla
            if validarCol == None:
                self._can_create_flag = False
                return
Example #6
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')
Example #7
0
    def addPKToDB(self, tableCreated):
        indicesPrimarios = []
        typeChecker = TypeChecker()
        tablaToExtract = typeChecker.searchTable(SymbolTable().useDatabase,
                                                 tableCreated)

        for colExt in tablaToExtract._colums:
            if colExt._primaryKey == True:
                indicesPrimarios.append(colExt._number)
        if len(indicesPrimarios) == 0:
            pass
        else:
            DataController().alterAddPK(tableCreated, indicesPrimarios, 0, 0)
Example #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
Example #9
0
    def addForeignKey(self, listaCols, nombreTabla, listaTablasCols):

        # the len of the cols must be de same
        if len(listaCols) != len(listaTablasCols):
            desc = f": cant of params in foreign() != "
            ErrorController().add(36, 'Execution', desc, 0, 0)
            self._can_create_flag = False
            return

        typeChecker = TypeChecker()
        existForeingTable = typeChecker.searchTable(SymbolTable().useDatabase,
                                                    nombreTabla)

        # validate if the foreign table exists
        if existForeingTable == None:
            desc = f": Undefined table in foreign key ()"
            ErrorController().add(27, 'Execution', desc, 0, 0)
            self._can_create_flag = False
            return

        # validate if the columns exists in the foreign table
        for coli in listaTablasCols:
            if typeChecker.searchColumn(existForeingTable, coli) == None:
                desc = f": Undefined col in table in foreign key ()"
                ErrorController().add(26, 'Execution', desc, 0, 0)
                self._can_create_flag = False
                return

        bandera = False
        for x in range(0, len(listaCols)):
            for columna in self._column_list:
                if isinstance(columna, CreateCol):
                    if (columna._column_name == listaCols[x]):
                        if columna._properties != None:
                            bandera = True
                            columna._properties[0]['fk_references_to'] = {
                                '_refTable': nombreTabla,
                                '_refColumn': listaTablasCols[x]
                            }
                            break
            if not bandera:
                desc = f": Undefined column in foreign key ()"
                ErrorController().add(26, 'Execution', desc, 0, 0)
                self._can_create_flag = False
                return
            bandera = False
Example #10
0
    def eliminarColumna(self, nombreTabla, nombreColumna):
        typeChecker = TypeChecker()
        bandera = False
        tableToAlter = typeChecker.searchTable(SymbolTable().useDatabase,
                                               nombreTabla)

        for columna in tableToAlter.columns:
            if (columna._name == nombreColumna):
                bandera = True
                # typeChecker.deleteColumn(tableToAlter,columna,0,0)
                break

        if not bandera:
            desc = f": Undefined column in alter drop column ()"
            ErrorController().add(26, 'Execution', desc, 0, 0)
            return
        bandera = False
        pass
Example #11
0
    def agregarNotNull(self, tablaAMod, colAMod):
        typeChecker = TypeChecker()
        bandera = False
        tableToAlter = typeChecker.searchTable(SymbolTable().useDatabase,
                                               tablaAMod)

        for columna in tableToAlter.columns:
            if (columna._name == colAMod):
                bandera = True
                columna._notNull = True
                break

        if not bandera:
            desc = f": Undefined column in alter not null ()"
            ErrorController().add(26, 'Execution', desc, 0, 0)
            return
        bandera = False
        typeChecker.writeFile()
Example #12
0
    def process(self, instrucction):

        typeChecker = TypeChecker()
        bandera = False
        tableToAlter = typeChecker.searchTable(SymbolTable().useDatabase,
                                               instrucction)

        for columna in tableToAlter.columns:
            if (columna._name == self._oldName):
                bandera = True
                columna._name = self._newName
                break

        if not bandera:
            desc = f": Undefined column in rename column ()"
            ErrorController().add(26, 'Execution', desc, 0, 0)
            return
        bandera = False
        typeChecker.writeFile()
Example #13
0
    def process(self, instruction):
        typeChecker = TypeChecker()

        print('')
        print('VAMOS A MODIFICAR LA SIGUIENTE TABLA')
        print(self._tablaAModificar)

        existTable = typeChecker.searchTable(SymbolTable().useDatabase,
                                             self._tablaAModificar)

        # validate if the table to alter exists
        if existTable == None:
            desc = f": Undefined table in alter table"
            ErrorController().add(27, 'Execution', desc, 0, 0)
            return

        print('y estos son los cambios')
        #  Cambio puede ser un add    (column,check,constraint_unique,foreign_key)
        #                   un alter
        #                   un drop
        #                   un rename
        for cambio in self._listaCambios:
            cambio.process(self._tablaAModificar)