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;
}
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);
}
}
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;
}
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());
}
}
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);
}
Aggregations