示例#1
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
示例#2
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()