Esempio n. 1
0
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]
Esempio n. 2
0
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]
        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]