Search in sources :

Example 1 with ParameterInterface

use of org.h2.expression.ParameterInterface in project h2database by h2database.

the class CommandRemote method close.

@Override
public void close() {
    if (session == null || session.isClosed()) {
        return;
    }
    synchronized (session) {
        session.traceOperation("COMMAND_CLOSE", id);
        for (Transfer transfer : transferList) {
            try {
                transfer.writeInt(SessionRemote.COMMAND_CLOSE).writeInt(id);
            } catch (IOException e) {
                trace.error(e, "close");
            }
        }
    }
    session = null;
    try {
        for (ParameterInterface p : parameters) {
            Value v = p.getParamValue();
            if (v != null) {
                v.remove();
            }
        }
    } catch (DbException e) {
        trace.error(e, "close");
    }
    parameters.clear();
}
Also used : ParameterInterface(org.h2.expression.ParameterInterface) Transfer(org.h2.value.Transfer) Value(org.h2.value.Value) IOException(java.io.IOException) DbException(org.h2.message.DbException)

Example 2 with ParameterInterface

use of org.h2.expression.ParameterInterface in project h2database by h2database.

the class Trace method formatParams.

/**
 * Format the parameter list.
 *
 * @param parameters the parameter list
 * @return the formatted text
 */
public static String formatParams(ArrayList<? extends ParameterInterface> parameters) {
    if (parameters.isEmpty()) {
        return "";
    }
    StatementBuilder buff = new StatementBuilder();
    int i = 0;
    boolean params = false;
    for (ParameterInterface p : parameters) {
        if (p.isValueSet()) {
            if (!params) {
                buff.append(" {");
                params = true;
            }
            buff.appendExceptFirst(", ");
            Value v = p.getParamValue();
            buff.append(++i).append(": ").append(v.getTraceSQL());
        }
    }
    if (params) {
        buff.append('}');
    }
    return buff.toString();
}
Also used : ParameterInterface(org.h2.expression.ParameterInterface) StatementBuilder(org.h2.util.StatementBuilder) Value(org.h2.value.Value)

Example 3 with ParameterInterface

use of org.h2.expression.ParameterInterface in project h2database by h2database.

the class JdbcPreparedStatement method executeBatch.

/**
 * Executes the batch.
 * If one of the batched statements fails, this database will continue.
 *
 * @return the array of update counts
 */
@Override
public int[] executeBatch() throws SQLException {
    try {
        debugCodeCall("executeBatch");
        if (batchParameters == null) {
            // TODO batch: check what other database do if no parameters are
            // set
            batchParameters = New.arrayList();
        }
        batchIdentities = new MergedResultSet();
        int size = batchParameters.size();
        int[] result = new int[size];
        boolean error = false;
        SQLException next = null;
        checkClosedForWrite();
        try {
            for (int i = 0; i < size; i++) {
                Value[] set = batchParameters.get(i);
                ArrayList<? extends ParameterInterface> parameters = command.getParameters();
                for (int j = 0; j < set.length; j++) {
                    Value value = set[j];
                    ParameterInterface param = parameters.get(j);
                    param.setValue(value, false);
                }
                try {
                    result[i] = executeUpdateInternal();
                    // Cannot use own implementation, it returns batch identities
                    ResultSet rs = super.getGeneratedKeys();
                    batchIdentities.add(rs);
                } catch (Exception re) {
                    SQLException e = logAndConvert(re);
                    if (next == null) {
                        next = e;
                    } else {
                        e.setNextException(next);
                        next = e;
                    }
                    result[i] = Statement.EXECUTE_FAILED;
                    error = true;
                }
            }
            batchParameters = null;
            if (error) {
                throw new JdbcBatchUpdateException(next, result);
            }
            return result;
        } finally {
            afterWriting();
        }
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : ParameterInterface(org.h2.expression.ParameterInterface) MergedResultSet(org.h2.util.MergedResultSet) SQLException(java.sql.SQLException) Value(org.h2.value.Value) ResultSet(java.sql.ResultSet) MergedResultSet(org.h2.util.MergedResultSet) DbException(org.h2.message.DbException) SQLException(java.sql.SQLException)

Example 4 with ParameterInterface

use of org.h2.expression.ParameterInterface in project h2database by h2database.

the class JdbcParameterMetaData method getParameterType.

/**
 * Returns the parameter type.
 * java.sql.Types.VARCHAR is returned if the data type is not known.
 *
 * @param param the column index (1,2,...)
 * @return the data type
 */
@Override
public int getParameterType(int param) throws SQLException {
    try {
        debugCodeCall("getParameterType", param);
        ParameterInterface p = getParameter(param);
        int type = p.getType();
        if (type == Value.UNKNOWN) {
            type = Value.STRING;
        }
        return DataType.getDataType(type).sqlType;
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : ParameterInterface(org.h2.expression.ParameterInterface) SQLException(java.sql.SQLException) DbException(org.h2.message.DbException)

Example 5 with ParameterInterface

use of org.h2.expression.ParameterInterface in project h2database by h2database.

the class JdbcParameterMetaData method getScale.

/**
 * Returns the parameter scale.
 * The value 0 is returned if the scale is not known.
 *
 * @param param the column index (1,2,...)
 * @return the scale
 */
@Override
public int getScale(int param) throws SQLException {
    try {
        debugCodeCall("getScale", param);
        ParameterInterface p = getParameter(param);
        return p.getScale();
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : ParameterInterface(org.h2.expression.ParameterInterface) SQLException(java.sql.SQLException) DbException(org.h2.message.DbException)

Aggregations

ParameterInterface (org.h2.expression.ParameterInterface)15 DbException (org.h2.message.DbException)10 SQLException (java.sql.SQLException)9 Value (org.h2.value.Value)6 IOException (java.io.IOException)1 ResultSet (java.sql.ResultSet)1 BitSet (java.util.BitSet)1 Parameter (org.h2.expression.Parameter)1 MergedResultSet (org.h2.util.MergedResultSet)1 StatementBuilder (org.h2.util.StatementBuilder)1 Transfer (org.h2.value.Transfer)1