sql = c.nativeSQL(sql);
resultOut.setResultType(ResultConstants.SQLPREPARE);
resultOut.setMainString(sql);
Result in = connection.sessionProxy.execute(resultOut);
if (in.isError()) {
Util.throwError(in);
}
// else it's a MULTI result encapsulating three sub results:
// 1.) a PREPARE_ACK
//
// Indicates the statement id to be communicated in SQLEXECUTE
// requests to allow the engine to find the corresponding
// CompiledStatement object, parameterize and execute it.
//
// 2.) a description of the statement's result set metadata
//
// This is communicated in the same way as for result sets. That is,
// the metadata arrays of Result, such as colTypes, are used in the
// "conventional" fashion. With some work, it may be possible
// to speed up internal execution of prepared statements by
// dispensing with generating most rsmd values while generating
// the result, safe in the knowlege that the client already
// has a copy of the rsmd. In general, only the colTypes array
// must be available at the engine, and only for network
// communications so that the row output and row input
// interfaces can do their work. One caveat is that the
// columnDisplaySize values are not accurate, as we do
// not consistently enforce column size yet and instead
// approximate the value when a result with actual data is
// retrieved
//
// 3.) a description of the statement's parameter metadata
//
// This is communicated in a similar fashion to 2.), but has
// a slighly different layout to allow the parameter modes
// to be transmitted. The values of this object are used
// to set up the parameter management of this class. The
// object is also used to construct the jdbcParameterMetaData
// object later, if requested. That is, it holds information
// additional to that used by this class, so it should not be
// altered or disposed of
//
// (boucherb@users)
Iterator i;
i = in.iterator();
try {
Object[] row;
// PREPARE_ACK
row = (Object[]) i.next();
statementID = ((Result) row[0]).getStatementID();
// DATA - isParameterDescription == false
row = (Object[]) i.next();
rsmdDescriptor = (Result) row[0];
isRowCount = rsmdDescriptor.mode == ResultConstants.UPDATECOUNT;
// DATA - isParameterDescription == true
row = (Object[]) i.next();
pmdDescriptor = (Result) row[0];
parameterTypes = pmdDescriptor.metaData.getParameterTypes();
parameterValues = new Object[parameterTypes.length];
parameterSet = new boolean[parameterTypes.length];
parameterModes = pmdDescriptor.metaData.paramMode;
} catch (Exception e) {
throw Trace.error(Trace.GENERAL_ERROR, e.toString());
}
resultOut = new Result(ResultConstants.SQLEXECUTE, parameterTypes,
statementID);
// for toString()
this.sql = sql;
}