private void parseSQLDTA_work(DRDAStatement stmt) throws DRDAProtocolException,SQLException
{
String strVal;
PreparedStatement ps = stmt.getPreparedStatement();
int codePoint;
ParameterMetaData pmeta = null;
// Clear params without releasing storage
stmt.clearDrdaParams();
int numVars = 0;
boolean rtnParam = false;
reader.markCollection();
codePoint = reader.getCodePoint();
while (codePoint != -1)
{
switch (codePoint)
{
// required
case CodePoint.FDODSC:
while (reader.getDdmLength() > 6) //we get parameter info til last 6 byte
{
int dtaGrpLen = reader.readUnsignedByte();
int numVarsInGrp = (dtaGrpLen - 3) / 3;
if (SanityManager.DEBUG)
trace("num of vars in this group is: "+numVarsInGrp);
reader.readByte(); // tripletType
reader.readByte(); // id
for (int j = 0; j < numVarsInGrp; j++)
{
final byte t = reader.readByte();
if (SanityManager.DEBUG)
trace("drdaType is: "+ "0x" +
Integer.toHexString(t));
int drdaLength = reader.readNetworkShort();
if (SanityManager.DEBUG)
trace("drdaLength is: "+drdaLength);
stmt.addDrdaParam(t, drdaLength);
}
}
numVars = stmt.getDrdaParamCount();
if (SanityManager.DEBUG)
trace("numVars = " + numVars);
if (ps == null) // it is a CallableStatement under construction
{
String marks = "(?"; // construct parameter marks
for (int i = 1; i < numVars; i++)
marks += ", ?";
String prepareString = "call " + stmt.procName + marks + ")";
if (SanityManager.DEBUG)
trace ("$$ prepareCall is: "+prepareString);
CallableStatement cs = null;
try {
cs = (CallableStatement)
stmt.prepare(prepareString);
stmt.registerAllOutParams();
} catch (SQLException se) {
if (! stmt.outputExpected ||
(!se.getSQLState().equals(SQLState.LANG_NO_METHOD_FOUND)))
throw se;
if (SanityManager.DEBUG)
trace("****** second try with return parameter...");
// Save first SQLException most likely suspect
if (numVars == 1)
prepareString = "? = call " + stmt.procName +"()";
else
prepareString = "? = call " + stmt.procName +"("+marks.substring(3) + ")";
if (SanityManager.DEBUG)
trace ("$$ prepareCall is: "+prepareString);
try {
cs = (CallableStatement) stmt.prepare(prepareString);
} catch (SQLException se2)
{
// The first exception is the most likely suspect
throw se;
}
rtnParam = true;
}
ps = cs;
stmt.ps = ps;
}
pmeta = stmt.getParameterMetaData();
reader.readBytes(6); // descriptor footer
break;
// optional
case CodePoint.FDODTA:
reader.readByte(); // row indicator
for (int i = 0; i < numVars; i++)
{
if ((stmt.getParamDRDAType(i+1) & 0x1) == 0x1) // nullable
{
int nullData = reader.readUnsignedByte();
if ((nullData & 0xFF) == FdocaConstants.NULL_DATA)
{
if (SanityManager.DEBUG)
trace("******param null");
if (pmeta.getParameterMode(i + 1)
!= JDBC30Translation.PARAMETER_MODE_OUT )
ps.setNull(i+1, pmeta.getParameterType(i+1));
if (stmt.isOutputParam(i+1))
stmt.registerOutParam(i+1);
continue;
}
}