Search in sources :

Example 11 with ParameterInterface

use of com.wplatform.ddal.command.expression.ParameterInterface in project jdbc-shards by wplatform.

the class JdbcPreparedStatement method setParameter.

// =============================================================
private void setParameter(int parameterIndex, Value value) {
    checkClosed();
    parameterIndex--;
    ArrayList<? extends ParameterInterface> parameters = command.getParameters();
    if (parameterIndex < 0 || parameterIndex >= parameters.size()) {
        throw DbException.getInvalidValueException("parameterIndex", parameterIndex + 1);
    }
    ParameterInterface param = parameters.get(parameterIndex);
    // can only delete old temp files if they are not in the batch
    param.setValue(value, batchParameters == null);
}
Also used : ParameterInterface(com.wplatform.ddal.command.expression.ParameterInterface)

Example 12 with ParameterInterface

use of com.wplatform.ddal.command.expression.ParameterInterface in project jdbc-shards by wplatform.

the class JdbcPreparedStatement method addBatch.

/**
     * Adds the current settings to the batch.
     */
@Override
public void addBatch() throws SQLException {
    try {
        debugCodeCall("addBatch");
        checkClosedForWrite();
        try {
            ArrayList<? extends ParameterInterface> parameters = command.getParameters();
            int size = parameters.size();
            Value[] set = new Value[size];
            for (int i = 0; i < size; i++) {
                ParameterInterface param = parameters.get(i);
                Value value = param.getParamValue();
                set[i] = value;
            }
            if (batchParameters == null) {
                batchParameters = New.arrayList();
            }
            batchParameters.add(set);
        } finally {
            afterWriting();
        }
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : ParameterInterface(com.wplatform.ddal.command.expression.ParameterInterface) DbException(com.wplatform.ddal.message.DbException)

Example 13 with ParameterInterface

use of com.wplatform.ddal.command.expression.ParameterInterface in project jdbc-shards by wplatform.

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.size() == 0) {
        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(com.wplatform.ddal.command.expression.ParameterInterface) StatementBuilder(com.wplatform.ddal.util.StatementBuilder) Value(com.wplatform.ddal.value.Value)

Aggregations

ParameterInterface (com.wplatform.ddal.command.expression.ParameterInterface)13 DbException (com.wplatform.ddal.message.DbException)9 SQLException (java.sql.SQLException)5 BitField (com.wplatform.ddal.util.BitField)1 StatementBuilder (com.wplatform.ddal.util.StatementBuilder)1 Value (com.wplatform.ddal.value.Value)1