def checkInsert(dbName, tableName, columns, values): lstErr.clear() if columns != None: if len(columns) != len(values): syntaxPostgreErrors.append( "Error: 42611: definicion en numero de columnas invalida ") return ["Columnas fuera de los limites"] table = S.extractTable(dbName, tableName) values = S.getValues(table, columns, values) if table == 0: syntaxPostgreErrors.append("Error: 42000: La base de datos " + str(dbName) + " no existe") return ["Error: No existe la base de datos"] elif table == 1: syntaxPostgreErrors.append("Error: 42P01: La tabla " + str(tableName) + " no existe") return ["Error: No existe la tabla"] elif not values: syntaxPostgreErrors.append("Error: 42P10: Columnas no identificadas ") return ["Error: Columnas no identificadas"] else: pass pks = [] indexCol = 0 for col in table["columns"]: x = Type.get(col["type"]) value = values[indexCol] if not isinstance(value, expression.Primitive): value = expression.Primitive(x, value, 0, 0, 0) values[indexCol] = value if col["PK"]: pks.append(indexCol) indexCol += 1 # Validar la llave primaria if pks: validatePrimary(dbName, tableName, values, pks) indexCol = 0 for value in values: column = table["columns"][indexCol] if value.value != None and value.type != TYPE.NULL: value.value = convertDateTime(value.value, column["type"]) if column["Unique"]: validateUnique(dbName, tableName, value.value, indexCol) if column["FK"] != None: validateForeign(dbName, column["FK"], value.value) if column["Constraint"] != None: validateConstraint(column["Constraint"], values, dbName, tableName, column["type"]) select(column, value) else: value.value = None validateNotNull(column["NN"], column["name"]) indexCol += 1 return [listError(), values]
def checkValue(dbName, tableName): lstErr.clear() table = S.extractTable(dbName, tableName) if table == 0 and table == 1: return for col in table["columns"]: if col["Default"] != None: if col["Default"][1] != 9: value = expression.Primitive(TypeNumber.get(col["Default"][1]), col["Default"][0], 0, 0, 0) select(col, value) if len(lstErr) != 0: col["Default"] = None else: col["Default"] = None return listError()
def p_literal(t): """ literal : INTEGER | STRING | DECIMAL | CHARACTER | R_TRUE | R_FALSE """ if t.slice[1].type == "CHARACTER" or t.slice[1].type == "STRING": tipo = expression.TYPE.STRING elif t.slice[1].type == "R_TRUE" or t.slice[1].type == "R_FALSE": t.slice[1].value = t.slice[1].value == "TRUE" tipo = expression.TYPE.BOOLEAN else: tipo = expression.TYPE.NUMBER t[0] = expression.Primitive(tipo, t.slice[1].value, t.slice[1].lineno, t.slice[1].lexpos)
def checkInsert(dbName, tableName, columns, values): lstErr.clear() S.load() if columns != None: if len(columns) != len(values): return ["Columnas fuera de los limites 1"] table = S.extractTable(dbName, tableName) values = S.getValues(table, columns, values) if table == 0: return ["No existe la base de datos"] elif table == 1: return ["No existe la tabla"] elif len(table["columns"]) != len(values): return ["Columnas fuera de los limites 2"] else: pass indexCol = 0 for value in values: column = table["columns"][indexCol] x = Type.get(column["type"]) if not isinstance(value, expression.Primitive): value = expression.Primitive(x, value, 0, 0) values[indexCol] = value if value != None and value.type != TYPE.NULL: if column["Unique"] or column["PK"]: validateUnique(dbName, tableName, value.value, indexCol) if column["FK"] != None: validateForeign(dbName, column["FK"], value.value) if column["Constraint"] != None: validateConstraint(column["Constraint"], values, dbName, tableName, column["type"]) select(column, value) else: validateNotNull(column["NN"], column["name"]) indexCol += 1 return [listError(), values]