use of org.h2.table.Column in project h2database by h2database.
the class Column method addCheckConstraint.
/**
* Add a check constraint expression to this column. An existing check
* constraint constraint is added using AND.
*
* @param session the session
* @param expr the (additional) constraint
*/
public void addCheckConstraint(Session session, Expression expr) {
if (expr == null) {
return;
}
resolver = new SingleColumnResolver(this);
synchronized (this) {
String oldName = name;
if (name == null) {
name = "VALUE";
}
expr.mapColumns(resolver, 0);
name = oldName;
}
expr = expr.optimize(session);
resolver.setValue(ValueNull.INSTANCE);
// check if the column is mapped
synchronized (this) {
expr.getValue(session);
}
if (checkConstraint == null) {
checkConstraint = expr;
} else {
checkConstraint = new ConditionAndOr(ConditionAndOr.AND, checkConstraint, expr);
}
checkConstraintSQL = getCheckConstraintSQL(session, name);
}
use of org.h2.table.Column in project h2database by h2database.
the class JoinBatch method getValue.
/**
* Get the value for the given column.
*
* @param filterId table filter id
* @param column the column
* @return column value for current row
*/
public Value getValue(int filterId, Column column) {
if (current == null) {
return null;
}
Object x = current.row(filterId);
assert x != null;
Row row = current.isRow(filterId) ? (Row) x : ((Cursor) x).get();
int columnId = column.getColumnId();
if (columnId == -1) {
return ValueLong.get(row.getKey());
}
Value value = row.getValue(column.getColumnId());
if (value == null) {
throw DbException.throwInternalError("value is null: " + column + " " + row);
}
return value;
}
use of org.h2.table.Column in project h2database by h2database.
the class JdbcResultSet method updateBinaryStream.
/**
* Updates a column in the current or insert row.
*
* @param columnLabel the column label
* @param x the value
* @param length the number of characters
* @throws SQLException if the result set is closed or not updatable
*/
@Override
public void updateBinaryStream(String columnLabel, InputStream x, long length) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateBinaryStream(" + quote(columnLabel) + ", x, " + length + "L);");
}
checkClosed();
Value v = conn.createBlob(x, length);
update(columnLabel, v);
} catch (Exception e) {
throw logAndConvert(e);
}
}
use of org.h2.table.Column in project h2database by h2database.
the class JdbcResultSet method updateBlob.
/**
* Updates a column in the current or insert row.
*
* @param columnLabel the column label
* @param x the value
* @throws SQLException if the result set is closed or not updatable
*/
@Override
public void updateBlob(String columnLabel, Blob x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateBlob(" + quote(columnLabel) + ", x);");
}
checkClosed();
Value v;
if (x == null) {
v = ValueNull.INSTANCE;
} else {
v = conn.createBlob(x.getBinaryStream(), -1);
}
update(columnLabel, v);
} catch (Exception e) {
throw logAndConvert(e);
}
}
use of org.h2.table.Column in project h2database by h2database.
the class JdbcResultSet method updateNCharacterStream.
/**
* Updates a column in the current or insert row.
*
* @param columnLabel the column label
* @param x the value
* @param length the number of characters
* @throws SQLException if the result set is closed or not updatable
*/
@Override
public void updateNCharacterStream(String columnLabel, Reader x, long length) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateNCharacterStream(" + quote(columnLabel) + ", x, " + length + "L);");
}
checkClosed();
Value v = conn.createClob(x, length);
update(columnLabel, v);
} catch (Exception e) {
throw logAndConvert(e);
}
}
Aggregations