Search in sources :

Example 96 with Column

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);
}
Also used : ValueString(org.h2.value.ValueString) ConditionAndOr(org.h2.expression.ConditionAndOr)

Example 97 with Column

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;
}
Also used : Value(org.h2.value.Value) Row(org.h2.result.Row) SearchRow(org.h2.result.SearchRow)

Example 98 with Column

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);
    }
}
Also used : Value(org.h2.value.Value) DbException(org.h2.message.DbException) SQLException(java.sql.SQLException)

Example 99 with Column

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);
    }
}
Also used : Value(org.h2.value.Value) DbException(org.h2.message.DbException) SQLException(java.sql.SQLException)

Example 100 with Column

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);
    }
}
Also used : Value(org.h2.value.Value) DbException(org.h2.message.DbException) SQLException(java.sql.SQLException)

Aggregations

Column (org.h2.table.Column)146 Value (org.h2.value.Value)83 IndexColumn (org.h2.table.IndexColumn)79 DbException (org.h2.message.DbException)64 SQLException (java.sql.SQLException)60 Expression (org.h2.expression.Expression)55 ExpressionColumn (org.h2.expression.ExpressionColumn)51 ValueString (org.h2.value.ValueString)34 AlterTableAlterColumn (org.h2.command.ddl.AlterTableAlterColumn)32 ValueExpression (org.h2.expression.ValueExpression)30 ArrayList (java.util.ArrayList)27 PreparedStatement (java.sql.PreparedStatement)26 Index (org.h2.index.Index)26 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)25 Table (org.h2.table.Table)25 AlterTableRenameColumn (org.h2.command.ddl.AlterTableRenameColumn)22 GridH2Table (org.apache.ignite.internal.processors.query.h2.opt.GridH2Table)21 AlterTableAddConstraint (org.h2.command.ddl.AlterTableAddConstraint)21 StatementBuilder (org.h2.util.StatementBuilder)19 Constraint (org.h2.constraint.Constraint)18