def execute(self, environment): form_data = {'nameDB': instruction.dbtemp, 'nameTab': self.name} resp = requests.post('http://127.0.0.1:9998/TABLE/extractTable', json=form_data) json1 = json.loads(resp.text) valor = json1["code"] if valor == 1: instruction.semanticErrors.append([ "La tabla " + str(self.name) + " no pertenece a la base de datos " + instruction.dbtemp, self.row, ]) instruction.syntaxPostgreSQL.append("Error: 42P01: la relacion " + instruction.dbtemp + "." + str(self.name) + " no existe") return "FATAL ERROR TABLE ID" # Almacena una lista con con el nombre y tipo de cada columna lst = Struct.extractColumns(instruction.dbtemp, self.name) columns = [l.name for l in lst] newColumns = [self.name + "." + col for col in columns] df = pd.DataFrame(result, columns=newColumns) environment.addTable(self.name) tempTypes = {} for i in range(len(newColumns)): tempTypes[newColumns[i]] = lst[i].type return [df, tempTypes]
def execute(self, environment): Struct.load() Index = File.importFile("Index") exists = Index.get(self.name) result = [] if not exists: if self.exists: result.append("El INDEX : " + self.name + " no existe") else: result.append("Error: El INDEX : " + self.name + " no existe") return result if not self.id: exists = Index.get(self.newName) if not exists: Index[self.newName] = Index.pop(self.name) result.append("Se cambio el nombre del INDEX : " + self.name + " a " + self.newName) else: result.append("Error: El INDEX : " + self.newName + " ya existe") else: column = self.newName index = Index[self.name] for c in index["Columns"]: if c["Name"] == column: if type(self.id) == int: table = index["Table"] columns = Struct.extractColumns( instruction.dbtemp, table) if columns: if self.id > len(columns): result.append("Error fatal: INDEX " + self.name + "numero de columna invalido") else: col = columns[self.id - 1].name c["Name"] = col result.append("INDEX : " + self.name + " cambio la columna " + column + " por " + col) else: result.append("Error fatal: INDEX " + self.name) else: c["Name"] = self.id result.append("INDEX : " + self.name + " cambio la columna " + column + " por " + self.id) Index[self.name] = index break if result == []: result.append("Error fatal: INDEX " + self.name + " columna invalida : " + self.newName) File.exportFile(Index, "Index") return result
def ambiguityBetweenColumns(self, column): """ Encargada de buscar ambiguedad de una columna entre todas las tablas de la clausula FROM """ env = self i = 0 table = None for t in env.tables: lst = Struct.extractColumns(env.database, t) for l in lst: if l.name == column: i += 1 table = t break if i > 1: print("Error: Existe ambiguedad entre la culumna:", column) return [True, None] return [False, table]