def checkInsert(dbName, tableName, columns, values): lstErr.clear() table = S.extractTable(dbName, tableName) 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"] if columns != None: if len(columns) != len(values): syntaxPostgreErrors.append( "Error: 42611: definicion en numero de columnas invalida ") return ["Columnas fuera de los limites"] else: if len(values) != len(table["columns"]): syntaxPostgreErrors.append( "Error: 42611: definicion en numero de columnas invalida ") return ["Columnas fuera de los limites"] values = S.getValues(table, columns, values) if not values: syntaxPostgreErrors.append("Error: 42P10: Columnas no identificadas ") return ["Error: Columnas no identificadas"] pks = [] indexCol = 0 for col in table["columns"]: x = Type.get(col["type"]) value = values[indexCol] if not isinstance(value, Primitive): value = 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 = 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 execute(self, environment): Struct.load() name = self.idIndex if self.existIndex(name): return "Error: ya existe un index con el nombre " + name table = Struct.extractTable(instruction.dbtemp, self.idTable) if table == 1 or table == 0: return ("Error: no existe la tabla " + self.idTable + " en la base de datos " + instruction.dbtemp) try: Index = File.importFile("Index") indexBody = {} indexBody["Table"] = self.idTable indexBody["Unique"] = self.unique indexBody["Method"] = self.usingMethod indexBody["Columns"] = [] for c in self.optList: col = {} col["Name"] = c[0] col["Order"] = c[1] if c[2]: nulls = c[2][0] if c[2][1]: nulls += " " + c[2][1] else: if col["Order"] == "DESC": nulls = "NULLS FIRST" else: nulls = "NULLS LAST" col["Nulls"] = nulls indexBody["Columns"].append(col) Index[name] = indexBody File.exportFile(Index, "Index") return "Index " + name + " creado" except: return "Error fatal"