Search in sources :

Example 61 with Insert

use of org.h2.command.dml.Insert in project h2database by h2database.

the class JdbcResultSet method updateNCharacterStream.

/**
 * Updates a column in the current or insert row.
 *
 * @param columnIndex (1,2,...)
 * @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(int columnIndex, Reader x, long length) throws SQLException {
    try {
        if (isDebugEnabled()) {
            debugCode("updateNCharacterStream(" + columnIndex + ", x, " + length + "L);");
        }
        checkClosed();
        Value v = conn.createClob(x, length);
        update(columnIndex, v);
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : Value(org.h2.value.Value) DbException(org.h2.message.DbException) SQLException(java.sql.SQLException)

Example 62 with Insert

use of org.h2.command.dml.Insert in project h2database by h2database.

the class JdbcResultSet method updateClob.

/**
 * Updates a column in the current or insert row.
 *
 * @param columnIndex (1,2,...)
 * @param x the value
 * @throws SQLException if the result set is closed or not updatable
 */
@Override
public void updateClob(int columnIndex, Clob x) throws SQLException {
    try {
        if (isDebugEnabled()) {
            debugCode("updateClob(" + columnIndex + ", x);");
        }
        checkClosed();
        Value v;
        if (x == null) {
            v = ValueNull.INSTANCE;
        } else {
            v = conn.createClob(x.getCharacterStream(), -1);
        }
        update(columnIndex, v);
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : Value(org.h2.value.Value) DbException(org.h2.message.DbException) SQLException(java.sql.SQLException)

Example 63 with Insert

use of org.h2.command.dml.Insert in project h2database by h2database.

the class JdbcResultSet method updateBlob.

/**
 * Updates a column in the current or insert row.
 *
 * @param columnIndex (1,2,...)
 * @param x the value
 * @param length the length
 * @throws SQLException if the result set is closed or not updatable
 */
@Override
public void updateBlob(int columnIndex, InputStream x, long length) throws SQLException {
    try {
        if (isDebugEnabled()) {
            debugCode("updateBlob(" + columnIndex + ", x, " + length + "L);");
        }
        checkClosed();
        Value v = conn.createBlob(x, length);
        update(columnIndex, v);
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : Value(org.h2.value.Value) DbException(org.h2.message.DbException) SQLException(java.sql.SQLException)

Example 64 with Insert

use of org.h2.command.dml.Insert in project h2database by h2database.

the class JdbcResultSet method updateRow.

/**
 * Updates the current row.
 *
 * @throws SQLException if the result set is closed, if the current row is
 *             the insert row or if not on a valid row, or if the result set
 *             it not updatable
 */
@Override
public void updateRow() throws SQLException {
    try {
        debugCodeCall("updateRow");
        checkUpdatable();
        if (insertRow != null) {
            throw DbException.get(ErrorCode.NOT_ON_UPDATABLE_ROW);
        }
        checkOnValidRow();
        if (updateRow != null) {
            UpdatableRow row = getUpdatableRow();
            Value[] current = new Value[columnCount];
            for (int i = 0; i < updateRow.length; i++) {
                current[i] = get(i + 1);
            }
            row.updateRow(current, updateRow);
            for (int i = 0; i < updateRow.length; i++) {
                if (updateRow[i] == null) {
                    updateRow[i] = current[i];
                }
            }
            Value[] patch = row.readRow(updateRow);
            patchCurrentRow(patch);
            updateRow = null;
        }
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : Value(org.h2.value.Value) UpdatableRow(org.h2.result.UpdatableRow) DbException(org.h2.message.DbException) SQLException(java.sql.SQLException)

Example 65 with Insert

use of org.h2.command.dml.Insert in project h2database by h2database.

the class JdbcResultSet method updateBinaryStream.

/**
 * Updates a column in the current or insert row.
 *
 * @param columnIndex (1,2,...)
 * @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(int columnIndex, InputStream x, long length) throws SQLException {
    try {
        if (isDebugEnabled()) {
            debugCode("updateBinaryStream(" + columnIndex + ", x, " + length + "L);");
        }
        checkClosed();
        Value v = conn.createBlob(x, length);
        update(columnIndex, v);
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : Value(org.h2.value.Value) DbException(org.h2.message.DbException) SQLException(java.sql.SQLException)

Aggregations

Statement (java.sql.Statement)215 ResultSet (java.sql.ResultSet)205 PreparedStatement (java.sql.PreparedStatement)202 Connection (java.sql.Connection)201 JdbcConnection (org.h2.jdbc.JdbcConnection)99 SimpleResultSet (org.h2.tools.SimpleResultSet)64 SQLException (java.sql.SQLException)56 JdbcStatement (org.h2.jdbc.JdbcStatement)46 JdbcPreparedStatement (org.h2.jdbc.JdbcPreparedStatement)35 Savepoint (java.sql.Savepoint)32 Random (java.util.Random)28 Value (org.h2.value.Value)28 DbException (org.h2.message.DbException)27 Column (org.h2.table.Column)18 Task (org.h2.util.Task)17 ValueString (org.h2.value.ValueString)16 ByteArrayInputStream (java.io.ByteArrayInputStream)14 StringReader (java.io.StringReader)12 ArrayList (java.util.ArrayList)12 InputStream (java.io.InputStream)11