Search in sources :

Example 86 with Value

use of org.h2.value.Value in project h2database by h2database.

the class CreateConstant method update.

@Override
public int update() {
    session.commit(true);
    session.getUser().checkAdmin();
    Database db = session.getDatabase();
    if (getSchema().findConstant(constantName) != null) {
        if (ifNotExists) {
            return 0;
        }
        throw DbException.get(ErrorCode.CONSTANT_ALREADY_EXISTS_1, constantName);
    }
    int id = getObjectId();
    Constant constant = new Constant(getSchema(), id, constantName);
    expression = expression.optimize(session);
    Value value = expression.getValue(session);
    constant.setValue(value);
    db.addSchemaObject(session, constant);
    return 0;
}
Also used : Constant(org.h2.schema.Constant) Database(org.h2.engine.Database) Value(org.h2.value.Value)

Example 87 with Value

use of org.h2.value.Value in project h2database by h2database.

the class ConstraintReferential method setWhere.

private void setWhere(Prepared command, int pos, Row row) {
    for (int i = 0, len = refColumns.length; i < len; i++) {
        int idx = refColumns[i].column.getColumnId();
        Value v = row.getValue(idx);
        ArrayList<Parameter> params = command.getParameters();
        Parameter param = params.get(pos + i);
        param.setValue(v);
    }
}
Also used : Value(org.h2.value.Value) Parameter(org.h2.expression.Parameter)

Example 88 with Value

use of org.h2.value.Value in project h2database by h2database.

the class ConstraintReferential method prepare.

private Prepared prepare(Session session, String sql, ConstraintActionType action) {
    Prepared command = session.prepare(sql);
    if (action != ConstraintActionType.CASCADE) {
        ArrayList<Parameter> params = command.getParameters();
        for (int i = 0, len = columns.length; i < len; i++) {
            Column column = columns[i].column;
            Parameter param = params.get(i);
            Value value;
            if (action == ConstraintActionType.SET_NULL) {
                value = ValueNull.INSTANCE;
            } else {
                Expression expr = column.getDefaultExpression();
                if (expr == null) {
                    throw DbException.get(ErrorCode.NO_DEFAULT_SET_1, column.getName());
                }
                value = expr.getValue(session);
            }
            param.setValue(value);
        }
    }
    return command;
}
Also used : Column(org.h2.table.Column) IndexColumn(org.h2.table.IndexColumn) Expression(org.h2.expression.Expression) Prepared(org.h2.command.Prepared) Value(org.h2.value.Value) Parameter(org.h2.expression.Parameter)

Example 89 with Value

use of org.h2.value.Value in project h2database by h2database.

the class ConstraintCheck method checkRow.

@Override
public void checkRow(Session session, Table t, Row oldRow, Row newRow) {
    if (newRow == null) {
        return;
    }
    filter.set(newRow);
    boolean b;
    try {
        Value v = expr.getValue(session);
        // Both TRUE and NULL are ok
        b = v == ValueNull.INSTANCE || v.getBoolean();
    } catch (DbException ex) {
        throw DbException.get(ErrorCode.CHECK_CONSTRAINT_INVALID, ex, getShortDescription());
    }
    if (!b) {
        throw DbException.get(ErrorCode.CHECK_CONSTRAINT_VIOLATED_1, getShortDescription());
    }
}
Also used : Value(org.h2.value.Value) DbException(org.h2.message.DbException)

Example 90 with Value

use of org.h2.value.Value in project h2database by h2database.

the class ConditionInParameter method getValue.

@Override
public Value getValue(Session session) {
    Value l = left.getValue(session);
    if (l == ValueNull.INSTANCE) {
        return l;
    }
    boolean result = false;
    boolean hasNull = false;
    Value value = parameter.getValue(session);
    if (value instanceof ValueArray) {
        for (Value r : ((ValueArray) value).getList()) {
            if (r == ValueNull.INSTANCE) {
                hasNull = true;
            } else {
                r = r.convertTo(l.getType());
                result = Comparison.compareNotNull(database, l, r, Comparison.EQUAL);
                if (result) {
                    break;
                }
            }
        }
    } else {
        if (value == ValueNull.INSTANCE) {
            hasNull = true;
        } else {
            value = value.convertTo(l.getType());
            result = Comparison.compareNotNull(database, l, value, Comparison.EQUAL);
        }
    }
    if (!result && hasNull) {
        return ValueNull.INSTANCE;
    }
    return ValueBoolean.get(result);
}
Also used : Value(org.h2.value.Value) ValueArray(org.h2.value.ValueArray)

Aggregations

Value (org.h2.value.Value)291 SQLException (java.sql.SQLException)94 DbException (org.h2.message.DbException)91 ResultSet (java.sql.ResultSet)69 PreparedStatement (java.sql.PreparedStatement)61 Statement (java.sql.Statement)53 Column (org.h2.table.Column)44 ValueString (org.h2.value.ValueString)44 JdbcStatement (org.h2.jdbc.JdbcStatement)42 JdbcPreparedStatement (org.h2.jdbc.JdbcPreparedStatement)36 SimpleResultSet (org.h2.tools.SimpleResultSet)31 StatementBuilder (org.h2.util.StatementBuilder)28 IndexColumn (org.h2.table.IndexColumn)23 Expression (org.h2.expression.Expression)22 IOException (java.io.IOException)21 Row (org.h2.result.Row)19 SearchRow (org.h2.result.SearchRow)18 Connection (java.sql.Connection)17 ValueArray (org.h2.value.ValueArray)17 ValueTimestamp (org.h2.value.ValueTimestamp)17