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();
}
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();
}
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);
}
}
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);
}
}
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);
}
}
Aggregations