0001: /*
0002:
0003: Derby - Class org.apache.derby.client.net.NetStatementReply
0004:
0005: Licensed to the Apache Software Foundation (ASF) under one or more
0006: contributor license agreements. See the NOTICE file distributed with
0007: this work for additional information regarding copyright ownership.
0008: The ASF licenses this file to You under the Apache License, Version 2.0
0009: (the "License"); you may not use this file except in compliance with
0010: the License. You may obtain a copy of the License at
0011:
0012: http://www.apache.org/licenses/LICENSE-2.0
0013:
0014: Unless required by applicable law or agreed to in writing, software
0015: distributed under the License is distributed on an "AS IS" BASIS,
0016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0017: See the License for the specific language governing permissions and
0018: limitations under the License.
0019:
0020: */
0021:
0022: package org.apache.derby.client.net;
0023:
0024: import org.apache.derby.client.am.ColumnMetaData;
0025: import org.apache.derby.client.am.DisconnectException;
0026: import org.apache.derby.client.am.PreparedStatementCallbackInterface;
0027: import org.apache.derby.client.am.ResultSetCallbackInterface;
0028: import org.apache.derby.client.am.Section;
0029: import org.apache.derby.client.am.SqlState;
0030: import org.apache.derby.client.am.SqlException;
0031: import org.apache.derby.client.am.Statement;
0032: import org.apache.derby.client.am.StatementCallbackInterface;
0033: import org.apache.derby.client.am.Types;
0034: import org.apache.derby.client.am.Utils;
0035: import org.apache.derby.jdbc.ClientDriver;
0036: import org.apache.derby.client.am.ClientJDBCObjectFactory;
0037: import org.apache.derby.shared.common.i18n.MessageUtil;
0038: import org.apache.derby.shared.common.reference.JDBC30Translation;
0039: import org.apache.derby.client.am.ClientMessageId;
0040: import org.apache.derby.shared.common.reference.SQLState;
0041: import org.apache.derby.shared.common.reference.MessageId;
0042:
0043: public class NetStatementReply extends NetPackageReply implements
0044: StatementReplyInterface {
0045: NetStatementReply(NetAgent netAgent, int bufferSize) {
0046: super (netAgent, bufferSize);
0047: }
0048:
0049: //----------------------------- entry points ---------------------------------
0050:
0051: public void readPrepareDescribeOutput(
0052: StatementCallbackInterface statement)
0053: throws DisconnectException {
0054: startSameIdChainParse();
0055: parsePRPSQLSTTreply(statement);
0056: endOfSameIdChainData();
0057: }
0058:
0059: public void readExecuteImmediate(
0060: StatementCallbackInterface statement)
0061: throws DisconnectException {
0062: startSameIdChainParse();
0063: parseEXCSQLIMMreply(statement);
0064: endOfSameIdChainData();
0065: }
0066:
0067: public void readOpenQuery(StatementCallbackInterface statement)
0068: throws DisconnectException {
0069: startSameIdChainParse();
0070: parseOPNQRYreply(statement);
0071: endOfSameIdChainData();
0072: }
0073:
0074: public void readExecute(
0075: PreparedStatementCallbackInterface preparedStatement)
0076: throws DisconnectException {
0077: startSameIdChainParse();
0078: parseEXCSQLSTTreply(preparedStatement);
0079: endOfSameIdChainData();
0080: }
0081:
0082: public void readPrepare(StatementCallbackInterface statement)
0083: throws DisconnectException {
0084: startSameIdChainParse();
0085: parsePRPSQLSTTreply(statement);
0086: endOfSameIdChainData();
0087: }
0088:
0089: public void readDescribeInput(
0090: PreparedStatementCallbackInterface preparedStatement)
0091: throws DisconnectException {
0092: if (longBufferForDecryption_ != null) {
0093: buffer_ = longBufferForDecryption_;
0094: pos_ = longPosForDecryption_;
0095: count_ = longCountForDecryption_;
0096: if (longBufferForDecryption_ != null
0097: && count_ > longBufferForDecryption_.length) {
0098: count_ = longBufferForDecryption_.length;
0099: }
0100: dssLength_ = 0;
0101: longBufferForDecryption_ = null;
0102: }
0103:
0104: startSameIdChainParse();
0105: parseDSCSQLSTTreply(preparedStatement, 1); // anything other than 0 for input
0106: endOfSameIdChainData();
0107: }
0108:
0109: public void readDescribeOutput(
0110: PreparedStatementCallbackInterface preparedStatement)
0111: throws DisconnectException {
0112: startSameIdChainParse();
0113: parseDSCSQLSTTreply(preparedStatement, 0); // 0 for output
0114: endOfSameIdChainData();
0115: }
0116:
0117: public void readExecuteCall(StatementCallbackInterface statement)
0118: throws DisconnectException {
0119: startSameIdChainParse();
0120: parseEXCSQLSTTreply(statement);
0121: endOfSameIdChainData();
0122: }
0123:
0124: //----------------------helper methods----------------------------------------
0125:
0126: //------------------parse reply for specific command--------------------------
0127:
0128: // These methods are "private protected", which is not a recognized java privilege,
0129: // but means that these methods are private to this class and to subclasses,
0130: // and should not be used as package-wide friendly methods.
0131:
0132: private void parsePRPSQLSTTreply(
0133: StatementCallbackInterface statement)
0134: throws DisconnectException {
0135: int peekCP = parseTypdefsOrMgrlvlovrs();
0136:
0137: if (peekCP == CodePoint.SQLDARD) {
0138: // the sqlcagrp is most likely null for insert/update/deletes. if it is null, then we can
0139: // peek ahead for the column number which most likely will be 0. if it is 0, then we will
0140: // not new up a ColumnMetaData, and we can skip the rest of the bytes in sqldard.
0141: // if sqlcargrp is not null, (most likely for select's) then we will not peek ahead for the
0142: // column number since it will never be 0 in a select case.
0143: ColumnMetaData columnMetaData = null;
0144: NetSqlca netSqlca = null;
0145: boolean nullSqlca = peekForNullSqlcagrp();
0146: if (nullSqlca && peekNumOfColumns() == 0) {
0147: netSqlca = parseSQLDARD(columnMetaData, true); // true means to skip the rest of SQLDARD bytes
0148: } else {
0149: columnMetaData = ClientDriver.getFactory()
0150: .newColumnMetaData(netAgent_.logWriter_);
0151: netSqlca = parseSQLDARD(columnMetaData, false); // false means do not skip SQLDARD bytes.
0152: }
0153:
0154: statement.completePrepareDescribeOutput(columnMetaData,
0155: netSqlca);
0156: } else if (peekCP == CodePoint.SQLCARD) {
0157: NetSqlca netSqlca = parseSQLCARD(null);
0158: statement.completePrepare(netSqlca);
0159: } else {
0160: parsePrepareError(statement);
0161: }
0162:
0163: }
0164:
0165: // Parse the reply for the Describe SQL Statement Command.
0166: // This method handles the parsing of all command replies and reply data
0167: // for the dscsqlstt command.
0168: private void parseDSCSQLSTTreply(
0169: PreparedStatementCallbackInterface ps, int metaDataType) // 0 is output, else input
0170: throws DisconnectException {
0171: int peekCP = parseTypdefsOrMgrlvlovrs();
0172:
0173: if (peekCP == CodePoint.SQLDARD) {
0174: ColumnMetaData columnMetaData = null;
0175:
0176: if (columnMetaData == null) {
0177: columnMetaData = ClientDriver.getFactory()
0178: .newColumnMetaData(netAgent_.logWriter_);
0179: }
0180:
0181: NetSqlca netSqlca = parseSQLDARD(columnMetaData, false); // false means do not skip SQLDARD bytes
0182: if (columnMetaData.columns_ == 0) {
0183: columnMetaData = null;
0184: }
0185:
0186: if (metaDataType == 0) // DESCRIBE OUTPUT
0187: {
0188: ps.completeDescribeOutput(columnMetaData, netSqlca);
0189: } else {
0190: ps.completeDescribeInput(columnMetaData, netSqlca);
0191: }
0192: } else if (peekCP == CodePoint.SQLCARD) {
0193: NetSqlca netSqlca = parseSQLCARD(null);
0194: if (metaDataType == 0) // DESCRIBE OUTPUT
0195: {
0196: ps.completeDescribeOutput(null, netSqlca);
0197: } else {
0198: ps.completeDescribeInput(null, netSqlca);
0199: }
0200: } else {
0201: parseDescribeError(ps);
0202: }
0203:
0204: }
0205:
0206: // Parse the reply for the Execute Immediate SQL Statement Command.
0207: // This method handles the parsing of all command replies and reply data
0208: // for the excsqlimm command.
0209: private void parseEXCSQLIMMreply(
0210: StatementCallbackInterface statement)
0211: throws DisconnectException {
0212: int peekCP = parseTypdefsOrMgrlvlovrs();
0213:
0214: if (peekCP == CodePoint.RDBUPDRM) {
0215: parseRDBUPDRM();
0216: peekCP = parseTypdefsOrMgrlvlovrs();
0217: }
0218:
0219: switch (peekCP) {
0220: case CodePoint.ENDUOWRM:
0221: parseENDUOWRM(statement.getConnectionCallbackInterface());
0222: parseTypdefsOrMgrlvlovrs();
0223: case CodePoint.SQLCARD:
0224: NetSqlca netSqlca = parseSQLCARD(null);
0225:
0226: statement.completeExecuteImmediate(netSqlca);
0227: break;
0228: default:
0229: parseExecuteImmediateError(statement);
0230: break;
0231: }
0232:
0233: }
0234:
0235: // Parse the reply for the Open Query Command.
0236: // This method handles the parsing of all command replies and reply data for the opnqry command.
0237: // will be replaced by parseOPNQRYreply (see parseOPNQRYreplyProto)
0238: private void parseOPNQRYreply(StatementCallbackInterface statementI)
0239: throws DisconnectException {
0240: int peekCP = peekCodePoint();
0241:
0242: if (peekCP == CodePoint.OPNQRYRM) {
0243: parseOpenQuery(statementI);
0244: peekCP = peekCodePoint();
0245: if (peekCP == CodePoint.RDBUPDRM) {
0246: parseRDBUPDRM();
0247: peekCP = peekCodePoint();
0248: }
0249: } else if (peekCP == CodePoint.RDBUPDRM) {
0250: parseRDBUPDRM();
0251: parseOpenQuery(statementI);
0252: peekCP = peekCodePoint();
0253: } else if (peekCP == CodePoint.OPNQFLRM) {
0254: parseOpenQueryFailure(statementI);
0255: peekCP = peekCodePoint();
0256: } else {
0257: parseOpenQueryError(statementI);
0258: peekCP = peekCodePoint();
0259: }
0260:
0261: }
0262:
0263: // Called by NETSetClientPiggybackCommand.read()
0264: private void parseEXCSQLSETreply(
0265: StatementCallbackInterface statement)
0266: throws DisconnectException {
0267: int peekCP = parseTypdefsOrMgrlvlovrs();
0268:
0269: if (peekCP == CodePoint.RDBUPDRM) {
0270: parseRDBUPDRM();
0271: parseTypdefsOrMgrlvlovrs();
0272: } else if (peekCP == CodePoint.ENDUOWRM) {
0273: parseENDUOWRM(statement.getConnectionCallbackInterface());
0274: parseTypdefsOrMgrlvlovrs();
0275: }
0276:
0277: if (peekCP == CodePoint.SQLCARD) {
0278: NetSqlca netSqlca = parseSQLCARD(null);
0279: statement.completeExecuteSetStatement(netSqlca);
0280: } else {
0281: parseExecuteSetStatementError(statement);
0282: }
0283:
0284: }
0285:
0286: // Parse the reply for the Execute SQL Statement Command.
0287: // This method handles the parsing of all command replies and reply data
0288: // for the excsqlstt command.
0289: // Also called by CallableStatement.readExecuteCall()
0290: private void parseEXCSQLSTTreply(
0291: StatementCallbackInterface statementI)
0292: throws DisconnectException {
0293: // first handle the transaction component, which consists of one or more
0294: // reply messages indicating the transaction state.
0295: // These are ENDUOWRM, CMMRQSRM, or RDBUPDRM. If RDBUPDRM is returned,
0296: // it may be followed by ENDUOWRM or CMMRQSRM
0297: int peekCP = peekCodePoint();
0298: if (peekCP == CodePoint.RDBUPDRM) {
0299: parseRDBUPDRM();
0300: peekCP = peekCodePoint();
0301: }
0302:
0303: if (peekCP == CodePoint.ENDUOWRM) {
0304: parseENDUOWRM(statementI.getConnectionCallbackInterface());
0305: peekCP = peekCodePoint();
0306: }
0307:
0308: // Check for a RSLSETRM, this is first rm of the result set summary component
0309: // which would be returned if a stored procedure was called which returned result sets.
0310: if (peekCP == CodePoint.RSLSETRM) {
0311: parseResultSetProcedure(statementI);
0312: peekCP = peekCodePoint();
0313: if (peekCP == CodePoint.RDBUPDRM) {
0314: parseRDBUPDRM();
0315: }
0316: return;
0317: }
0318:
0319: // check for a possible TYPDEFNAM or TYPDEFOVR which may be present
0320: // before the SQLCARD or SQLDTARD.
0321: peekCP = parseTypdefsOrMgrlvlovrs();
0322:
0323: // an SQLCARD may be retunred if there was no output data, result sets or parameters,
0324: // or in the case of an error.
0325: if (peekCP == CodePoint.SQLCARD) {
0326: NetSqlca netSqlca = parseSQLCARD(null);
0327:
0328: statementI.completeExecute(netSqlca);
0329: } else if (peekCP == CodePoint.SQLDTARD) {
0330: // in the case of singleton select or if a stored procedure was called which had
0331: // parameters but no result sets, an SQLSTARD may be returned
0332: // keep the PreparedStatementCallbackInterface, since only preparedstatement and callablestatement
0333: // has parameters or singleton select which translates to sqldtard.
0334: NetSqldta netSqldta = null;
0335: boolean useCachedSingletonRowData = false;
0336: if (((Statement) statementI).cachedSingletonRowData_ == null) {
0337: netSqldta = new NetSqldta(netAgent_);
0338: } else {
0339: netSqldta = (NetSqldta) ((Statement) statementI).cachedSingletonRowData_;
0340: netSqldta.resetDataBuffer();
0341: netSqldta.extdtaData_.clear();
0342: useCachedSingletonRowData = true;
0343: }
0344: NetSqlca netSqlca = parseSQLDTARD(netSqldta);
0345:
0346: // there may be externalized LOB data which also gets returned.
0347: peekCP = peekCodePoint();
0348: while (peekCP == CodePoint.EXTDTA) {
0349: copyEXTDTA(netSqldta);
0350: peekCP = peekCodePoint();
0351: }
0352: statementI.completeExecuteCall(netSqlca, netSqldta);
0353: } else {
0354: // if here, then assume an error reply message was returned.
0355: parseExecuteError(statementI);
0356: }
0357:
0358: }
0359:
0360: protected void parseResultSetProcedure(
0361: StatementCallbackInterface statementI)
0362: throws DisconnectException {
0363: // when a stored procedure is called which returns result sets,
0364: // the next thing to be returned after the optional transaction component
0365: // is the summary component.
0366: //
0367: // Parse the Result Set Summary Component which consists of a
0368: // Result Set Reply Message, SQLCARD or SQLDTARD, and an SQL Result Set
0369: // Reply data object. Also check for possible TYPDEF overrides before the
0370: // OBJDSSs.
0371: // This method returns an ArrayList of generated sections which contain the
0372: // package and section information for the result sets which were opened on the
0373: // server.
0374:
0375: // the result set summary component consists of a result set reply message.
0376: java.util.ArrayList sectionAL = parseRSLSETRM();
0377:
0378: // following the RSLSETRM is an SQLCARD or an SQLDTARD. check for a
0379: // TYPDEFNAM or TYPDEFOVR before looking for these objects.
0380: int peekCP = parseTypdefsOrMgrlvlovrs();
0381:
0382: // The SQLCARD and the SQLDTARD are mutually exclusive.
0383: // The SQLDTARD is returned if the stored procedure had parameters.
0384: // (Note: the SQLDTARD contains an sqlca also. this is the sqlca for the
0385: // stored procedure call.
0386: NetSqldta netSqldta = null;
0387: NetSqlca netSqlca = null;
0388: if (peekCP == CodePoint.SQLCARD) {
0389: netSqlca = parseSQLCARD(null);
0390: } else {
0391: // keep the PreparedStatementCallbackInterface, since only preparedstatement and callablestatement
0392: // has parameters or singleton select which translates to sqldtard.
0393: netSqldta = new NetSqldta(netAgent_);
0394: netSqlca = parseSQLDTARD(netSqldta);
0395: }
0396:
0397: // check for a possible TYPDEFNAM or TYPDEFOVR
0398: // before the SQL Result Set Reply Data object
0399: peekCP = parseTypdefsOrMgrlvlovrs();
0400:
0401: int numberOfResultSets = parseSQLRSLRD(sectionAL);
0402:
0403: // The result set summary component parsed above indicated how many result sets were opened
0404: // by the stored pocedure call. It contained section information for
0405: // each of these result sets. Loop through the section array and
0406: // parse the result set component for each of the retunred result sets.
0407: NetResultSet[] resultSets = new NetResultSet[numberOfResultSets];
0408: for (int i = 0; i < numberOfResultSets; i++) {
0409: // parse the result set component of the stored procedure reply.
0410: NetResultSet netResultSet = parseResultSetCursor(
0411: statementI, (Section) sectionAL.get(i));
0412: resultSets[i] = netResultSet;
0413: }
0414:
0415: // LOBs may have been returned for one of the stored procedure parameters so
0416: // check for any externalized data.
0417: peekCP = peekCodePoint();
0418: while (peekCP == CodePoint.EXTDTA) {
0419: copyEXTDTA(netSqldta);
0420: peekCP = peekCodePoint();
0421: }
0422: statementI.completeExecuteCall(netSqlca, netSqldta, resultSets);
0423: }
0424:
0425: // Parse the Result Set component of the reply for a stored procedure
0426: // call which returns result sets.
0427: // The Result Set component consists of an Open Query Reply Message
0428: // followed by an optional SQLCARD, followed by an optional
0429: // SQL Column Information Reply data object, followed by a Query Descriptor.
0430: // There may also be Query Data or an End of Query Reply Message.
0431: protected NetResultSet parseResultSetCursor(
0432: StatementCallbackInterface statementI, Section section)
0433: throws DisconnectException {
0434: // The first item returne is an OPNQRYRM.
0435: NetResultSet netResultSet = parseOPNQRYRM(statementI, false);
0436:
0437: // The next to be returned is an OBJDSS so check for any TYPDEF overrides.
0438: int peekCP = parseTypdefsOrMgrlvlovrs();
0439:
0440: // An SQLCARD may be returned if there were any warnings on the OPEN.
0441: NetSqlca netSqlca = null;
0442: if (peekCP == CodePoint.SQLCARD) {
0443: netSqlca = parseSQLCARD(null);
0444: peekCP = parseTypdefsOrMgrlvlovrs();
0445: }
0446:
0447: // the SQLCINRD contains SQLDA like information for the result set.
0448: ColumnMetaData resultSetMetaData = null;
0449: if (peekCP == CodePoint.SQLCINRD) {
0450: resultSetMetaData = parseSQLCINRD();
0451: peekCP = parseTypdefsOrMgrlvlovrs();
0452: }
0453:
0454: // A Query Descriptor must be present.
0455: // We cannot cache the cursor if result set is returned from a stored procedure, so
0456: // there is no cached cursor to use here.
0457: parseQRYDSC(netResultSet.netCursor_);
0458: peekCP = peekCodePoint();
0459: statementI.completeExecuteCallOpenQuery(netSqlca, netResultSet,
0460: resultSetMetaData, section);
0461:
0462: // Depending on the blocking rules, QRYDTA may have been returned on the open.
0463: while (peekCP == CodePoint.QRYDTA) {
0464: parseQRYDTA(netResultSet);
0465: peekCP = peekCodePoint();
0466: }
0467:
0468: // Under some circumstances, the server may have closed the cursor.
0469: // This will be indicated by an ENDQRYRM.
0470: if (peekCP == CodePoint.ENDQRYRM) {
0471: parseEndQuery((ResultSetCallbackInterface) netResultSet);
0472: }
0473:
0474: return netResultSet;
0475: }
0476:
0477: protected void parseOpenQuery(StatementCallbackInterface statementI)
0478: throws DisconnectException {
0479: NetResultSet netResultSet = parseOPNQRYRM(statementI, true);
0480:
0481: NetSqlca sqlca = null;
0482: int peekCP = peekCodePoint();
0483: if (peekCP != CodePoint.QRYDSC) {
0484:
0485: peekCP = parseTypdefsOrMgrlvlovrs();
0486:
0487: if (peekCP == CodePoint.SQLDARD) {
0488: ColumnMetaData columnMetaData = ClientDriver
0489: .getFactory().newColumnMetaData(
0490: netAgent_.logWriter_);
0491: NetSqlca netSqlca = parseSQLDARD(columnMetaData, false); // false means do not skip SQLDARD bytes
0492:
0493: //For java stored procedure, we got the resultSetMetaData from server,
0494: //Do we need to save the resultSetMetaData and propagate netSqlca?
0495: //The following statement are doing the both, but it do more than
0496: //we want. It also mark the completion of Prepare statement.
0497: //
0498: // this will override the same call made from parsePrepareDescribe
0499: // this will not work, this is not the DA for the stored proc params
0500: statementI.completePrepareDescribeOutput(
0501: columnMetaData, netSqlca);
0502: peekCP = parseTypdefsOrMgrlvlovrs();
0503: }
0504: // check if the DARD is mutually exclusive with CARD, if so, then the following if should be an elese
0505:
0506: if (peekCP == CodePoint.SQLCARD) {
0507: sqlca = parseSQLCARD(null);
0508: peekCP = parseTypdefsOrMgrlvlovrs();
0509: }
0510: }
0511: parseQRYDSC(netResultSet.netCursor_);
0512:
0513: peekCP = peekCodePoint();
0514: while (peekCP == CodePoint.QRYDTA) {
0515: parseQRYDTA(netResultSet);
0516: peekCP = peekCodePoint();
0517: }
0518:
0519: if (peekCP == CodePoint.SQLCARD) {
0520: NetSqlca netSqlca = parseSQLCARD(null);
0521: statementI.completeSqlca(netSqlca);
0522: peekCP = peekCodePoint();
0523: }
0524:
0525: if (peekCP == CodePoint.ENDQRYRM) {
0526: parseEndQuery(netResultSet);
0527: }
0528:
0529: statementI.completeOpenQuery(sqlca, netResultSet);
0530: }
0531:
0532: protected void parseEndQuery(ResultSetCallbackInterface resultSetI)
0533: throws DisconnectException {
0534: parseENDQRYRM(resultSetI);
0535: parseTypdefsOrMgrlvlovrs();
0536: NetSqlca netSqlca = parseSQLCARD(null);
0537: resultSetI.earlyCloseComplete(netSqlca);
0538: }
0539:
0540: void parseOpenQueryFailure(StatementCallbackInterface statementI)
0541: throws DisconnectException {
0542: parseOPNQFLRM(statementI);
0543: parseTypdefsOrMgrlvlovrs();
0544: NetSqlca netSqlca = parseSQLCARD(null);
0545: statementI.completeOpenQuery(netSqlca, null);
0546: }
0547:
0548: void parsePrepareError(StatementCallbackInterface statement)
0549: throws DisconnectException {
0550: int peekCP = peekCodePoint();
0551: switch (peekCP) {
0552: case CodePoint.ABNUOWRM: {
0553: //passing the StatementCallbackInterface implementation will
0554: //help in retrieving the the UnitOfWorkListener that needs to
0555: //be rolled back
0556: NetSqlca sqlca = parseAbnormalEndUow(statement);
0557: statement.completeSqlca(sqlca);
0558: break;
0559: }
0560: case CodePoint.CMDCHKRM:
0561: parseCMDCHKRM();
0562: break;
0563: case CodePoint.DTAMCHRM:
0564: parseDTAMCHRM();
0565: break;
0566: case CodePoint.OBJNSPRM:
0567: parseOBJNSPRM();
0568: break;
0569: case CodePoint.RDBNACRM:
0570: parseRDBNACRM();
0571: break;
0572: case CodePoint.SQLERRRM: {
0573: NetSqlca sqlca = parseSqlErrorCondition();
0574: statement.completeSqlca(sqlca);
0575: break;
0576: }
0577: default:
0578: parseCommonError(peekCP);
0579: }
0580: }
0581:
0582: void parseExecuteImmediateError(StatementCallbackInterface statement)
0583: throws DisconnectException {
0584: int peekCP = peekCodePoint();
0585: switch (peekCP) {
0586: case CodePoint.ABNUOWRM: {
0587: //passing the StatementCallbackInterface implementation will
0588: //help in retrieving the the UnitOfWorkListener that needs to
0589: //be rolled back
0590: NetSqlca sqlca = parseAbnormalEndUow(statement);
0591: statement.completeSqlca(sqlca);
0592: break;
0593: }
0594: case CodePoint.CMDCHKRM:
0595: parseCMDCHKRM();
0596: break;
0597: case CodePoint.DTAMCHRM:
0598: parseDTAMCHRM();
0599: break;
0600: case CodePoint.OBJNSPRM:
0601: parseOBJNSPRM();
0602: break;
0603: case CodePoint.RDBNACRM:
0604: parseRDBNACRM();
0605: break;
0606: case CodePoint.SQLERRRM: {
0607: NetSqlca sqlca = parseSqlErrorCondition();
0608: statement.completeSqlca(sqlca);
0609: break;
0610: }
0611: default:
0612: parseCommonError(peekCP);
0613: break;
0614: }
0615: }
0616:
0617: void parseDescribeError(StatementCallbackInterface statement)
0618: throws DisconnectException {
0619: int peekCP = peekCodePoint();
0620: switch (peekCP) {
0621: case CodePoint.ABNUOWRM: {
0622: //passing the StatementCallbackInterface implementation will
0623: //help in retrieving the the UnitOfWorkListener that needs to
0624: //be rolled back
0625: NetSqlca sqlca = parseAbnormalEndUow(statement);
0626: statement.completeSqlca(sqlca);
0627: break;
0628: }
0629: case CodePoint.CMDCHKRM:
0630: parseCMDCHKRM();
0631: break;
0632: case CodePoint.RDBNACRM:
0633: parseRDBNACRM();
0634: break;
0635: case CodePoint.SQLERRRM: {
0636: NetSqlca sqlca = parseSqlErrorCondition();
0637: statement.completeSqlca(sqlca);
0638: break;
0639: }
0640: default:
0641: parseCommonError(peekCP);
0642: }
0643: }
0644:
0645: void parseOpenQueryError(StatementCallbackInterface statementI)
0646: throws DisconnectException {
0647: int peekCP = peekCodePoint();
0648: switch (peekCP) {
0649: case CodePoint.ABNUOWRM: {
0650: //passing the StatementCallbackInterface implementation will
0651: //help in retrieving the the UnitOfWorkListener that needs to
0652: //be rolled back
0653: NetSqlca sqlca = parseAbnormalEndUow(statementI);
0654: statementI.completeSqlca(sqlca);
0655: break;
0656: }
0657: case CodePoint.CMDCHKRM:
0658: parseCMDCHKRM();
0659: break;
0660: case CodePoint.DTAMCHRM:
0661: parseDTAMCHRM();
0662: break;
0663: case CodePoint.OBJNSPRM:
0664: parseOBJNSPRM();
0665: break;
0666: case CodePoint.QRYPOPRM:
0667: parseQRYPOPRM();
0668: break;
0669: case CodePoint.RDBNACRM:
0670: parseRDBNACRM();
0671: break;
0672: default:
0673: parseCommonError(peekCP);
0674: }
0675: }
0676:
0677: void parseExecuteError(StatementCallbackInterface statementI)
0678: throws DisconnectException {
0679: int peekCP = peekCodePoint();
0680: switch (peekCP) {
0681: case CodePoint.ABNUOWRM: {
0682: //passing the StatementCallbackInterface implementation will
0683: //help in retrieving the the UnitOfWorkListener that needs to
0684: //be rolled back
0685: NetSqlca sqlca = parseAbnormalEndUow(statementI);
0686: statementI.completeSqlca(sqlca);
0687: break;
0688: }
0689: case CodePoint.CMDCHKRM:
0690: parseCMDCHKRM();
0691: break;
0692: case CodePoint.DTAMCHRM:
0693: parseDTAMCHRM();
0694: break;
0695: case CodePoint.OBJNSPRM:
0696: parseOBJNSPRM();
0697: break;
0698: case CodePoint.RDBNACRM:
0699: parseRDBNACRM();
0700: break;
0701: case CodePoint.SQLERRRM: {
0702: NetSqlca sqlca = parseSqlErrorCondition();
0703: statementI.completeSqlca(sqlca);
0704: break;
0705: }
0706: default:
0707: parseCommonError(peekCP);
0708: break;
0709: }
0710: }
0711:
0712: void parseExecuteSetStatementError(
0713: StatementCallbackInterface statement)
0714: throws DisconnectException {
0715: int peekCP = peekCodePoint();
0716: switch (peekCP) {
0717: case CodePoint.ABNUOWRM: {
0718: //passing the StatementCallbackInterface implementation will
0719: //help in retrieving the the UnitOfWorkListener that needs to
0720: //be rolled back
0721: NetSqlca sqlca = parseAbnormalEndUow(statement);
0722: statement.completeSqlca(sqlca);
0723: break;
0724: }
0725: case CodePoint.CMDCHKRM:
0726: parseCMDCHKRM();
0727: break;
0728: case CodePoint.DTAMCHRM:
0729: parseDTAMCHRM();
0730: break;
0731: case CodePoint.OBJNSPRM:
0732: parseOBJNSPRM();
0733: break;
0734: case CodePoint.RDBNACRM:
0735: parseRDBNACRM();
0736: break;
0737: case CodePoint.SQLERRRM: {
0738: NetSqlca sqlca = parseSqlErrorCondition();
0739: statement.completeSqlca(sqlca);
0740: break;
0741: }
0742: default:
0743: parseCommonError(peekCP);
0744: break;
0745: }
0746: }
0747:
0748: //-----------------------------parse DDM Reply Messages-----------------------
0749:
0750: /**
0751: * Open Query Complete Reply Message indicates to the requester
0752: * that an OPNQRY or EXCSQLSTT command completed normally and that
0753: * the query process has been initiated. It also indicates the
0754: * type of query protocol and cursor used for the query.
0755: * <p>
0756: * When an EXCSQLSTT contains an SQL statement that invokes a
0757: * stored procedure, and the procedure completes, an OPNQRYRM is
0758: * returned for each answer set.
0759: *
0760: * @param statementI statement callback interface
0761: * @param isOPNQRYreply If true, parse a reply to an OPNQRY
0762: * command. Otherwise, parse a reply to an EXCSQLSTT command.
0763: * @return a <code>NetResultSet</code> value
0764: * @exception DisconnectException
0765: */
0766: protected NetResultSet parseOPNQRYRM(
0767: StatementCallbackInterface statementI, boolean isOPNQRYreply)
0768: throws DisconnectException {
0769: // these need to be initialized to the correct default values.
0770: int svrcod = CodePoint.SVRCOD_INFO;
0771: boolean svrcodReceived = false;
0772: int qryprctyp = 0;
0773: boolean qryprctypReceived = false;
0774: int sqlcsrhld = 0xF0; // 0xF0 is false (default), 0xF1 is true.
0775: boolean sqlcsrhldReceived = false;
0776: int qryattscr = 0xF0; // 0xF0 is false (default), 0xF1 is true.
0777: boolean qryattscrReceived = false;
0778: int qryattsns = CodePoint.QRYUNK;
0779: boolean qryattsnsReceived = false;
0780: int qryattupd = CodePoint.QRYUNK;
0781: boolean qryattupdReceived = false;
0782: long qryinsid = 0;
0783: boolean qryinsidReceived = false;
0784:
0785: int qryattset = 0xF0; // 0xF0 is false (default), 0xF1 is true.
0786: boolean qryattsetReceived = false;
0787:
0788: parseLengthAndMatchCodePoint(CodePoint.OPNQRYRM);
0789: //pushLengthOnCollectionStack();
0790: int ddmLength = getDdmLength();
0791: ensureBLayerDataInBuffer(ddmLength);
0792: int peekCP = peekCodePoint();
0793: int length = 0;
0794:
0795: //while (peekCP != Reply.END_OF_COLLECTION) {
0796: while (ddmLength > 0) {
0797:
0798: boolean foundInPass = false;
0799:
0800: if (peekCP == CodePoint.SVRCOD) {
0801: foundInPass = true;
0802: svrcodReceived = checkAndGetReceivedFlag(svrcodReceived);
0803: length = peekedLength_;
0804: svrcod = parseFastSVRCOD(CodePoint.SVRCOD_INFO,
0805: CodePoint.SVRCOD_SESDMG);
0806: ddmLength = adjustDdmLength(ddmLength, length);
0807: peekCP = peekCodePoint();
0808: }
0809:
0810: if (peekCP == CodePoint.QRYPRCTYP) {
0811: foundInPass = true;
0812: qryprctypReceived = checkAndGetReceivedFlag(qryprctypReceived);
0813: length = peekedLength_;
0814: qryprctyp = parseFastQRYPRCTYP();
0815: ddmLength = adjustDdmLength(ddmLength, length);
0816: peekCP = peekCodePoint();
0817: }
0818:
0819: if (peekCP == CodePoint.SQLCSRHLD) {
0820: // Indicates whether the requester specified the HOLD option.
0821: // When specified, the cursor is not closed upon execution of a commit operation.
0822: foundInPass = true;
0823: sqlcsrhldReceived = checkAndGetReceivedFlag(sqlcsrhldReceived);
0824: length = peekedLength_;
0825: sqlcsrhld = parseFastSQLCSRHLD();
0826: ddmLength = adjustDdmLength(ddmLength, length);
0827: peekCP = peekCodePoint();
0828: }
0829:
0830: if (peekCP == CodePoint.QRYATTSCR) {
0831: foundInPass = true;
0832: qryattscrReceived = checkAndGetReceivedFlag(qryattscrReceived);
0833: length = peekedLength_;
0834: qryattscr = parseFastQRYATTSCR();
0835: ddmLength = adjustDdmLength(ddmLength, length);
0836: peekCP = peekCodePoint();
0837: }
0838:
0839: if (peekCP == CodePoint.QRYATTSNS) {
0840: foundInPass = true;
0841: qryattsnsReceived = checkAndGetReceivedFlag(qryattsnsReceived);
0842: length = peekedLength_;
0843: qryattsns = parseFastQRYATTSNS();
0844: ddmLength = adjustDdmLength(ddmLength, length);
0845: peekCP = peekCodePoint();
0846: }
0847:
0848: if (peekCP == CodePoint.QRYATTUPD) {
0849: foundInPass = true;
0850: qryattupdReceived = checkAndGetReceivedFlag(qryattupdReceived);
0851: length = peekedLength_;
0852: qryattupd = parseFastQRYATTUPD();
0853: ddmLength = adjustDdmLength(ddmLength, length);
0854: peekCP = peekCodePoint();
0855: }
0856:
0857: if (peekCP == CodePoint.QRYINSID) {
0858: foundInPass = true;
0859: qryinsidReceived = checkAndGetReceivedFlag(qryinsidReceived);
0860: length = peekedLength_;
0861: qryinsid = parseFastQRYINSID();
0862: ddmLength = adjustDdmLength(ddmLength, length);
0863: peekCP = peekCodePoint();
0864: }
0865:
0866: if (peekCP == CodePoint.QRYATTSET) {
0867: foundInPass = true;
0868: qryattsetReceived = checkAndGetReceivedFlag(qryattsetReceived);
0869: length = peekedLength_;
0870: qryattset = parseFastQRYATTSET();
0871: ddmLength = adjustDdmLength(ddmLength, length);
0872: peekCP = peekCodePoint();
0873: }
0874:
0875: if (!foundInPass) {
0876: doPrmnsprmSemantics(peekCP);
0877: }
0878:
0879: }
0880: checkRequiredObjects(svrcodReceived, qryprctypReceived,
0881: qryinsidReceived);
0882:
0883: netAgent_.setSvrcod(svrcod);
0884:
0885: // hack for now until event methods are used below
0886: Statement statement = (Statement) statementI;
0887:
0888: // if there is a cached Cursor object, then use the cached cursor object.
0889: NetResultSet rs = null;
0890: if (statement.cachedCursor_ != null) {
0891: statement.cachedCursor_.resetDataBuffer();
0892: ((NetCursor) statement.cachedCursor_).extdtaData_.clear();
0893: try {
0894: rs = (NetResultSet) ClientDriver
0895: .getFactory()
0896: .newNetResultSet(
0897: netAgent_,
0898: (NetStatement) statement.materialStatement_,
0899: statement.cachedCursor_,
0900: qryprctyp, //protocolType, CodePoint.FIXROWPRC |
0901: // CodePoint.LMTBLKPRC
0902: sqlcsrhld, //holdOption, 0xF0 for false (default) | 0xF1 for true.
0903: qryattscr, //scrollOption, 0xF0 for false (default) | 0xF1 for true.
0904: qryattsns, //sensitivity, CodePoint.QRYUNK |
0905: // CodePoint.QRYINS |
0906: // CodePoint.QRYSNSSTC
0907: qryattset,
0908: qryinsid, //instanceIdentifier, 0 (if not returned, check default) or number
0909: calculateResultSetType(qryattscr,
0910: qryattsns,
0911: statement.resultSetType_),
0912: calculateResultSetConcurrency(
0913: qryattupd,
0914: statement.resultSetConcurrency_),
0915: calculateResultSetHoldability(sqlcsrhld));
0916: } catch (SqlException sqle) {
0917: throw new DisconnectException(netAgent_, sqle);
0918: }
0919: } else {
0920: try {
0921: rs = (NetResultSet) ClientDriver
0922: .getFactory()
0923: .newNetResultSet(
0924: netAgent_,
0925: (NetStatement) statement.materialStatement_,
0926: new NetCursor(netAgent_, qryprctyp),
0927: qryprctyp, //protocolType, CodePoint.FIXROWPRC |
0928: // CodePoint.LMTBLKPRC
0929: sqlcsrhld, //holdOption, 0xF0 for false (default) | 0xF1 for true.
0930: qryattscr, //scrollOption, 0xF0 for false (default) | 0xF1 for true.
0931: qryattsns, //sensitivity, CodePoint.QRYUNK | CodePoint.QRYINS
0932: qryattset,
0933: qryinsid, //instanceIdentifier, 0 (if not returned, check default) or number
0934: calculateResultSetType(qryattscr,
0935: qryattsns,
0936: statement.resultSetType_),
0937: calculateResultSetConcurrency(
0938: qryattupd,
0939: statement.resultSetConcurrency_),
0940: calculateResultSetHoldability(sqlcsrhld));
0941: } catch (SqlException sqle) {
0942: throw new DisconnectException(netAgent_, sqle);
0943: }
0944:
0945: }
0946:
0947: // QRYCLSIMP only applies to OPNQRY, not EXCSQLSTT
0948: final boolean qryclsimp = isOPNQRYreply
0949: && (rs.resultSetType_ == java.sql.ResultSet.TYPE_FORWARD_ONLY)
0950: && netAgent_.netConnection_.serverSupportsQryclsimp();
0951: rs.netCursor_.setQryclsimpEnabled(qryclsimp);
0952:
0953: return rs;
0954: }
0955:
0956: // Also called by NetResultSetReply subclass.
0957: // The End of Query Reply Message indicates that the query process has
0958: // terminated in such a manner that the query or result set is now closed.
0959: // It cannot be resumed with the CNTQRY command or closed with the CLSQRY command.
0960: // The ENDQRYRM is always followed by an SQLCARD.
0961: protected void parseENDQRYRM(ResultSetCallbackInterface resultSetI)
0962: throws DisconnectException {
0963: boolean svrcodReceived = false;
0964: int svrcod = CodePoint.SVRCOD_INFO;
0965: boolean rdbnamReceived = false;
0966: String rdbnam = null;
0967:
0968: parseLengthAndMatchCodePoint(CodePoint.ENDQRYRM);
0969: pushLengthOnCollectionStack();
0970: int peekCP = peekCodePoint();
0971:
0972: while (peekCP != Reply.END_OF_COLLECTION) {
0973:
0974: boolean foundInPass = false;
0975:
0976: if (peekCP == CodePoint.SVRCOD) {
0977: foundInPass = true;
0978: svrcodReceived = checkAndGetReceivedFlag(svrcodReceived);
0979: svrcod = parseSVRCOD(CodePoint.SVRCOD_WARNING,
0980: CodePoint.SVRCOD_ERROR);
0981: peekCP = peekCodePoint();
0982: }
0983:
0984: if (peekCP == CodePoint.RDBNAM) {
0985: foundInPass = true;
0986: rdbnamReceived = checkAndGetReceivedFlag(rdbnamReceived);
0987: rdbnam = parseRDBNAM(true);
0988: peekCP = peekCodePoint();
0989: }
0990: if (!foundInPass) {
0991: doPrmnsprmSemantics(peekCP);
0992: }
0993:
0994: }
0995: popCollectionStack();
0996: checkRequiredObjects(svrcodReceived);
0997:
0998: netAgent_.setSvrcod(svrcod);
0999:
1000: }
1001:
1002: // Query Previously Opened Reply Message is issued when an
1003: // OPNQRY command is issued for a query that is already open.
1004: // A previous OPNQRY command might have opened the query
1005: // which may not be closed.
1006: // PROTOCOL Architects an SQLSTATE of 58008 or 58009.
1007: //
1008: // Messages
1009: // SQLSTATE : 58009
1010: // Execution failed due to a distribution protocol error that caused deallocation of the conversation.
1011: // SQLCODE : -30020
1012: // Execution failed because of a Distributed Protocol
1013: // Error that will affect the successful execution of subsequent
1014: // commands and SQL statements: Reason Code <reason-code>.
1015: // Some possible reason codes include:
1016: // 121C Indicates that the user is not authorized to perform the requested command.
1017: // 1232 The command could not be completed because of a permanent error.
1018: // In most cases, the server will be in the process of an abend.
1019: // 220A The target server has received an invalid data description.
1020: // If a user SQLDA is specified, ensure that the fields are
1021: // initialized correctly. Also, ensure that the length does not
1022: // exceed the maximum allowed length for the data type being used.
1023: //
1024: // The command or statement cannot be processed. The current
1025: // transaction is rolled back and the application is disconnected
1026: // from the remote database.
1027: //
1028: //
1029: // Returned from Server:
1030: // SVRCOD - required (8 - ERROR)
1031: // RDBNAM - required
1032: // PKGNAMCSN - required
1033: // SRVDGN - optional
1034: //
1035: private void parseQRYPOPRM() throws DisconnectException {
1036: boolean svrcodReceived = false;
1037: int svrcod = CodePoint.SVRCOD_INFO;
1038: boolean rdbnamReceived = false;
1039: String rdbnam = null;
1040: boolean pkgnamcsnReceived = false;
1041: Object pkgnamcsn = null;
1042:
1043: parseLengthAndMatchCodePoint(CodePoint.QRYPOPRM);
1044: pushLengthOnCollectionStack();
1045: int peekCP = peekCodePoint();
1046:
1047: while (peekCP != Reply.END_OF_COLLECTION) {
1048:
1049: boolean foundInPass = false;
1050:
1051: if (peekCP == CodePoint.SVRCOD) {
1052: foundInPass = true;
1053: svrcodReceived = checkAndGetReceivedFlag(svrcodReceived);
1054: svrcod = parseSVRCOD(CodePoint.SVRCOD_ERROR,
1055: CodePoint.SVRCOD_ERROR);
1056: peekCP = peekCodePoint();
1057: }
1058:
1059: if (peekCP == CodePoint.RDBNAM) {
1060: foundInPass = true;
1061: rdbnamReceived = checkAndGetReceivedFlag(rdbnamReceived);
1062: rdbnam = parseRDBNAM(true);
1063: peekCP = peekCodePoint();
1064: }
1065: if (peekCP == CodePoint.PKGNAMCSN) {
1066: foundInPass = true;
1067: pkgnamcsnReceived = checkAndGetReceivedFlag(pkgnamcsnReceived);
1068: pkgnamcsn = parsePKGNAMCSN(true);
1069: peekCP = peekCodePoint();
1070: }
1071:
1072: if (!foundInPass) {
1073: doPrmnsprmSemantics(peekCP);
1074: }
1075:
1076: }
1077: popCollectionStack();
1078: checkRequiredObjects(svrcodReceived, rdbnamReceived,
1079: pkgnamcsnReceived);
1080:
1081: netAgent_.setSvrcod(svrcod);
1082: agent_
1083: .accumulateChainBreakingReadExceptionAndThrow(new DisconnectException(
1084: agent_,
1085: new ClientMessageId(
1086: SQLState.DRDA_CONNECTION_TERMINATED),
1087: MessageUtil
1088: .getCompleteMessage(
1089: MessageId.CONN_DRDA_QRYOPEN,
1090: SqlException.CLIENT_MESSAGE_RESOURCE_NAME,
1091: (Object[]) null)));
1092: }
1093:
1094: // Open Query Failure (OPNQFLRM) Reply Message indicates that the
1095: // OPNQRY command failed to open the query. The reason that the
1096: // target relational database was unable to open the query is reported in an
1097: // SQLCARD reply data object.
1098: // Whenever an OPNQFLRM is returned, an SQLCARD object must also be returned
1099: // following the OPNQFLRM.
1100: //
1101: // Returned from Server:
1102: // SVRCOD - required (8 - ERROR)
1103: // RDBNAM - required
1104: // SRVDGN - optional
1105: private void parseOPNQFLRM(StatementCallbackInterface statement)
1106: throws DisconnectException {
1107: boolean svrcodReceived = false;
1108: int svrcod = CodePoint.SVRCOD_INFO;
1109: boolean rdbnamReceived = false;
1110: String rdbnam = null;
1111:
1112: parseLengthAndMatchCodePoint(CodePoint.OPNQFLRM);
1113: pushLengthOnCollectionStack();
1114: int peekCP = peekCodePoint();
1115:
1116: while (peekCP != Reply.END_OF_COLLECTION) {
1117:
1118: boolean foundInPass = false;
1119:
1120: if (peekCP == CodePoint.SVRCOD) {
1121: foundInPass = true;
1122: svrcodReceived = checkAndGetReceivedFlag(svrcodReceived);
1123: svrcod = parseSVRCOD(CodePoint.SVRCOD_ERROR,
1124: CodePoint.SVRCOD_ERROR);
1125: peekCP = peekCodePoint();
1126: }
1127:
1128: if (peekCP == CodePoint.RDBNAM) {
1129: // skip the rdbnam since it doesn't tell us anything new.
1130: // there is no way to return it to the application anyway.
1131: // not having to convert this to a string is a time saver also.
1132: foundInPass = true;
1133: rdbnamReceived = checkAndGetReceivedFlag(rdbnamReceived);
1134: rdbnam = parseRDBNAM(true);
1135: peekCP = peekCodePoint();
1136: }
1137: if (!foundInPass) {
1138: doPrmnsprmSemantics(peekCP);
1139: }
1140:
1141: }
1142: popCollectionStack();
1143: checkRequiredObjects(svrcodReceived, rdbnamReceived);
1144:
1145: netAgent_.setSvrcod(svrcod);
1146:
1147: // get SQLSTATE from SQLCARD...
1148: }
1149:
1150: // RDB Result Set Reply Message (RSLSETRM) indicates that an
1151: // EXCSQLSTT command invoked a stored procedure, that the execution
1152: // of the stored procedure generated one or more result sets, and
1153: // additional information aobut these result sets follows the SQLCARD and
1154: // SQLDTARD in the reply data of the response
1155: //
1156: // Returned from Server:
1157: // SVRCOD - required (0 INFO)
1158: // PKGSNLST - required
1159: // SRVDGN - optional
1160: protected java.util.ArrayList parseRSLSETRM()
1161: throws DisconnectException {
1162: boolean svrcodReceived = false;
1163: int svrcod = CodePoint.SVRCOD_INFO;
1164: boolean pkgsnlstReceived = false;
1165: java.util.ArrayList pkgsnlst = null;
1166:
1167: parseLengthAndMatchCodePoint(CodePoint.RSLSETRM);
1168: pushLengthOnCollectionStack();
1169: int peekCP = peekCodePoint();
1170:
1171: while (peekCP != Reply.END_OF_COLLECTION) {
1172:
1173: boolean foundInPass = false;
1174:
1175: if (peekCP == CodePoint.SVRCOD) {
1176: foundInPass = true;
1177: svrcodReceived = checkAndGetReceivedFlag(svrcodReceived);
1178: svrcod = parseSVRCOD(CodePoint.SVRCOD_INFO,
1179: CodePoint.SVRCOD_INFO);
1180: peekCP = peekCodePoint();
1181: }
1182:
1183: if (peekCP == CodePoint.PKGSNLST) {
1184: // contain repeatable PKGNAMCSN
1185: foundInPass = true;
1186: pkgsnlstReceived = checkAndGetReceivedFlag(pkgsnlstReceived);
1187: pkgsnlst = parsePKGSNLST();
1188: peekCP = peekCodePoint();
1189: }
1190:
1191: if (!foundInPass) {
1192: doPrmnsprmSemantics(peekCP);
1193: }
1194:
1195: }
1196: popCollectionStack();
1197: checkRequiredObjects(svrcodReceived, pkgsnlstReceived);
1198:
1199: netAgent_.setSvrcod(svrcod);
1200:
1201: return pkgsnlst;
1202: }
1203:
1204: //--------------------- parse DDM Reply Data--------------------------------------
1205:
1206: // SQL Data Reply Data consists of output data from the relational database (RDB)
1207: // processing of an SQL statement. It also includes a description of the data.
1208: //
1209: // Returned from Server:
1210: // FDODSC - required
1211: // FDODTA - required
1212: protected NetSqlca parseSQLDTARD(NetSqldta netSqldta)
1213: throws DisconnectException {
1214: boolean fdodscReceived = false;
1215: boolean fdodtaReceived = false;
1216:
1217: parseLengthAndMatchCodePoint(CodePoint.SQLDTARD);
1218: pushLengthOnCollectionStack();
1219:
1220: NetSqlca netSqlca = null;
1221: int peekCP = peekCodePoint();
1222: while (peekCP != Reply.END_OF_COLLECTION) {
1223:
1224: boolean foundInPass = false;
1225:
1226: if (peekCP == CodePoint.FDODSC) {
1227: foundInPass = true;
1228: fdodscReceived = checkAndGetReceivedFlag(fdodscReceived);
1229: parseFDODSC(netSqldta);
1230: peekCP = peekCodePoint();
1231: }
1232:
1233: if (peekCP == CodePoint.FDODTA) {
1234: foundInPass = true;
1235: fdodtaReceived = checkAndGetReceivedFlag(fdodtaReceived);
1236: netSqlca = parseFDODTA(netSqldta);
1237: peekCP = peekCodePoint();
1238: }
1239:
1240: if (!foundInPass) {
1241: doPrmnsprmSemantics(peekCP);
1242: }
1243:
1244: }
1245: popCollectionStack();
1246: checkRequiredObjects(fdodscReceived, fdodtaReceived);
1247: netSqldta.calculateColumnOffsetsForRow();
1248: return netSqlca;
1249: }
1250:
1251: protected void parseQRYDSC(NetCursor cursor)
1252: throws DisconnectException {
1253: parseLengthAndMatchCodePoint(CodePoint.QRYDSC);
1254: parseSQLDTARDarray(cursor, false); // false means don't just skip the bytes
1255: }
1256:
1257: private void parseFDODSC(NetCursor cursor)
1258: throws DisconnectException {
1259: parseLengthAndMatchCodePoint(CodePoint.FDODSC);
1260: parseSQLDTARDarray(cursor, false); // false means don't just skip the bytes
1261: }
1262:
1263: private void parseSQLDTARDarray(NetCursor cursor, boolean skipBytes)
1264: throws DisconnectException {
1265: if (skipBytes) {
1266: skipBytes();
1267: }
1268: int previousTripletType = FdocaConstants.SQLDTARD_TRIPLET_TYPE_START;
1269: int previousTripletId = FdocaConstants.SQLDTARD_TRIPLET_ID_START;
1270: int mddProtocolType = 0;
1271: int columnCount = 0;
1272: netAgent_.targetTypdef_.clearMddOverrides();
1273:
1274: int ddmLength = getDdmLength();
1275: ensureBLayerDataInBuffer(ddmLength);
1276:
1277: while (ddmLength > 0) {
1278:
1279: int tripletLength = readFastUnsignedByte();
1280: int tripletType = readFastUnsignedByte();
1281: int tripletId = readFastUnsignedByte();
1282:
1283: switch (tripletType) {
1284:
1285: case FdocaConstants.MDD_TRIPLET_TYPE:
1286: if ((tripletLength != FdocaConstants.MDD_TRIPLET_SIZE)
1287: || (tripletId != FdocaConstants.NULL_LID)) {
1288: descriptorErrorDetected();
1289: }
1290: checkPreviousSQLDTARDtriplet(previousTripletType,
1291: FdocaConstants.SQLDTARD_TRIPLET_TYPE_MDD,
1292: previousTripletId,
1293: FdocaConstants.SQLDTARD_TRIPLET_ID_0);
1294: previousTripletType = FdocaConstants.SQLDTARD_TRIPLET_TYPE_MDD;
1295: previousTripletId = FdocaConstants.SQLDTARD_TRIPLET_ID_0;
1296:
1297: // read in remaining MDD bytes
1298: int mddClass = readFastUnsignedByte();
1299: int mddType = readFastUnsignedByte();
1300: int mddRefType = readFastUnsignedByte();
1301: mddProtocolType = readFastUnsignedByte();
1302: break;
1303:
1304: case FdocaConstants.NGDA_TRIPLET_TYPE: // rename to NGDA_TRIPLET_CODEPOINT
1305: if (tripletId != FdocaConstants.SQLDTAGRP_LID) {
1306: descriptorErrorDetected();
1307: }
1308: checkPreviousSQLDTARDtriplet(previousTripletType,
1309: FdocaConstants.SQLDTARD_TRIPLET_TYPE_GDA,
1310: previousTripletId,
1311: FdocaConstants.SQLDTARD_TRIPLET_ID_D0);
1312: previousTripletType = FdocaConstants.SQLDTARD_TRIPLET_TYPE_GDA;
1313: previousTripletId = FdocaConstants.SQLDTARD_TRIPLET_ID_0;
1314:
1315: // add a quick check to see if the table is altered (columns are added or deleted)
1316: // before reusing the cached cursor. note: this check does not catch the case
1317: // where the number of columns stay the same, but the column type or length changes,
1318: // i.e. from integer to char.
1319: int columns = peekTotalColumnCount(tripletLength);
1320: // peek ahead to get the total number of columns.
1321: cursor.initializeColumnInfoArrays(
1322: netAgent_.targetTypdef_, columns,
1323: netAgent_.targetSqlam_);
1324: columnCount += parseSQLDTAGRPdataLabelsAndUpdateColumn(
1325: cursor, columnCount, tripletLength);
1326: break;
1327:
1328: case FdocaConstants.RLO_TRIPLET_TYPE: // rename to RLO_TRIPLET_CODEPOINT
1329:
1330: switch (tripletId) {
1331: case FdocaConstants.SQLCADTA_LID:
1332: if (tripletLength != FdocaConstants.SQLCADTA_RLO_SIZE) {
1333: descriptorErrorDetected(); // DSCERRCD_06
1334: }
1335: checkPreviousSQLDTARDtriplet(previousTripletType,
1336: FdocaConstants.SQLDTARD_TRIPLET_TYPE_RLO,
1337: previousTripletId,
1338: FdocaConstants.SQLDTARD_TRIPLET_ID_E0);
1339: previousTripletType = FdocaConstants.SQLDTARD_TRIPLET_TYPE_RLO;
1340: previousTripletId = FdocaConstants.SQLDTARD_TRIPLET_ID_E0;
1341: checkFastRLO(FdocaConstants.RLO_SQLCADTA);
1342: break;
1343:
1344: case FdocaConstants.SQLDTARD_LID:
1345: if (tripletLength != FdocaConstants.SQLDTARD_RLO_SIZE) {
1346: descriptorErrorDetected(); // DSCERRCD_06
1347: }
1348: checkPreviousSQLDTARDtriplet(previousTripletType,
1349: FdocaConstants.SQLDTARD_TRIPLET_TYPE_RLO,
1350: previousTripletId,
1351: FdocaConstants.SQLDTARD_TRIPLET_ID_F0);
1352: previousTripletType = FdocaConstants.SQLDTARD_TRIPLET_TYPE_RLO;
1353: previousTripletId = FdocaConstants.SQLDTARD_TRIPLET_ID_F0;
1354: checkFastRLO(FdocaConstants.RLO_SQLDTARD);
1355: break;
1356: default:
1357: descriptorErrorDetected(); // DSCERRCD_07
1358: break;
1359: }
1360: break;
1361:
1362: case FdocaConstants.CPT_TRIPLET_TYPE: // rename to CPT_TRIPLET_CODEPOINT
1363: if (tripletId != FdocaConstants.NULL_LID) {
1364: descriptorErrorDetected();
1365: }
1366: checkPreviousSQLDTARDtriplet(previousTripletType,
1367: FdocaConstants.SQLDTARD_TRIPLET_TYPE_CPT,
1368: previousTripletId,
1369: FdocaConstants.SQLDTARD_TRIPLET_ID_0);
1370: previousTripletType = FdocaConstants.SQLDTARD_TRIPLET_TYPE_CPT;
1371: previousTripletId = FdocaConstants.SQLDTARD_TRIPLET_ID_0;
1372:
1373: columnCount += parseSQLDTAGRPdataLabelsAndUpdateColumn(
1374: cursor, columnCount, tripletLength);
1375: break;
1376:
1377: case FdocaConstants.SDA_TRIPLET_TYPE: // rename to SDA_TRIPLET_CODEPOINT
1378: if (tripletLength != FdocaConstants.SDA_TRIPLET_SIZE) {
1379: descriptorErrorDetected(); // DSCERRCD_06
1380: }
1381: checkPreviousSQLDTARDtriplet(previousTripletType,
1382: FdocaConstants.SQLDTARD_TRIPLET_TYPE_SDA,
1383: previousTripletId,
1384: FdocaConstants.SQLDTARD_TRIPLET_ID_SDA);
1385: previousTripletType = FdocaConstants.SQLDTARD_TRIPLET_TYPE_SDA;
1386: previousTripletId = FdocaConstants.SQLDTARD_TRIPLET_ID_SDA;
1387: netAgent_.targetTypdef_.setMddOverride(mddProtocolType, // mdd protocol type
1388: tripletId, // fdocaTripletLid
1389: readFastUnsignedByte(), // fdocaFieldType
1390: readFastInt(), // ccsid
1391: readFastUnsignedByte(), // characterSize
1392: readFastUnsignedByte(), // mode
1393: readFastShort());
1394: break;
1395:
1396: default:
1397: descriptorErrorDetected(); //DSCERRCD_01
1398: break;
1399: }
1400:
1401: ddmLength -= tripletLength;
1402: }
1403:
1404: adjustLengths(getDdmLength());
1405:
1406: // Allocate a char buffer after all of the descriptors have been parsed out.
1407: cursor.allocateCharBuffer();
1408:
1409: checkPreviousSQLDTARDtriplet(previousTripletType,
1410: FdocaConstants.SQLDTARD_TRIPLET_TYPE_END,
1411: previousTripletId,
1412: FdocaConstants.SQLDTARD_TRIPLET_ID_END);
1413:
1414: }
1415:
1416: private void checkPreviousSQLDTARDtriplet(int previousTripletType,
1417: int tripletType, int previousTripletId, int tripletId)
1418: throws DisconnectException {
1419: if (FdocaConstants.SQLDTARD_TRIPLET_TYPES[previousTripletType][tripletType] == false) {
1420: descriptorErrorDetected(); // DSCERRCD_02 move error identity into array
1421: }
1422: if (FdocaConstants.SQLDTARD_TRIPLET_IDS[previousTripletId][tripletId] == false) {
1423: descriptorErrorDetected(); // DSCERRCD_02 move error identity into array
1424: }
1425: }
1426:
1427: private void checkFastRLO(int[][] rlo) throws DisconnectException {
1428: for (int i = 0; i < rlo.length; i++) {
1429: int lid = readFastUnsignedByte();
1430: if (lid != rlo[i][FdocaConstants.RLO_GROUP_LID]) {
1431: descriptorErrorDetected(); // DSCERRCD_42
1432: }
1433: int elementTaken = readFastUnsignedByte();
1434: if (elementTaken != rlo[i][FdocaConstants.RLO_ELEMENT_TAKEN]) {
1435: descriptorErrorDetected(); // DSCERRCD_07
1436: }
1437: int repFactor = readFastUnsignedByte();
1438: if (repFactor != rlo[i][FdocaConstants.RLO_REP_FACTOR]) {
1439: descriptorErrorDetected(); // DSCERRCD_07
1440: }
1441: }
1442: }
1443:
1444: // Possible errors to detect include:
1445: // DSCERRCD_01 - FDOCA triplet is not used in PROTOCOL descriptors or type code is invalid
1446: // DSCERRCD_02 - FDOCA triplet sequence error
1447: // DSCERRCD_03 - An array description is required and this is not one
1448: // (too many or too few RLO triplets)
1449: // DSCERRCD_04 - A row description is required and this is not one
1450: // (too many or too few RLO triplets)
1451: // DSCERRCD_05 - Late Environmental Descriptor just received not supported
1452: // DSCERRCD_06 - Malformed triplet, required parameter is missing
1453: // DSCERRCD_07 - Parameter value is not acceptable
1454: // DSCERRCD_11 - MDD present is not recognized as an SQL descriptor
1455: // DSCERRCD_12 - MDD class is not recognized as a valid SQL class
1456: // DSCERRCD_13 - MDD type not recognized as a valid SQL type
1457: // DSCERRCD_21 - Representation is incompatible with SQL type (in prior MDD)
1458: // DSCERRCD_22 - CCSID is not supported
1459: // DSCERRCD_32 - GDA references a local identifier which is not an SDA or GDA
1460: // DSCERRCD_33 - GDA length override exceeds limits
1461: // DSCERRCD_34 - GDA precision exceeds limits
1462: // DSCERRCD_35 - GDA scale greater than precision or scale negative
1463: // DSCERRCD_36 - GDA length override missing or incompatible with data type
1464: // DSCERRCD_41 - RLO references a LID which is not an RLO or GDA.
1465: // DSCERRCD_42 - RLO fails to reference a required GDA or RLO.
1466: private void descriptorErrorDetected() throws DisconnectException {
1467: agent_
1468: .accumulateChainBreakingReadExceptionAndThrow(new DisconnectException(
1469: agent_,
1470: new ClientMessageId(
1471: SQLState.DRDA_CONNECTION_TERMINATED),
1472: MessageUtil
1473: .getCompleteMessage(
1474: MessageId.CONN_DRDA_INVALIDFDOCA,
1475: SqlException.CLIENT_MESSAGE_RESOURCE_NAME,
1476: (Object[]) null)));
1477: }
1478:
1479: protected void parseQRYDTA(NetResultSet netResultSet)
1480: throws DisconnectException {
1481: parseLengthAndMatchCodePoint(CodePoint.QRYDTA);
1482: if (longValueForDecryption_ == null) {
1483: int ddmLength = getDdmLength();
1484: ensureBLayerDataInBuffer(ddmLength);
1485: }
1486: parseSQLDTARDdata(netResultSet.netCursor_);
1487: if (longValueForDecryption_ == null) {
1488: adjustLengths(getDdmLength());
1489: } else {
1490: longValueForDecryption_ = null;
1491: }
1492: if (longBufferForDecryption_ != null) {
1493: buffer_ = longBufferForDecryption_;
1494: pos_ = longPosForDecryption_;
1495: if (count_ > longBufferForDecryption_.length) {
1496: count_ = longBufferForDecryption_.length;
1497: } else if (longCountForDecryption_ != 0) {
1498: count_ = longCountForDecryption_;
1499: longCountForDecryption_ = 0;
1500: }
1501: dssLength_ = 0;
1502: longBufferForDecryption_ = null;
1503: }
1504:
1505: }
1506:
1507: NetSqlca parseFDODTA(NetCursor netCursor)
1508: throws DisconnectException {
1509: parseLengthAndMatchCodePoint(CodePoint.FDODTA);
1510: int ddmLength = getDdmLength();
1511: ensureBLayerDataInBuffer(ddmLength);
1512: mark();
1513: NetSqlca netSqlca = parseSQLCARDrow(null);
1514: int length = getFastSkipSQLCARDrowLength();
1515: adjustLengths(length);
1516: parseFastSQLDTARDdata(netCursor);
1517: return netSqlca;
1518: }
1519:
1520: void parseFastSQLDTARDdata(NetCursor netCursor)
1521: throws DisconnectException {
1522: netCursor.dataBufferStream_ = getFastData(netCursor.dataBufferStream_);
1523: netCursor.dataBuffer_ = netCursor.dataBufferStream_
1524: .toByteArray();
1525: netCursor.lastValidBytePosition_ = netCursor.dataBuffer_.length;
1526: }
1527:
1528: void parseSQLDTARDdata(NetCursor netCursor)
1529: throws DisconnectException {
1530: if (longValueForDecryption_ == null) {
1531: netCursor.dataBufferStream_ = getData(netCursor.dataBufferStream_);
1532: netCursor.dataBuffer_ = netCursor.dataBufferStream_
1533: .toByteArray();
1534: } else {
1535: int size = netCursor.dataBufferStream_.size();
1536: if (size == 0) {
1537: netCursor.dataBuffer_ = longValueForDecryption_;
1538: //longValue_ = null;
1539: } else {
1540: byte[] newArray = new byte[size
1541: + longValueForDecryption_.length];
1542: System.arraycopy(netCursor.dataBuffer_, 0, newArray, 0,
1543: size);
1544: System.arraycopy(longValueForDecryption_, 0, newArray,
1545: size, longValueForDecryption_.length);
1546: netCursor.dataBuffer_ = newArray;
1547: //longValue_ = null;
1548: }
1549: }
1550:
1551: netCursor.lastValidBytePosition_ = netCursor.dataBuffer_.length;
1552: }
1553:
1554: protected void copyEXTDTA(NetCursor netCursor)
1555: throws DisconnectException {
1556: try {
1557: parseLengthAndMatchCodePoint(CodePoint.EXTDTA);
1558: byte[] data = null;
1559: if (longValueForDecryption_ == null) {
1560: data = (getData(null)).toByteArray();
1561: } else {
1562: data = longValueForDecryption_;
1563: dssLength_ = 0;
1564: longValueForDecryption_ = null;
1565: }
1566: netCursor.extdtaData_.add(data);
1567: } catch (java.lang.OutOfMemoryError e) {
1568: agent_
1569: .accumulateChainBreakingReadExceptionAndThrow(new DisconnectException(
1570: agent_,
1571: new ClientMessageId(
1572: SQLState.NET_LOB_DATA_TOO_LARGE_FOR_JVM),
1573: null, e));
1574: }
1575: }
1576:
1577: //------------------------parse DDM Scalars-----------------------------
1578:
1579: // RDB Package name, consistency token, and section number
1580: // specifies the fully qualified name of a relational
1581: // database package, its consistency token, and a specific
1582: // section within a package.
1583: //
1584: // Only called for generated secctions from a callable statement.
1585: //
1586: protected Object parsePKGNAMCSN(boolean skip)
1587: throws DisconnectException {
1588: parseLengthAndMatchCodePoint(CodePoint.PKGNAMCSN);
1589: if (skip) {
1590: skipBytes();
1591: return null;
1592: }
1593:
1594: // Still need to populate the logical members in case of an "set current packageset"
1595: String rdbnam = null;
1596: String rdbcolid = null;
1597: String pkgid = null;
1598: byte[] pkgcnstkn = null;
1599:
1600: int pkgsn = 0;
1601: byte[] pkgnamcsnBytes = null;
1602: int pkgnamcsnLength = 0;
1603:
1604: int ddmLength = getDdmLength();
1605: int offset = 0;
1606:
1607: ensureBLayerDataInBuffer(ddmLength);
1608:
1609: if (ddmLength == 64) {
1610: // read all the bytes except the section number into the byte[] for caching
1611: pkgnamcsnLength = ddmLength - 2;
1612: //pkgnamcsnBytes = readBytes (pkgnamcsnLength);
1613: pkgnamcsnBytes = new byte[pkgnamcsnLength];
1614: // readFast() does a read without moving the read head.
1615: offset = peekFastBytes(pkgnamcsnBytes, offset,
1616: pkgnamcsnLength);
1617:
1618: // populate the logical members
1619: rdbnam = readFastString(18); // RDB name
1620: rdbcolid = readFastString(18); // RDB Collection ID
1621: pkgid = readFastString(18); // RDB Package ID
1622: pkgcnstkn = readFastBytes(8); // Package Consistency Token
1623: } else if ((ddmLength >= 71) && (ddmLength <= 781)) {
1624: // this is the new SCLDTA format.
1625:
1626: // new up a byte[] to cache all the bytes except the 2-byte section number
1627: pkgnamcsnBytes = new byte[ddmLength - 2];
1628:
1629: // get rdbnam
1630: int scldtaLen = peekFastLength();
1631: if (scldtaLen < 18 || scldtaLen > 255) {
1632: agent_
1633: .accumulateChainBreakingReadExceptionAndThrow(new DisconnectException(
1634: agent_,
1635: new ClientMessageId(
1636: SQLState.NET_SQLCDTA_INVALID_FOR_RDBNAM),
1637: new Integer(scldtaLen)));
1638: return null;
1639: }
1640: // read 2+scldtaLen number of bytes from the reply buffer into the pkgnamcsnBytes
1641: //offset = readBytes (pkgnamcsnBytes, offset, 2+scldtaLen);
1642: offset = peekFastBytes(pkgnamcsnBytes, offset,
1643: 2 + scldtaLen);
1644: skipFastBytes(2);
1645: rdbnam = readFastString(scldtaLen);
1646:
1647: // get rdbcolid
1648: scldtaLen = peekFastLength();
1649: if (scldtaLen < 18 || scldtaLen > 255) {
1650: agent_
1651: .accumulateChainBreakingReadExceptionAndThrow(new DisconnectException(
1652: agent_,
1653: new ClientMessageId(
1654: SQLState.NET_SQLCDTA_INVALID_FOR_RDBCOLID),
1655: new Integer(scldtaLen)));
1656: return null;
1657: }
1658: // read 2+scldtaLen number of bytes from the reply buffer into the pkgnamcsnBytes
1659: offset = peekFastBytes(pkgnamcsnBytes, offset,
1660: 2 + scldtaLen);
1661: skipFastBytes(2);
1662: rdbcolid = readFastString(scldtaLen);
1663:
1664: // get pkgid
1665: scldtaLen = peekFastLength();
1666: if (scldtaLen < 18 || scldtaLen > 255) {
1667: agent_
1668: .accumulateChainBreakingReadExceptionAndThrow(new DisconnectException(
1669: agent_,
1670: new ClientMessageId(
1671: SQLState.NET_SQLCDTA_INVALID_FOR_PKGID),
1672: new Integer(scldtaLen)));
1673: return null; // To make compiler happy.
1674: }
1675: // read 2+scldtaLen number of bytes from the reply buffer into the pkgnamcsnBytes
1676: offset = peekFastBytes(pkgnamcsnBytes, offset,
1677: 2 + scldtaLen);
1678: skipFastBytes(2);
1679: pkgid = readFastString(scldtaLen);
1680:
1681: // get consistency token
1682: offset = peekFastBytes(pkgnamcsnBytes, offset, 8);
1683: pkgcnstkn = readFastBytes(8);
1684:
1685: } else {
1686: agent_
1687: .accumulateChainBreakingReadExceptionAndThrow(new DisconnectException(
1688: agent_,
1689: new ClientMessageId(
1690: SQLState.NET_PGNAMCSN_INVALID_AT_SQLAM),
1691: new Integer(ddmLength), new Integer(
1692: netAgent_.targetSqlam_)));
1693: return null; // To make compiler happy.
1694: }
1695:
1696: pkgsn = readFastUnsignedShort(); // Package Section Number.
1697: adjustLengths(ddmLength);
1698: // this is a server generated section
1699: // the -1 is set for holdability and it is not used for generated sections
1700: Section section = new Section(this .agent_, pkgid, pkgsn, null,
1701: -1, true);
1702: section.setPKGNAMCBytes(pkgnamcsnBytes);
1703: return section;
1704: }
1705:
1706: // Query Protocol type specifies the type of query protocol
1707: // the target SQLAM uses.
1708: protected int parseQRYPRCTYP() throws DisconnectException {
1709: parseLengthAndMatchCodePoint(CodePoint.QRYPRCTYP);
1710: int qryprctyp = parseCODPNTDR();
1711: if ((qryprctyp != CodePoint.FIXROWPRC)
1712: && (qryprctyp != CodePoint.LMTBLKPRC)) {
1713: doValnsprmSemantics(CodePoint.QRYPRCTYP, qryprctyp);
1714: }
1715: return qryprctyp;
1716: }
1717:
1718: protected int parseFastQRYPRCTYP() throws DisconnectException {
1719: matchCodePoint(CodePoint.QRYPRCTYP);
1720: int qryprctyp = readFastUnsignedShort();
1721: if ((qryprctyp != CodePoint.FIXROWPRC)
1722: && (qryprctyp != CodePoint.LMTBLKPRC)) {
1723: doValnsprmSemantics(CodePoint.QRYPRCTYP, qryprctyp);
1724: }
1725: return qryprctyp;
1726: }
1727:
1728: // hold cursor position state indicates whether the requester specified
1729: // the HOLD option on the SQL DECLARE CURSOR statement. When the HOLD
1730: // option is specified, the cursor is not closed upon execution of a
1731: // commit operation.
1732: // The value TRUE indicates that the requester specifies the HOLD
1733: // operation. The value FALSSE indicates that the requeter is not
1734: // specifying the HOLD option.
1735: protected int parseSQLCSRHLD() throws DisconnectException {
1736: parseLengthAndMatchCodePoint(CodePoint.SQLCSRHLD);
1737: int sqlcsrhld = readUnsignedByte();
1738: // 0xF0 is false (default), 0xF1 is true // use constants in if
1739: if ((sqlcsrhld != 0xF0) && (sqlcsrhld != 0xF1)) {
1740: doValnsprmSemantics(CodePoint.SQLCSRHLD, sqlcsrhld);
1741: }
1742: return sqlcsrhld;
1743: }
1744:
1745: protected int parseFastSQLCSRHLD() throws DisconnectException {
1746: matchCodePoint(CodePoint.SQLCSRHLD);
1747: int sqlcsrhld = readFastUnsignedByte();
1748: // 0xF0 is false (default), 0xF1 is true // use constants in if
1749: if ((sqlcsrhld != 0xF0) && (sqlcsrhld != 0xF1)) {
1750: doValnsprmSemantics(CodePoint.SQLCSRHLD, sqlcsrhld);
1751: }
1752: return sqlcsrhld;
1753: }
1754:
1755: // Query Attribute for Scrollability indicates whether
1756: // a cursor is scrollable or non-scrollable
1757: protected int parseQRYATTSCR() throws DisconnectException {
1758: parseLengthAndMatchCodePoint(CodePoint.QRYATTSCR);
1759: int qryattscr = readUnsignedByte(); // use constants in if
1760: if ((qryattscr != 0xF0) && (qryattscr != 0xF1)) {
1761: doValnsprmSemantics(CodePoint.QRYATTSCR, qryattscr);
1762: }
1763: return qryattscr;
1764: }
1765:
1766: protected int parseFastQRYATTSCR() throws DisconnectException {
1767: matchCodePoint(CodePoint.QRYATTSCR);
1768: int qryattscr = readFastUnsignedByte(); // use constants in if
1769: if ((qryattscr != 0xF0) && (qryattscr != 0xF1)) {
1770: doValnsprmSemantics(CodePoint.QRYATTSCR, qryattscr);
1771: }
1772: return qryattscr;
1773: }
1774:
1775: // enabled for rowset positioning.
1776: protected int parseQRYATTSET() throws DisconnectException {
1777: parseLengthAndMatchCodePoint(CodePoint.QRYATTSET);
1778: int qryattset = readUnsignedByte(); // use constants in if
1779: if ((qryattset != 0xF0) && (qryattset != 0xF1)) {
1780: doValnsprmSemantics(CodePoint.QRYATTSET, qryattset);
1781: }
1782: return qryattset;
1783: }
1784:
1785: protected int parseFastQRYATTSET() throws DisconnectException {
1786: matchCodePoint(CodePoint.QRYATTSET);
1787: int qryattset = readFastUnsignedByte(); // use constants in if
1788: if ((qryattset != 0xF0) && (qryattset != 0xF1)) {
1789: doValnsprmSemantics(CodePoint.QRYATTSET, qryattset);
1790: }
1791: return qryattset;
1792: }
1793:
1794: // Query attribute for Sensitivity indicats the sensitivity
1795: // of an opened cursor to changes made to the underlying
1796: // base table.
1797: protected int parseQRYATTSNS() throws DisconnectException {
1798: parseLengthAndMatchCodePoint(CodePoint.QRYATTSNS);
1799: int qryattsns = readUnsignedByte();
1800: switch (qryattsns) {
1801: case CodePoint.QRYUNK:
1802: case CodePoint.QRYINS:
1803: break;
1804: default:
1805: doValnsprmSemantics(CodePoint.QRYATTSNS, qryattsns);
1806: break;
1807: }
1808: return qryattsns;
1809: }
1810:
1811: protected int parseFastQRYATTSNS() throws DisconnectException {
1812: matchCodePoint(CodePoint.QRYATTSNS);
1813: int qryattsns = readFastUnsignedByte();
1814: switch (qryattsns) {
1815: case CodePoint.QRYUNK:
1816: case CodePoint.QRYSNSSTC:
1817: case CodePoint.QRYINS:
1818: break;
1819: default:
1820: doValnsprmSemantics(CodePoint.QRYATTSNS, qryattsns);
1821: break;
1822: }
1823: return qryattsns;
1824: }
1825:
1826: // Query Attribute for Updatability indicates the updatability
1827: // of an opened cursor.
1828: protected int parseQRYATTUPD() throws DisconnectException {
1829: parseLengthAndMatchCodePoint(CodePoint.QRYATTUPD);
1830: int qryattupd = readUnsignedByte();
1831: switch (qryattupd) {
1832: case CodePoint.QRYUNK:
1833: case CodePoint.QRYRDO:
1834: case CodePoint.QRYUPD:
1835: break;
1836: default:
1837: doValnsprmSemantics(CodePoint.QRYATTUPD, qryattupd);
1838: break;
1839: }
1840: return qryattupd;
1841: }
1842:
1843: protected int parseFastQRYATTUPD() throws DisconnectException {
1844: matchCodePoint(CodePoint.QRYATTUPD);
1845: int qryattupd = readFastUnsignedByte();
1846: switch (qryattupd) {
1847: case CodePoint.QRYUNK:
1848: case CodePoint.QRYRDO:
1849: case CodePoint.QRYUPD:
1850: break;
1851: default:
1852: doValnsprmSemantics(CodePoint.QRYATTUPD, qryattupd);
1853: break;
1854: }
1855: return qryattupd;
1856: }
1857:
1858: private long parseFastQRYINSID() throws DisconnectException {
1859: matchCodePoint(CodePoint.QRYINSID);
1860: return readFastLong();
1861: }
1862:
1863: // RDB Package Namce, Consistency Token, and Section Number List
1864: // specifies a list of fully qualified names of specific sections
1865: // within one or more packages.
1866: protected java.util.ArrayList parsePKGSNLST()
1867: throws DisconnectException {
1868: Object pkgnamcsn = null;
1869: java.util.ArrayList pkgsnlst = new java.util.ArrayList(); // what default size should we use
1870:
1871: parseLengthAndMatchCodePoint(CodePoint.PKGSNLST);
1872: pushLengthOnCollectionStack();
1873: while (peekCodePoint() != Reply.END_OF_COLLECTION) {
1874: pkgnamcsn = parsePKGNAMCSN(false);
1875: pkgsnlst.add(pkgnamcsn);
1876: }
1877: popCollectionStack();
1878: return pkgsnlst;
1879: }
1880:
1881: protected NetSqlca parseSQLDARD(ColumnMetaData columnMetaData,
1882: boolean skipBytes) throws DisconnectException {
1883: parseLengthAndMatchCodePoint(CodePoint.SQLDARD);
1884: return parseSQLDARDarray(columnMetaData, skipBytes);
1885: }
1886:
1887: protected int parseSQLRSLRD(java.util.ArrayList sectionAL)
1888: throws DisconnectException {
1889: parseLengthAndMatchCodePoint(CodePoint.SQLRSLRD);
1890: return parseSQLRSLRDarray(sectionAL);
1891: }
1892:
1893: protected ColumnMetaData parseSQLCINRD() throws DisconnectException {
1894: parseLengthAndMatchCodePoint(CodePoint.SQLCINRD);
1895: int ddmLength = getDdmLength();
1896: ensureBLayerDataInBuffer(ddmLength);
1897: ColumnMetaData cm = parseSQLCINRDarray();
1898: adjustLengths(getDdmLength());
1899: return cm;
1900: }
1901:
1902: //--------------------------parse FDOCA objects------------------------
1903:
1904: // SQLDARD : FDOCA EARLY ARRAY
1905: // SQL Descriptor Area Row Description with SQL Communications Area
1906: //
1907: // FORMAT FOR SQLAM <= 6
1908: // SQLCARD; ROW LID 0x64; ELEMENT TAKEN 0(all); REP FACTOR 1
1909: // SQLNUMROW; ROW LID 0x68; ELEMENT TAKEN 0(all); REP FACTOR 1
1910: // SQLDAROW; ROW LID 0x60; ELEMENT TAKEN 0(all); REP FACTOR 0(all)
1911: //
1912: // FORMAT FOR SQLAM >= 7
1913: // SQLCARD; ROW LID 0x64; ELEMENT TAKEN 0(all); REP FACTOR 1
1914: // SQLDHROW; ROW LID 0xE0; ELEMENT TAKEN 0(all); REP FACTOR 1
1915: // SQLNUMROW; ROW LID 0x68; ELEMENT TAKEN 0(all); REP FACTOR 1
1916: // SQLDAROW; ROW LID 0x60; ELEMENT TAKEN 0(all); REP FACTOR 0(all)
1917: NetSqlca parseSQLDARDarray(ColumnMetaData columnMetaData,
1918: boolean skipBytes) throws DisconnectException {
1919: int ddmLength = 0;
1920: if (!ensuredLengthForDecryption_
1921: && longValueForDecryption_ == null) { //if ensuredLength = true, means we already ensured length in decryptData, so don't need to do it again
1922: ddmLength = getDdmLength();
1923: ensureBLayerDataInBuffer(ddmLength);
1924:
1925: }
1926: if (longValueForDecryption_ != null) {
1927: buffer_ = longValueForDecryption_;
1928: pos_ = 0;
1929: count_ = longValueForDecryption_.length;
1930: //dssLength_ = 0;
1931: }
1932:
1933: NetSqlca netSqlca = null;
1934: if (skipBytes) {
1935: mark();
1936: netSqlca = parseSQLCARDrow(null);
1937: skipFastBytes(ddmLength - getFastSkipSQLCARDrowLength());
1938: adjustLengths(getDdmLength());
1939: return netSqlca;
1940: } else {
1941: netSqlca = parseSQLCARDrow(null);
1942: }
1943:
1944: parseSQLDHROW(columnMetaData);
1945:
1946: int columns = parseSQLNUMROW();
1947: if (columns > columnMetaData.columns_) // this will only be true when columnMetaData.columns_ = 0 under deferred prepare
1948: // under deferred prepare the CMD arrays are not allocated until now, no guesses were made
1949: {
1950: columnMetaData.initializeCache(columns);
1951: } else // column count was guessed, don't bother reallocating arrays, just truncate their lengths
1952: {
1953: columnMetaData.columns_ = columns;
1954: }
1955:
1956: // is this correct for 0 SQLNUMROW
1957: // does rest of code expect a null ColumnMetaData object
1958: // or does rest of code expect an non null object
1959: // with columns_ set to 0
1960:
1961: for (int i = 0; i < columnMetaData.columns_; i++) {
1962: parseSQLDAROW(columnMetaData, i);
1963: }
1964:
1965: if (longValueForDecryption_ == null) {
1966: adjustLengths(getDdmLength());
1967: } else {
1968: dssLength_ = 0;
1969: longValueForDecryption_ = null;
1970: }
1971:
1972: return netSqlca;
1973: }
1974:
1975: // SQLRSLRD : FDOCA EARLY ARRAY
1976: // Data Array of a Result Set
1977: //
1978: // FORMAT FOR ALL SQLAM LEVELS
1979: // SQLNUMROW; ROW LID 0x68; ELEMENT TAKEN 0(all); REP FACTOR 1
1980: // SQLRSROW; ROW LID 0x6F; ELEMENT TAKEN 0(all); REP FACTOR 0(all)
1981: //
1982: // SQL Result Set Reply Data (SQLRSLRD) is a byte string that specifies
1983: // information about result sets returned as reply data in the response to
1984: // an EXCSQLSTT command that invokes a stored procedure
1985: int parseSQLRSLRDarray(java.util.ArrayList sectionAL)
1986: throws DisconnectException {
1987: int numOfResultSets = parseSQLNUMROW();
1988: for (int i = 0; i < numOfResultSets; i++) {
1989: parseSQLRSROW((Section) sectionAL.get(i));
1990: }
1991: return numOfResultSets;
1992: }
1993:
1994: // SQLCINRD : FDOCA EARLY ARRAY
1995: // SQL Result Set Column Array Description
1996: //
1997: // FORMAT FOR SQLAM <= 6
1998: // SQLNUMROW; ROW LID 0x68; ELEMENT TAKEN 0(all); REP FACTOR 1
1999: // SQLCIROW; ROW LID 0x6B; ELEMENT TAKEN 0(all); REP FACTOR 0(all)
2000: //
2001: // FORMAT FOR SQLAM >= 7
2002: // SQLDHROW; ROW LID 0xE0; ELEMENT TAKEN 0(all); REP FACTOR 1
2003: // SQLNUMROW; ROW LID 0x68; ELEMENT TAKEN 0(all); REP FACTOR 1
2004: // SQLDAROW; ROW LID 0x60; ELEMENT TAKEN 0(all); REP FACTOR 0(all)
2005: //
2006: // SQL Result Set Column Information Reply Data (SQLCINRD) is a byte string
2007: // that specifies information about columns for a result set returned as
2008: // reply data in the response to an EXCSQLSTT command that invodes a stored
2009: // procedure
2010: ColumnMetaData parseSQLCINRDarray() throws DisconnectException {
2011: ColumnMetaData columnMetaData = ClientDriver.getFactory()
2012: .newColumnMetaData(netAgent_.logWriter_);
2013:
2014: parseSQLDHROW(columnMetaData);
2015:
2016: // possibly change initializeCache to not new up arrays if
2017: // parseSQLNUMROW returns 0
2018: columnMetaData.initializeCache(parseFastSQLNUMROW());
2019:
2020: // is this correct for 0 SQLNUMROW,
2021: // does rest of code expect a null ColumnMetaData object
2022: // or does rest of code expect an non null object
2023: // with columns_ set to 0
2024: for (int i = 0; i < columnMetaData.columns_; i++) {
2025: parseSQLDAROW(columnMetaData, i);
2026: }
2027:
2028: return columnMetaData;
2029: }
2030:
2031: // SQLDAROW : FDOCA EARLY ROW
2032: // SQL Data Area Row Description
2033: //
2034: // FORMAT FOR ALL SQLAM LEVELS
2035: // SQLDAGRP; GROUP LID 0x50; ELEMENT TAKEN 0(all); REP FACTOR 1
2036: private void parseSQLDAROW(ColumnMetaData columnMetaData,
2037: int columnNumber) throws DisconnectException {
2038: parseSQLDAGRP(columnMetaData, columnNumber);
2039: }
2040:
2041: // SQLDHROW : FDOCA EARLY ROW
2042: // SQL Descriptor Header Row Description
2043: //
2044: // FORMAT FOR SQLAM >= 7
2045: // SQLDHGRP; GROUP LID 0xD0; ELEMENT TAKEN 0(all); REP FACTOR 1
2046: private void parseSQLDHROW(ColumnMetaData columnMetaData)
2047: throws DisconnectException {
2048: parseSQLDHGRP(columnMetaData);
2049: }
2050:
2051: // SQLRSROW : FDOCA EARLY ROW
2052: // SQL Row Description for One Result Set Row
2053: //
2054: // FORMAT FOR ALL SQLAM LEVELS
2055: // SQLRSGRP; GROUP LID 0x5F; ELEMENT TAKEN 0(all); REP FACTOR 1
2056: private void parseSQLRSROW(Section section)
2057: throws DisconnectException {
2058: parseSQLRSGRP(section);
2059: }
2060:
2061: // These methods are "private protected", which is not a recognized java privilege,
2062: // but means that these methods are private to this class and to subclasses,
2063: // and should not be used as package-wide friendly methods.
2064:
2065: // SQLDAGRP : EARLY FDOCA GROUP
2066: // SQL Data Area Group Description
2067: //
2068: // FORMAT FOR SQLAM <= 6
2069: // SQLPRECISION; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2070: // SQLSCALE; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2071: // SQLLENGTH; PROTOCOL TYPE I4; ENVLID 0x02; Length Override 4
2072: // SQLTYPE; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2073: // SQLCCSID; PROTOCOL TYPE FB; ENVLID 0x26; Length Override 2
2074: // SQLNAME_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 30
2075: // SQLNAME_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 30
2076: // SQLLABEL_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 30
2077: // SQLLABEL_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 30
2078: // SQLCOMMENTS_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 254
2079: // SQLCOMMENTS_m; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 254
2080: //
2081: // FORMAT FOR SQLAM == 6
2082: // SQLPRECISION; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2083: // SQLSCALE; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2084: // SQLLENGTH; PROTOCOL TYPE I8; ENVLID 0x16; Length Override 8
2085: // SQLTYPE; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2086: // SQLCCSID; PROTOCOL TYPE FB; ENVLID 0x26; Length Override 2
2087: // SQLNAME_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 30
2088: // SQLNAME_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 30
2089: // SQLLABEL_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 30
2090: // SQLLABEL_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 30
2091: // SQLCOMMENTS_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 254
2092: // SQLCOMMENTS_m; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 254
2093: // SQLUDTGRP; PROTOCOL TYPE N-GDA; ENVLID 0x51; Length Override 0
2094: //
2095: // FORMAT FOR SQLAM >= 7
2096: // SQLPRECISION; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2097: // SQLSCALE; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2098: // SQLLENGTH; PROTOCOL TYPE I8; ENVLID 0x16; Length Override 8
2099: // SQLTYPE; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2100: // SQLCCSID; PROTOCOL TYPE FB; ENVLID 0x26; Length Override 2
2101: // SQLDOPTGRP; PROTOCOL TYPE N-GDA; ENVLID 0xD2; Length Override 0
2102: private void parseSQLDAGRP(ColumnMetaData columnMetaData,
2103: int columnNumber) throws DisconnectException {
2104: long columnLength = 0;
2105:
2106: // 2-byte precision
2107: int precision = readFastShort();
2108:
2109: // 2-byte scale
2110: int scale = readFastShort();
2111:
2112: // 8 byte sqllength
2113: columnLength = readFastLong();
2114:
2115: // create a set method after sqlType and ccsid is read
2116: // possibly have it set the nullable
2117: int sqlType = readFastShort();
2118:
2119: // 2-byte sqlccsid
2120: // (NOTE: SQLCCSID is always flown as BIG ENDIAN, not as data!)
2121: // The C-Common Client also does the following:
2122: // 1. Determine which type of code page is to be used for this variable:
2123: // 2. Map the CCSID to the correct codepage:
2124: // 3. "Split" the CCSID to see whether it is for SBCS or MBCS:
2125: int ccsid = readFastUnsignedShort();
2126:
2127: columnMetaData.sqlPrecision_[columnNumber] = precision;
2128: columnMetaData.sqlScale_[columnNumber] = scale;
2129: columnMetaData.sqlLength_[columnNumber] = columnLength;
2130: columnMetaData.sqlType_[columnNumber] = sqlType;
2131: // Set the nullables
2132: columnMetaData.nullable_[columnNumber] = Utils
2133: .isSqlTypeNullable(sqlType);
2134: columnMetaData.sqlCcsid_[columnNumber] = ccsid;
2135: columnMetaData.types_[columnNumber] = Types
2136: .mapDERBYTypeToDriverType(true, sqlType, columnLength,
2137: ccsid); // true means isDescribed
2138: parseSQLDOPTGRP(columnMetaData, columnNumber);
2139: }
2140:
2141: // SQLUDTGRP : EARLY FDOCA GROUP
2142: // SQL User-Defined Data Group Description
2143: //
2144: // FORMAT FOR SQLAM >= 7
2145: // SQLUDTXTYPE; PROTOCOL TYPE I4; ENVLID 0X02; Length Override 4
2146: // SQLUDTRDB; PROTOCOL TYPE VCS; ENVLID 0X32; Length Override 255
2147: // SQLUDTSCHEMA_m; PROTOCOL TYPE VCM; ENVLID 0X3E; Length Override 255
2148: // SQLUDTSCHEMA_s; PROTOCOL TYPE VCS; ENVLID 0X32; Length Override 255
2149: // SQLUDTNAME_m; PROTOCOL TYPE VCM; ENVLID 0X3E; Length Override 255
2150: // SQLUDTNAME_s; PROTOCOL TYPE VCS; ENVLID 0X32; Length Override 255
2151: private void parseSQLUDTGRP(ColumnMetaData columnMetaData,
2152: int columnNumber) throws DisconnectException {
2153: if (readFastUnsignedByte() == CodePoint.NULLDATA) {
2154: return;
2155: }
2156:
2157: }
2158:
2159: // SQLDOPTGRP : EARLY FDOCA GROUP
2160: // SQL Descriptor Optional Group Description
2161: //
2162: // FORMAT FOR SQLAM >= 7
2163: // SQLUNNAMED; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2164: // SQLNAME_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 255
2165: // SQLNAME_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2166: // SQLLABEL_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 255
2167: // SQLLABEL_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2168: // SQLCOMMENTS_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 255
2169: // SQLCOMMENTS_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2170: // SQLUDTGRP; PROTOCOL TYPE N-GDA; ENVLID 0x5B; Length Override 0
2171: // SQLDXGRP; PROTOCOL TYPE N-GDA; ENVLID 0xD4; Length Override 0
2172: private void parseSQLDOPTGRP(ColumnMetaData columnMetaData,
2173: int columnNumber) throws DisconnectException {
2174: if (readFastUnsignedByte() == CodePoint.NULLDATA) {
2175: return;
2176: }
2177:
2178: // SQLUNNAMED; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2179: short sqlunnamed = readFastShort();
2180:
2181: // SQLNAME_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 255
2182: // SQLNAME_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2183: String name = parseFastVCMorVCS();
2184:
2185: // SQLLABEL_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 255
2186: // SQLLABEL_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2187: String label = parseFastVCMorVCS();
2188:
2189: // SQLCOMMENTS_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 255
2190: // SQLCOMMENTS_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2191: String colComments = parseFastVCMorVCS();
2192:
2193: if (columnMetaData.sqlName_ == null) {
2194: columnMetaData.sqlName_ = new String[columnMetaData.columns_];
2195: }
2196: if (columnMetaData.sqlLabel_ == null) {
2197: columnMetaData.sqlLabel_ = new String[columnMetaData.columns_];
2198: }
2199: if (columnMetaData.sqlUnnamed_ == null) {
2200: columnMetaData.sqlUnnamed_ = new short[columnMetaData.columns_];
2201: }
2202: if (columnMetaData.sqlComment_ == null) {
2203: columnMetaData.sqlComment_ = new String[columnMetaData.columns_];
2204: }
2205: columnMetaData.sqlName_[columnNumber] = name;
2206: columnMetaData.sqlLabel_[columnNumber] = label;
2207: columnMetaData.sqlUnnamed_[columnNumber] = sqlunnamed;
2208: columnMetaData.sqlComment_[columnNumber] = colComments;
2209:
2210: // possibly move all the assignments into a single method on the columnMetaData object
2211:
2212: parseSQLUDTGRP(columnMetaData, columnNumber);
2213: parseSQLDXGRP(columnMetaData, columnNumber);
2214: }
2215:
2216: // SQLDXGRP : EARLY FDOCA GROUP
2217: // SQL Descriptor Extended Group Description
2218: //
2219: // FORMAT FOR SQLAM >=7
2220: // SQLXKEYMEM; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2221: // SQLXUPDATEABLE; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2222: // SQLXGENERATED; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2223: // SQLXPARMMODE; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2224: // SQLXRDBNAM; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2225: // SQLXCORNAME_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 255
2226: // SQLXCORNAME_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2227: // SQLXBASENAME_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 255
2228: // SQLXBASENAME_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2229: // SQLXSCHEMA_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 255
2230: // SQLXSCHEMA_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2231: // SQLXNAME_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 255
2232: // SQLXNAME_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2233: private void parseSQLDXGRP(ColumnMetaData columnMetaData, int column)
2234: throws DisconnectException {
2235: if (readFastUnsignedByte() == CodePoint.NULLDATA) {
2236: return;
2237: }
2238:
2239: // SQLXKEYMEM; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2240: short sqlxkeymem = readFastShort();
2241:
2242: // SQLXUPDATEABLE; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2243: short sqlxupdateable = readFastShort();
2244:
2245: // SQLXGENERATED; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2246: short sqlxgenerated = readFastShort();
2247:
2248: // SQLXPARMMODE; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2249: short sqlxparmmode = readFastShort();
2250:
2251: // SQLXRDBNAM; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2252: String sqlxrdbnam = parseFastVCS();
2253:
2254: // SQLXCORNAME_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 255
2255: // SQLXCORNAME_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2256: String sqlxcorname = parseFastVCMorVCS();
2257:
2258: // SQLXBASENAME_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 255
2259: // SQLXBASENAME_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2260: String sqlxbasename = parseFastVCMorVCS();
2261:
2262: // SQLXSCHEMA_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 255
2263: // SQLXSCHEMA_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2264: String sqlxschema = parseFastVCMorVCS();
2265:
2266: // SQLXNAME_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 255
2267: // SQLXNAME_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2268: String sqlxname = parseFastVCMorVCS();
2269:
2270: if (columnMetaData.sqlxKeymem_ == null) {
2271: columnMetaData.sqlxKeymem_ = new short[columnMetaData.columns_];
2272: }
2273: if (columnMetaData.sqlxGenerated_ == null) {
2274: columnMetaData.sqlxGenerated_ = new short[columnMetaData.columns_];
2275: }
2276: if (columnMetaData.sqlxParmmode_ == null) {
2277: columnMetaData.sqlxParmmode_ = new short[columnMetaData.columns_];
2278: }
2279: if (columnMetaData.sqlxCorname_ == null) {
2280: columnMetaData.sqlxCorname_ = new String[columnMetaData.columns_];
2281: }
2282: if (columnMetaData.sqlxName_ == null) {
2283: columnMetaData.sqlxName_ = new String[columnMetaData.columns_];
2284: }
2285: if (columnMetaData.sqlxBasename_ == null) {
2286: columnMetaData.sqlxBasename_ = new String[columnMetaData.columns_];
2287: }
2288: if (columnMetaData.sqlxUpdatable_ == null) {
2289: columnMetaData.sqlxUpdatable_ = new int[columnMetaData.columns_];
2290: }
2291: if (columnMetaData.sqlxSchema_ == null) {
2292: columnMetaData.sqlxSchema_ = new String[columnMetaData.columns_];
2293: }
2294: if (columnMetaData.sqlxRdbnam_ == null) {
2295: columnMetaData.sqlxRdbnam_ = new String[columnMetaData.columns_];
2296: }
2297:
2298: columnMetaData.sqlxKeymem_[column] = sqlxkeymem;
2299: columnMetaData.sqlxGenerated_[column] = sqlxgenerated;
2300: columnMetaData.sqlxParmmode_[column] = sqlxparmmode;
2301: columnMetaData.sqlxCorname_[column] = sqlxcorname;
2302: columnMetaData.sqlxName_[column] = sqlxname;
2303: columnMetaData.sqlxBasename_[column] = sqlxbasename;
2304: columnMetaData.sqlxUpdatable_[column] = sqlxupdateable;
2305: columnMetaData.sqlxSchema_[column] = (sqlxschema == null) ? columnMetaData.sqldSchema_
2306: : sqlxschema;
2307: columnMetaData.sqlxRdbnam_[column] = (sqlxrdbnam == null) ? columnMetaData.sqldRdbnam_
2308: : sqlxrdbnam;
2309: }
2310:
2311: // SQLDHGRP : EARLY FDOCA GROUP
2312: // SQL Descriptor Header Group Description
2313: //
2314: // FORMAT FOR SQLAM >= 7
2315: // SQLDHOLD; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2316: // SQLDRETURN; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2317: // SQLDSCROLL; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2318: // SQLDSENSITIVE; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2319: // SQLDFCODE; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2320: // SQLDKEYTYPE; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2321: // SQLDRDBNAM; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2322: // SQLDSCHEMA_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 255
2323: // SQLDSCHEMA_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2324: private void parseSQLDHGRP(ColumnMetaData columnMetaData)
2325: throws DisconnectException {
2326: if (readFastUnsignedByte() == CodePoint.NULLDATA) {
2327: return;
2328: }
2329:
2330: // SQLDHOLD; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2331: short sqldhold = readFastShort();
2332:
2333: // SQLDRETURN; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2334: short sqldreturn = readFastShort();
2335:
2336: // SQLDSCROLL; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2337: short sqldscroll = readFastShort();
2338:
2339: // SQLDSENSITIVE; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2340: short sqldsensitive = readFastShort();
2341:
2342: // SQLDFCODE; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2343: short sqldfcode = readFastShort();
2344:
2345: // SQLDKEYTYPE; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2346: short sqldkeytype = readFastShort();
2347:
2348: // SQLDRDBNAM; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2349: String sqldrdbnam = parseFastVCS();
2350:
2351: // SQLDSCHEMA_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 255
2352: // SQLDSCHEMA_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2353: String sqldschema = parseFastVCMorVCS();
2354:
2355: columnMetaData.sqldHold_ = sqldhold;
2356: columnMetaData.sqldReturn_ = sqldreturn;
2357: columnMetaData.sqldScroll_ = sqldscroll;
2358: columnMetaData.sqldSensitive_ = sqldsensitive;
2359: columnMetaData.sqldFcode_ = sqldfcode;
2360: columnMetaData.sqldKeytype_ = sqldkeytype;
2361: columnMetaData.sqldRdbnam_ = sqldrdbnam;
2362: columnMetaData.sqldSchema_ = sqldschema;
2363: }
2364:
2365: // SQLRSGRP : EARLY FDOCA GROUP
2366: // SQL Result Set Group Description
2367: //
2368: // FORMAT FOR SQLAM >= 7
2369: // SQLRSLOCATOR; PROTOCOL TYPE RSL; ENVLID 0x14; Length Override 4
2370: // SQLRSNAME_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 255
2371: // SQLRSNAME_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2372: // SQLRSNUMROWS; PROTOCOL TYPE I4; ENVLID 0x02; Length Override 4
2373: private void parseSQLRSGRP(Section section)
2374: throws DisconnectException {
2375:
2376: int rsLocator = readInt();
2377: String rsName = parseVCMorVCS(); // ignore length change bt SQLAM 6 and 7
2378: int rsNumRows = readInt();
2379: // currently rsLocator and rsNumRows are not being used.
2380: section.setCursorName(rsName);
2381: }
2382:
2383: // this is duplicated in parseColumnMetaData, but different
2384: // DAGroup under NETColumnMetaData requires a lot more stuffs including
2385: // precsion, scale and other stuffs
2386: private String parseFastVCMorVCS() throws DisconnectException {
2387: String stringToBeSet = null;
2388:
2389: int vcm_length = readFastUnsignedShort();
2390: if (vcm_length > 0) {
2391: stringToBeSet = readFastString(vcm_length,
2392: netAgent_.targetTypdef_.getCcsidMbcEncoding());
2393: }
2394: int vcs_length = readFastUnsignedShort();
2395: if (vcm_length > 0 && vcs_length > 0) {
2396: agent_
2397: .accumulateChainBreakingReadExceptionAndThrow(new DisconnectException(
2398: agent_,
2399: new ClientMessageId(
2400: SQLState.NET_VCM_VCS_LENGTHS_INVALID)));
2401: } else if (vcs_length > 0) {
2402: stringToBeSet = readFastString(vcs_length,
2403: netAgent_.targetTypdef_.getCcsidSbcEncoding());
2404: }
2405:
2406: return stringToBeSet;
2407: }
2408:
2409: private String parseVCMorVCS() throws DisconnectException {
2410: String stringToBeSet = null;
2411:
2412: int vcm_length = readUnsignedShort();
2413: if (vcm_length > 0) {
2414: stringToBeSet = readString(vcm_length,
2415: netAgent_.targetTypdef_.getCcsidMbcEncoding());
2416: }
2417: int vcs_length = readUnsignedShort();
2418: if (vcm_length > 0 && vcs_length > 0) {
2419: agent_
2420: .accumulateChainBreakingReadExceptionAndThrow(new DisconnectException(
2421: agent_,
2422: new ClientMessageId(
2423: SQLState.NET_VCM_VCS_LENGTHS_INVALID)));
2424: } else if (vcs_length > 0) {
2425: stringToBeSet = readString(vcs_length,
2426: netAgent_.targetTypdef_.getCcsidSbcEncoding());
2427: }
2428:
2429: return stringToBeSet;
2430: }
2431:
2432: //----------------------non-parsing computational helper methods--------------
2433: private int calculateResultSetType(int qryattscr, int qryattsns,
2434: int defaultType) {
2435: // We are passing in defaultType "FOWARD_ONLY", in case desired type
2436: // cannot be obtained,we don't want to set the type to Statement's type,
2437: // but we will set it to the default.
2438:
2439: if (qryattscr == 0xF0) {
2440: return java.sql.ResultSet.TYPE_FORWARD_ONLY;
2441: }
2442:
2443: switch (qryattsns) {
2444: case CodePoint.QRYINS:
2445: return java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE;
2446: default:
2447: return defaultType;
2448: }
2449: }
2450:
2451: private int calculateResultSetConcurrency(int qryattupd,
2452: int defaultConcurrency) {
2453: // QRYATTUPD does come back for forward-only cursors if the desired concurrency cannot be
2454: // obtained, in which case we don't want to set the concurrency to the default, but
2455: // we want to set it to the actual concurrency.
2456: switch (qryattupd) {
2457: case CodePoint.QRYRDO:
2458: return java.sql.ResultSet.CONCUR_READ_ONLY;
2459: case CodePoint.QRYUPD:
2460: return java.sql.ResultSet.CONCUR_UPDATABLE;
2461: default:
2462: return defaultConcurrency;
2463: }
2464: }
2465:
2466: private int calculateResultSetHoldability(int sqlcsrhld) {
2467: if (sqlcsrhld == 0xF0) {
2468: return JDBC30Translation.CLOSE_CURSORS_AT_COMMIT;
2469: } else {
2470: return JDBC30Translation.HOLD_CURSORS_OVER_COMMIT;
2471: }
2472: }
2473:
2474: private int parseSQLDTAGRPdataLabelsAndUpdateColumn(
2475: NetCursor cursor, int columnIndex, int tripletLength)
2476: throws DisconnectException {
2477: int numColumns = (tripletLength - 3) / 3;
2478: for (int i = columnIndex; i < columnIndex + numColumns; i++) {
2479: cursor.qrydscTypdef_.updateColumn(cursor, i,
2480: readFastUnsignedByte(), readFastUnsignedShort());
2481: }
2482: return numColumns;
2483: }
2484:
2485: private String parseSQLSTT() throws DisconnectException {
2486: parseLengthAndMatchCodePoint(CodePoint.SQLSTT);
2487: return parseSQLSTTGRP();
2488: }
2489:
2490: private String parseSQLSTTGRP() throws DisconnectException {
2491: int mixedNullInd = readUnsignedByte();
2492: int singleNullInd = 0;
2493: String sqlsttString = null;
2494: int stringLength = 0;
2495:
2496: if (mixedNullInd == CodePoint.NULLDATA) {
2497: singleNullInd = readUnsignedByte();
2498: if (singleNullInd == CodePoint.NULLDATA) {
2499: // throw DTAMCHRM
2500: doDtamchrmSemantics();
2501: }
2502: // read 4-byte length
2503: stringLength = readInt();
2504: // read sqlstt string
2505: sqlsttString = readString(stringLength,
2506: netAgent_.targetTypdef_.getCcsidSbcEncoding());
2507: } else {
2508: // read 4-byte length
2509: stringLength = readInt();
2510: // read sqlstt string
2511: sqlsttString = readString(stringLength,
2512: netAgent_.targetTypdef_.getCcsidMbcEncoding());
2513: // read null indicator
2514: singleNullInd = readUnsignedByte();
2515: }
2516: return sqlsttString;
2517: }
2518:
2519: public void readSetSpecialRegister(
2520: StatementCallbackInterface statement)
2521: throws DisconnectException {
2522: startSameIdChainParse();
2523: parseEXCSQLSETreply(statement);
2524: endOfSameIdChainData();
2525: }
2526: }
|