def validateConstraint(values, record, database, table, type_): # values = [name,[exp1,exp2,op,type1,type2]] # record = [val1,val2,...,valn] name = values[0] value1 = values[1][0] value2 = values[1][1] op = values[1][2] type1 = values[1][3] type2 = values[1][4] index1 = 0 index1 = 0 if type1 == "ID": index1 = S.getIndex(database, table, value1) value1 = record[index1].value if type2 == "ID": index2 = S.getIndex(database, table, value2) value2 = record[index2].value insert = CheckOperation(value1, value2, type_, op) try: if not insert: lstErr.append("El registro no cumple con la restriccion: ", name) syntaxPostgreErrors.append( "Error: 23000: El registro no cumple con la restriccion " + str(name)) elif insert: return else: lstErr.append(insert) except: lstErr.append(insert)
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 ")