def validateUnique(database, table, value, index): records = jsonMode.extractTable(database, table) if records == []: return for record in records: if value == record[index]: lstErr.append("El Valor " + str(value) + " ya existe dentro de la tabla") syntaxPostgreErrors.append("Error: 23505: El valor " + str(value) + " ya existe dentro de la tabla") break
def validatePrimary(database, table, values, index): records = jsonMode.extractTable(database, table) if records == []: return for record in records: lst1 = [] lst2 = [] for j in index: lst1.append(record[j]) lst2.append(values[j].value) if lst1 == lst2: lstErr.append("Llaves primarias existentes dentro de la tabla") syntaxPostgreErrors.append( "Error: 23505: llaves primarias duplicadas ") break
def validateForeign(database, values, value): # values = [references,column] references = values[0] column = values[1] records = jsonMode.extractTable(database, references) if records == []: syntaxPostgreErrors.append("Error: 23503: El valor " + str(value) + " no es una llave foranea ") lstErr.append("El Valor " + str(value) + " no es una llave foranea") return index = S.getIndex(database, references, column) for record in records: if value == record[index]: return lstErr.append("El Valor " + str(value) + " no es una llave primaria") syntaxPostgreErrors.append("Error: 23505: El valor " + str(value) + " no es una llave primaria ")
def execute(self, environment): result = jsonMode.extractTable(instruction.dbtemp, self.name) if result == None: 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]