KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > client > net > NetStatementReply


1 /*
2
3    Derby - Class org.apache.derby.client.net.NetStatementReply
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20 */

21
22 package org.apache.derby.client.net;
23
24 import org.apache.derby.client.am.ColumnMetaData;
25 import org.apache.derby.client.am.DisconnectException;
26 import org.apache.derby.client.am.PreparedStatementCallbackInterface;
27 import org.apache.derby.client.am.ResultSetCallbackInterface;
28 import org.apache.derby.client.am.Section;
29 import org.apache.derby.client.am.SqlState;
30 import org.apache.derby.client.am.SqlException;
31 import org.apache.derby.client.am.Statement;
32 import org.apache.derby.client.am.StatementCallbackInterface;
33 import org.apache.derby.client.am.Types;
34 import org.apache.derby.client.am.Utils;
35 import org.apache.derby.jdbc.ClientDriver;
36 import org.apache.derby.client.am.ClientJDBCObjectFactory;
37 import org.apache.derby.shared.common.i18n.MessageUtil;
38 import org.apache.derby.shared.common.reference.JDBC30Translation;
39 import org.apache.derby.client.am.ClientMessageId;
40 import org.apache.derby.shared.common.reference.SQLState;
41 import org.apache.derby.shared.common.reference.MessageId;
42
43 public class NetStatementReply extends NetPackageReply implements StatementReplyInterface {
44     NetStatementReply(NetAgent netAgent, int bufferSize) {
45         super(netAgent, bufferSize);
46     }
47
48     //----------------------------- entry points ---------------------------------
49

50     public void readPrepareDescribeOutput(StatementCallbackInterface statement) throws DisconnectException {
51         startSameIdChainParse();
52         parsePRPSQLSTTreply(statement);
53         endOfSameIdChainData();
54     }
55
56     public void readExecuteImmediate(StatementCallbackInterface statement) throws DisconnectException {
57         startSameIdChainParse();
58         parseEXCSQLIMMreply(statement);
59         endOfSameIdChainData();
60     }
61
62     public void readOpenQuery(StatementCallbackInterface statement) throws DisconnectException {
63         startSameIdChainParse();
64         parseOPNQRYreply(statement);
65         endOfSameIdChainData();
66     }
67
68     public void readExecute(PreparedStatementCallbackInterface preparedStatement) throws DisconnectException {
69         startSameIdChainParse();
70         parseEXCSQLSTTreply(preparedStatement);
71         endOfSameIdChainData();
72     }
73
74     public void readPrepare(StatementCallbackInterface statement) throws DisconnectException {
75         startSameIdChainParse();
76         parsePRPSQLSTTreply(statement);
77         endOfSameIdChainData();
78     }
79
80     public void readDescribeInput(PreparedStatementCallbackInterface preparedStatement) throws DisconnectException {
81         if (longBufferForDecryption_ != null) {
82             buffer_ = longBufferForDecryption_;
83             pos_ = longPosForDecryption_;
84             count_ = longCountForDecryption_;
85             if (longBufferForDecryption_ != null && count_ > longBufferForDecryption_.length) {
86                 count_ = longBufferForDecryption_.length;
87             }
88             dssLength_ = 0;
89             longBufferForDecryption_ = null;
90         }
91
92         startSameIdChainParse();
93         parseDSCSQLSTTreply(preparedStatement, 1); // anything other than 0 for input
94
endOfSameIdChainData();
95     }
96
97     public void readDescribeOutput(PreparedStatementCallbackInterface preparedStatement) throws DisconnectException {
98         startSameIdChainParse();
99         parseDSCSQLSTTreply(preparedStatement, 0); // 0 for output
100
endOfSameIdChainData();
101     }
102
103     public void readExecuteCall(StatementCallbackInterface statement) throws DisconnectException {
104         startSameIdChainParse();
105         parseEXCSQLSTTreply(statement);
106         endOfSameIdChainData();
107     }
108
109
110     //----------------------helper methods----------------------------------------
111

112     //------------------parse reply for specific command--------------------------
113

114     // These methods are "private protected", which is not a recognized java privilege,
115
// but means that these methods are private to this class and to subclasses,
116
// and should not be used as package-wide friendly methods.
117

118     private void parsePRPSQLSTTreply(StatementCallbackInterface statement) throws DisconnectException {
119         int peekCP = parseTypdefsOrMgrlvlovrs();
120
121         if (peekCP == CodePoint.SQLDARD) {
122             // the sqlcagrp is most likely null for insert/update/deletes. if it is null, then we can
123
// peek ahead for the column number which most likely will be 0. if it is 0, then we will
124
// not new up a ColumnMetaData, and we can skip the rest of the bytes in sqldard.
125
// if sqlcargrp is not null, (most likely for select's) then we will not peek ahead for the
126
// column number since it will never be 0 in a select case.
127
ColumnMetaData columnMetaData = null;
128             NetSqlca netSqlca = null;
129             boolean nullSqlca = peekForNullSqlcagrp();
130             if (nullSqlca && peekNumOfColumns() == 0) {
131                 netSqlca = parseSQLDARD(columnMetaData, true); // true means to skip the rest of SQLDARD bytes
132
} else {
133                 columnMetaData = ClientDriver.getFactory().newColumnMetaData(netAgent_.logWriter_);
134                 netSqlca = parseSQLDARD(columnMetaData, false); // false means do not skip SQLDARD bytes.
135
}
136
137             statement.completePrepareDescribeOutput(columnMetaData,
138                     netSqlca);
139         } else if (peekCP == CodePoint.SQLCARD) {
140             NetSqlca netSqlca = parseSQLCARD(null);
141             statement.completePrepare(netSqlca);
142         } else {
143             parsePrepareError(statement);
144         }
145
146     }
147
148     // Parse the reply for the Describe SQL Statement Command.
149
// This method handles the parsing of all command replies and reply data
150
// for the dscsqlstt command.
151
private void parseDSCSQLSTTreply(PreparedStatementCallbackInterface ps,
152                                      int metaDataType) // 0 is output, else input
153
throws DisconnectException {
154         int peekCP = parseTypdefsOrMgrlvlovrs();
155
156         if (peekCP == CodePoint.SQLDARD) {
157             ColumnMetaData columnMetaData = null;
158
159             if (columnMetaData == null) {
160                 columnMetaData = ClientDriver.getFactory().newColumnMetaData(netAgent_.logWriter_);
161             }
162
163             NetSqlca netSqlca = parseSQLDARD(columnMetaData, false); // false means do not skip SQLDARD bytes
164
if (columnMetaData.columns_ == 0) {
165                 columnMetaData = null;
166             }
167
168             if (metaDataType == 0) // DESCRIBE OUTPUT
169
{
170                 ps.completeDescribeOutput(columnMetaData, netSqlca);
171             } else {
172                 ps.completeDescribeInput(columnMetaData, netSqlca);
173             }
174         } else if (peekCP == CodePoint.SQLCARD) {
175             NetSqlca netSqlca = parseSQLCARD(null);
176             if (metaDataType == 0) // DESCRIBE OUTPUT
177
{
178                 ps.completeDescribeOutput(null, netSqlca);
179             } else {
180                 ps.completeDescribeInput(null, netSqlca);
181             }
182         } else {
183             parseDescribeError(ps);
184         }
185
186     }
187
188     // Parse the reply for the Execute Immediate SQL Statement Command.
189
// This method handles the parsing of all command replies and reply data
190
// for the excsqlimm command.
191
private void parseEXCSQLIMMreply(StatementCallbackInterface statement) throws DisconnectException {
192         int peekCP = parseTypdefsOrMgrlvlovrs();
193
194         if (peekCP == CodePoint.RDBUPDRM) {
195             parseRDBUPDRM();
196             peekCP = parseTypdefsOrMgrlvlovrs();
197         }
198
199         switch (peekCP) {
200         case CodePoint.ENDUOWRM:
201             parseENDUOWRM(statement.getConnectionCallbackInterface());
202             parseTypdefsOrMgrlvlovrs();
203         case CodePoint.SQLCARD:
204             NetSqlca netSqlca = parseSQLCARD(null);
205
206
207             statement.completeExecuteImmediate(netSqlca);
208             break;
209         default:
210             parseExecuteImmediateError(statement);
211             break;
212         }
213
214     }
215
216     // Parse the reply for the Open Query Command.
217
// This method handles the parsing of all command replies and reply data for the opnqry command.
218
// will be replaced by parseOPNQRYreply (see parseOPNQRYreplyProto)
219
private void parseOPNQRYreply(StatementCallbackInterface statementI) throws DisconnectException {
220         int peekCP = peekCodePoint();
221
222         if (peekCP == CodePoint.OPNQRYRM) {
223             parseOpenQuery(statementI);
224             peekCP = peekCodePoint();
225             if (peekCP == CodePoint.RDBUPDRM) {
226                 parseRDBUPDRM();
227                 peekCP = peekCodePoint();
228             }
229         } else if (peekCP == CodePoint.RDBUPDRM) {
230             parseRDBUPDRM();
231             parseOpenQuery(statementI);
232             peekCP = peekCodePoint();
233         } else if (peekCP == CodePoint.OPNQFLRM) {
234             parseOpenQueryFailure(statementI);
235             peekCP = peekCodePoint();
236         } else {
237             parseOpenQueryError(statementI);
238             peekCP = peekCodePoint();
239         }
240
241     }
242
243     // Called by NETSetClientPiggybackCommand.read()
244
private void parseEXCSQLSETreply(StatementCallbackInterface statement) throws DisconnectException {
245         int peekCP = parseTypdefsOrMgrlvlovrs();
246
247         if (peekCP == CodePoint.RDBUPDRM) {
248             parseRDBUPDRM();
249             parseTypdefsOrMgrlvlovrs();
250         } else if (peekCP == CodePoint.ENDUOWRM) {
251             parseENDUOWRM(statement.getConnectionCallbackInterface());
252             parseTypdefsOrMgrlvlovrs();
253         }
254
255         if (peekCP == CodePoint.SQLCARD) {
256             NetSqlca netSqlca = parseSQLCARD(null);
257             statement.completeExecuteSetStatement(netSqlca);
258         } else {
259             parseExecuteSetStatementError(statement);
260         }
261
262     }
263
264     // Parse the reply for the Execute SQL Statement Command.
265
// This method handles the parsing of all command replies and reply data
266
// for the excsqlstt command.
267
// Also called by CallableStatement.readExecuteCall()
268
private void parseEXCSQLSTTreply(StatementCallbackInterface statementI) throws DisconnectException {
269         // first handle the transaction component, which consists of one or more
270
// reply messages indicating the transaction state.
271
// These are ENDUOWRM, CMMRQSRM, or RDBUPDRM. If RDBUPDRM is returned,
272
// it may be followed by ENDUOWRM or CMMRQSRM
273
int peekCP = peekCodePoint();
274         if (peekCP == CodePoint.RDBUPDRM) {
275             parseRDBUPDRM();
276             peekCP = peekCodePoint();
277         }
278
279         if (peekCP == CodePoint.ENDUOWRM) {
280             parseENDUOWRM(statementI.getConnectionCallbackInterface());
281             peekCP = peekCodePoint();
282         }
283
284         // Check for a RSLSETRM, this is first rm of the result set summary component
285
// which would be returned if a stored procedure was called which returned result sets.
286
if (peekCP == CodePoint.RSLSETRM) {
287             parseResultSetProcedure(statementI);
288             peekCP = peekCodePoint();
289             if (peekCP == CodePoint.RDBUPDRM) {
290                 parseRDBUPDRM();
291             }
292             return;
293         }
294
295         // check for a possible TYPDEFNAM or TYPDEFOVR which may be present
296
// before the SQLCARD or SQLDTARD.
297
peekCP = parseTypdefsOrMgrlvlovrs();
298
299         // an SQLCARD may be retunred if there was no output data, result sets or parameters,
300
// or in the case of an error.
301
if (peekCP == CodePoint.SQLCARD) {
302             NetSqlca netSqlca = parseSQLCARD(null);
303
304             statementI.completeExecute(netSqlca);
305         } else if (peekCP == CodePoint.SQLDTARD) {
306             // in the case of singleton select or if a stored procedure was called which had
307
// parameters but no result sets, an SQLSTARD may be returned
308
// keep the PreparedStatementCallbackInterface, since only preparedstatement and callablestatement
309
// has parameters or singleton select which translates to sqldtard.
310
NetSqldta netSqldta = null;
311             boolean useCachedSingletonRowData = false;
312             if (((Statement) statementI).cachedSingletonRowData_ == null) {
313                 netSqldta = new NetSqldta(netAgent_);
314             } else {
315                 netSqldta = (NetSqldta) ((Statement) statementI).cachedSingletonRowData_;
316                 netSqldta.resetDataBuffer();
317                 netSqldta.extdtaData_.clear();
318                 useCachedSingletonRowData = true;
319             }
320             NetSqlca netSqlca =
321                     parseSQLDTARD(netSqldta);
322
323             // there may be externalized LOB data which also gets returned.
324
peekCP = peekCodePoint();
325             while (peekCP == CodePoint.EXTDTA) {
326                 copyEXTDTA(netSqldta);
327                 peekCP = peekCodePoint();
328             }
329             statementI.completeExecuteCall(netSqlca, netSqldta);
330         } else {
331             // if here, then assume an error reply message was returned.
332
parseExecuteError(statementI);
333         }
334
335     }
336
337     protected void parseResultSetProcedure(StatementCallbackInterface statementI) throws DisconnectException {
338         // when a stored procedure is called which returns result sets,
339
// the next thing to be returned after the optional transaction component
340
// is the summary component.
341
//
342
// Parse the Result Set Summary Component which consists of a
343
// Result Set Reply Message, SQLCARD or SQLDTARD, and an SQL Result Set
344
// Reply data object. Also check for possible TYPDEF overrides before the
345
// OBJDSSs.
346
// This method returns an ArrayList of generated sections which contain the
347
// package and section information for the result sets which were opened on the
348
// server.
349

350         // the result set summary component consists of a result set reply message.
351
java.util.ArrayList JavaDoc sectionAL = parseRSLSETRM();
352
353         // following the RSLSETRM is an SQLCARD or an SQLDTARD. check for a
354
// TYPDEFNAM or TYPDEFOVR before looking for these objects.
355
int peekCP = parseTypdefsOrMgrlvlovrs();
356
357         // The SQLCARD and the SQLDTARD are mutually exclusive.
358
// The SQLDTARD is returned if the stored procedure had parameters.
359
// (Note: the SQLDTARD contains an sqlca also. this is the sqlca for the
360
// stored procedure call.
361
NetSqldta netSqldta = null;
362         NetSqlca netSqlca = null;
363         if (peekCP == CodePoint.SQLCARD) {
364             netSqlca = parseSQLCARD(null);
365         } else {
366             // keep the PreparedStatementCallbackInterface, since only preparedstatement and callablestatement
367
// has parameters or singleton select which translates to sqldtard.
368
netSqldta = new NetSqldta(netAgent_);
369             netSqlca = parseSQLDTARD(netSqldta);
370         }
371
372         // check for a possible TYPDEFNAM or TYPDEFOVR
373
// before the SQL Result Set Reply Data object
374
peekCP = parseTypdefsOrMgrlvlovrs();
375
376         int numberOfResultSets = parseSQLRSLRD(sectionAL);
377
378         // The result set summary component parsed above indicated how many result sets were opened
379
// by the stored pocedure call. It contained section information for
380
// each of these result sets. Loop through the section array and
381
// parse the result set component for each of the retunred result sets.
382
NetResultSet[] resultSets = new NetResultSet[numberOfResultSets];
383         for (int i = 0; i < numberOfResultSets; i++) {
384             // parse the result set component of the stored procedure reply.
385
NetResultSet netResultSet = parseResultSetCursor(statementI, (Section) sectionAL.get(i));
386             resultSets[i] = netResultSet;
387         }
388
389         // LOBs may have been returned for one of the stored procedure parameters so
390
// check for any externalized data.
391
peekCP = peekCodePoint();
392         while (peekCP == CodePoint.EXTDTA) {
393             copyEXTDTA(netSqldta);
394             peekCP = peekCodePoint();
395         }
396         statementI.completeExecuteCall(netSqlca, netSqldta, resultSets);
397     }
398
399     // Parse the Result Set component of the reply for a stored procedure
400
// call which returns result sets.
401
// The Result Set component consists of an Open Query Reply Message
402
// followed by an optional SQLCARD, followed by an optional
403
// SQL Column Information Reply data object, followed by a Query Descriptor.
404
// There may also be Query Data or an End of Query Reply Message.
405
protected NetResultSet parseResultSetCursor(StatementCallbackInterface statementI,
406                                                 Section section) throws DisconnectException {
407         // The first item returne is an OPNQRYRM.
408
NetResultSet netResultSet = parseOPNQRYRM(statementI, false);
409
410         // The next to be returned is an OBJDSS so check for any TYPDEF overrides.
411
int peekCP = parseTypdefsOrMgrlvlovrs();
412
413         // An SQLCARD may be returned if there were any warnings on the OPEN.
414
NetSqlca netSqlca = null;
415         if (peekCP == CodePoint.SQLCARD) {
416             netSqlca = parseSQLCARD(null);
417             peekCP = parseTypdefsOrMgrlvlovrs();
418         }
419
420         // the SQLCINRD contains SQLDA like information for the result set.
421
ColumnMetaData resultSetMetaData = null;
422         if (peekCP == CodePoint.SQLCINRD) {
423             resultSetMetaData = parseSQLCINRD();
424             peekCP = parseTypdefsOrMgrlvlovrs();
425         }
426
427         // A Query Descriptor must be present.
428
// We cannot cache the cursor if result set is returned from a stored procedure, so
429
// there is no cached cursor to use here.
430
parseQRYDSC(netResultSet.netCursor_);
431         peekCP = peekCodePoint();
432         statementI.completeExecuteCallOpenQuery(netSqlca, netResultSet, resultSetMetaData, section);
433
434         // Depending on the blocking rules, QRYDTA may have been returned on the open.
435
while (peekCP == CodePoint.QRYDTA) {
436             parseQRYDTA(netResultSet);
437             peekCP = peekCodePoint();
438         }
439
440         // Under some circumstances, the server may have closed the cursor.
441
// This will be indicated by an ENDQRYRM.
442
if (peekCP == CodePoint.ENDQRYRM) {
443             parseEndQuery((ResultSetCallbackInterface) netResultSet);
444         }
445
446         return netResultSet;
447     }
448
449     protected void parseOpenQuery(StatementCallbackInterface statementI) throws DisconnectException {
450         NetResultSet netResultSet = parseOPNQRYRM(statementI, true);
451
452         NetSqlca sqlca = null;
453         int peekCP = peekCodePoint();
454         if (peekCP != CodePoint.QRYDSC) {
455
456             peekCP = parseTypdefsOrMgrlvlovrs();
457
458             if (peekCP == CodePoint.SQLDARD) {
459                 ColumnMetaData columnMetaData = ClientDriver.getFactory().newColumnMetaData(netAgent_.logWriter_);
460                 NetSqlca netSqlca = parseSQLDARD(columnMetaData, false); // false means do not skip SQLDARD bytes
461

462                 //For java stored procedure, we got the resultSetMetaData from server,
463
//Do we need to save the resultSetMetaData and propagate netSqlca?
464
//The following statement are doing the both, but it do more than
465
//we want. It also mark the completion of Prepare statement.
466
//
467
// this will override the same call made from parsePrepareDescribe
468
// this will not work, this is not the DA for the stored proc params
469
statementI.completePrepareDescribeOutput(columnMetaData, netSqlca);
470                 peekCP = parseTypdefsOrMgrlvlovrs();
471             }
472             // check if the DARD is mutually exclusive with CARD, if so, then the following if should be an elese
473

474             if (peekCP == CodePoint.SQLCARD) {
475                 sqlca = parseSQLCARD(null);
476                 peekCP = parseTypdefsOrMgrlvlovrs();
477             }
478         }
479         parseQRYDSC(netResultSet.netCursor_);
480
481         peekCP = peekCodePoint();
482         while (peekCP == CodePoint.QRYDTA) {
483             parseQRYDTA(netResultSet);
484             peekCP = peekCodePoint();
485         }
486
487         if (peekCP == CodePoint.SQLCARD) {
488             NetSqlca netSqlca = parseSQLCARD(null);
489             statementI.completeSqlca(netSqlca);
490             peekCP = peekCodePoint();
491         }
492
493         if (peekCP == CodePoint.ENDQRYRM) {
494             parseEndQuery(netResultSet);
495         }
496
497         statementI.completeOpenQuery(sqlca, netResultSet);
498     }
499
500     protected void parseEndQuery(ResultSetCallbackInterface resultSetI) throws DisconnectException {
501         parseENDQRYRM(resultSetI);
502         parseTypdefsOrMgrlvlovrs();
503         NetSqlca netSqlca = parseSQLCARD(null);
504         resultSetI.earlyCloseComplete(netSqlca);
505     }
506
507     void parseOpenQueryFailure(StatementCallbackInterface statementI) throws DisconnectException {
508         parseOPNQFLRM(statementI);
509         parseTypdefsOrMgrlvlovrs();
510         NetSqlca netSqlca = parseSQLCARD(null);
511         statementI.completeOpenQuery(netSqlca, null);
512     }
513
514     void parsePrepareError(StatementCallbackInterface statement) throws DisconnectException {
515         int peekCP = peekCodePoint();
516         switch (peekCP) {
517         case CodePoint.ABNUOWRM:
518             {
519                 //passing the StatementCallbackInterface implementation will
520
//help in retrieving the the UnitOfWorkListener that needs to
521
//be rolled back
522
NetSqlca sqlca = parseAbnormalEndUow(statement);
523                 statement.completeSqlca(sqlca);
524                 break;
525             }
526         case CodePoint.CMDCHKRM:
527             parseCMDCHKRM();
528             break;
529         case CodePoint.DTAMCHRM:
530             parseDTAMCHRM();
531             break;
532         case CodePoint.OBJNSPRM:
533             parseOBJNSPRM();
534             break;
535         case CodePoint.RDBNACRM:
536             parseRDBNACRM();
537             break;
538         case CodePoint.SQLERRRM:
539             {
540                 NetSqlca sqlca = parseSqlErrorCondition();
541                 statement.completeSqlca(sqlca);
542                 break;
543             }
544         default:
545             parseCommonError(peekCP);
546         }
547     }
548
549     void parseExecuteImmediateError(StatementCallbackInterface statement) throws DisconnectException {
550         int peekCP = peekCodePoint();
551         switch (peekCP) {
552         case CodePoint.ABNUOWRM:
553             {
554                 //passing the StatementCallbackInterface implementation will
555
//help in retrieving the the UnitOfWorkListener that needs to
556
//be rolled back
557
NetSqlca sqlca = parseAbnormalEndUow(statement);
558                 statement.completeSqlca(sqlca);
559                 break;
560             }
561         case CodePoint.CMDCHKRM:
562             parseCMDCHKRM();
563             break;
564         case CodePoint.DTAMCHRM:
565             parseDTAMCHRM();
566             break;
567         case CodePoint.OBJNSPRM:
568             parseOBJNSPRM();
569             break;
570         case CodePoint.RDBNACRM:
571             parseRDBNACRM();
572             break;
573         case CodePoint.SQLERRRM:
574             {
575                 NetSqlca sqlca = parseSqlErrorCondition();
576                 statement.completeSqlca(sqlca);
577                 break;
578             }
579         default:
580             parseCommonError(peekCP);
581             break;
582         }
583     }
584
585
586     void parseDescribeError(StatementCallbackInterface statement) throws DisconnectException {
587         int peekCP = peekCodePoint();
588         switch (peekCP) {
589         case CodePoint.ABNUOWRM:
590             {
591                 //passing the StatementCallbackInterface implementation will
592
//help in retrieving the the UnitOfWorkListener that needs to
593
//be rolled back
594
NetSqlca sqlca = parseAbnormalEndUow(statement);
595                 statement.completeSqlca(sqlca);
596                 break;
597             }
598         case CodePoint.CMDCHKRM:
599             parseCMDCHKRM();
600             break;
601         case CodePoint.RDBNACRM:
602             parseRDBNACRM();
603             break;
604         case CodePoint.SQLERRRM:
605             {
606                 NetSqlca sqlca = parseSqlErrorCondition();
607                 statement.completeSqlca(sqlca);
608                 break;
609             }
610         default:
611             parseCommonError(peekCP);
612         }
613     }
614
615
616     void parseOpenQueryError(StatementCallbackInterface statementI) throws DisconnectException {
617         int peekCP = peekCodePoint();
618         switch (peekCP) {
619         case CodePoint.ABNUOWRM:
620             {
621                 //passing the StatementCallbackInterface implementation will
622
//help in retrieving the the UnitOfWorkListener that needs to
623
//be rolled back
624
NetSqlca sqlca = parseAbnormalEndUow(statementI);
625                 statementI.completeSqlca(sqlca);
626                 break;
627             }
628         case CodePoint.CMDCHKRM:
629             parseCMDCHKRM();
630             break;
631         case CodePoint.DTAMCHRM:
632             parseDTAMCHRM();
633             break;
634         case CodePoint.OBJNSPRM:
635             parseOBJNSPRM();
636             break;
637         case CodePoint.QRYPOPRM:
638             parseQRYPOPRM();
639             break;
640         case CodePoint.RDBNACRM:
641             parseRDBNACRM();
642             break;
643         default:
644             parseCommonError(peekCP);
645         }
646     }
647
648     void parseExecuteError(StatementCallbackInterface statementI) throws DisconnectException {
649         int peekCP = peekCodePoint();
650         switch (peekCP) {
651         case CodePoint.ABNUOWRM:
652             {
653                 //passing the StatementCallbackInterface implementation will
654
//help in retrieving the the UnitOfWorkListener that needs to
655
//be rolled back
656
NetSqlca sqlca = parseAbnormalEndUow(statementI);
657                 statementI.completeSqlca(sqlca);
658                 break;
659             }
660         case CodePoint.CMDCHKRM:
661             parseCMDCHKRM();
662             break;
663         case CodePoint.DTAMCHRM:
664             parseDTAMCHRM();
665             break;
666         case CodePoint.OBJNSPRM:
667             parseOBJNSPRM();
668             break;
669         case CodePoint.RDBNACRM:
670             parseRDBNACRM();
671             break;
672         case CodePoint.SQLERRRM:
673             {
674                 NetSqlca sqlca = parseSqlErrorCondition();
675                 statementI.completeSqlca(sqlca);
676                 break;
677             }
678         default:
679             parseCommonError(peekCP);
680             break;
681         }
682     }
683
684     void parseExecuteSetStatementError(StatementCallbackInterface statement) throws DisconnectException {
685         int peekCP = peekCodePoint();
686         switch (peekCP) {
687         case CodePoint.ABNUOWRM:
688             {
689                 //passing the StatementCallbackInterface implementation will
690
//help in retrieving the the UnitOfWorkListener that needs to
691
//be rolled back
692
NetSqlca sqlca = parseAbnormalEndUow(statement);
693                 statement.completeSqlca(sqlca);
694                 break;
695             }
696         case CodePoint.CMDCHKRM:
697             parseCMDCHKRM();
698             break;
699         case CodePoint.DTAMCHRM:
700             parseDTAMCHRM();
701             break;
702         case CodePoint.OBJNSPRM:
703             parseOBJNSPRM();
704             break;
705         case CodePoint.RDBNACRM:
706             parseRDBNACRM();
707             break;
708         case CodePoint.SQLERRRM:
709             {
710                 NetSqlca sqlca = parseSqlErrorCondition();
711                 statement.completeSqlca(sqlca);
712                 break;
713             }
714         default:
715             parseCommonError(peekCP);
716             break;
717         }
718     }
719
720
721     //-----------------------------parse DDM Reply Messages-----------------------
722

723     /**
724      * Open Query Complete Reply Message indicates to the requester
725      * that an OPNQRY or EXCSQLSTT command completed normally and that
726      * the query process has been initiated. It also indicates the
727      * type of query protocol and cursor used for the query.
728      * <p>
729      * When an EXCSQLSTT contains an SQL statement that invokes a
730      * stored procedure, and the procedure completes, an OPNQRYRM is
731      * returned for each answer set.
732      *
733      * @param statementI statement callback interface
734      * @param isOPNQRYreply If true, parse a reply to an OPNQRY
735      * command. Otherwise, parse a reply to an EXCSQLSTT command.
736      * @return a <code>NetResultSet</code> value
737      * @exception DisconnectException
738      */

739     protected NetResultSet parseOPNQRYRM(StatementCallbackInterface statementI,
740                                          boolean isOPNQRYreply)
741         throws DisconnectException
742     {
743         // these need to be initialized to the correct default values.
744
int svrcod = CodePoint.SVRCOD_INFO;
745         boolean svrcodReceived = false;
746         int qryprctyp = 0;
747         boolean qryprctypReceived = false;
748         int sqlcsrhld = 0xF0; // 0xF0 is false (default), 0xF1 is true.
749
boolean sqlcsrhldReceived = false;
750         int qryattscr = 0xF0; // 0xF0 is false (default), 0xF1 is true.
751
boolean qryattscrReceived = false;
752         int qryattsns = CodePoint.QRYUNK;
753         boolean qryattsnsReceived = false;
754         int qryattupd = CodePoint.QRYUNK;
755         boolean qryattupdReceived = false;
756         long qryinsid = 0;
757         boolean qryinsidReceived = false;
758
759
760         int qryattset = 0xF0; // 0xF0 is false (default), 0xF1 is true.
761
boolean qryattsetReceived = false;
762
763         parseLengthAndMatchCodePoint(CodePoint.OPNQRYRM);
764         //pushLengthOnCollectionStack();
765
int ddmLength = getDdmLength();
766         ensureBLayerDataInBuffer(ddmLength);
767         int peekCP = peekCodePoint();
768         int length = 0;
769
770         //while (peekCP != Reply.END_OF_COLLECTION) {
771
while (ddmLength > 0) {
772
773             boolean foundInPass = false;
774
775             if (peekCP == CodePoint.SVRCOD) {
776                 foundInPass = true;
777                 svrcodReceived = checkAndGetReceivedFlag(svrcodReceived);
778                 length = peekedLength_;
779                 svrcod = parseFastSVRCOD(CodePoint.SVRCOD_INFO, CodePoint.SVRCOD_SESDMG);
780                 ddmLength = adjustDdmLength(ddmLength, length);
781                 peekCP = peekCodePoint();
782             }
783
784             if (peekCP == CodePoint.QRYPRCTYP) {
785                 foundInPass = true;
786                 qryprctypReceived = checkAndGetReceivedFlag(qryprctypReceived);
787                 length = peekedLength_;
788                 qryprctyp = parseFastQRYPRCTYP();
789                 ddmLength = adjustDdmLength(ddmLength, length);
790                 peekCP = peekCodePoint();
791             }
792
793             if (peekCP == CodePoint.SQLCSRHLD) {
794                 // Indicates whether the requester specified the HOLD option.
795
// When specified, the cursor is not closed upon execution of a commit operation.
796
foundInPass = true;
797                 sqlcsrhldReceived = checkAndGetReceivedFlag(sqlcsrhldReceived);
798                 length = peekedLength_;
799                 sqlcsrhld = parseFastSQLCSRHLD();
800                 ddmLength = adjustDdmLength(ddmLength, length);
801                 peekCP = peekCodePoint();
802             }
803
804             if (peekCP == CodePoint.QRYATTSCR) {
805                 foundInPass = true;
806                 qryattscrReceived = checkAndGetReceivedFlag(qryattscrReceived);
807                 length = peekedLength_;
808                 qryattscr = parseFastQRYATTSCR();
809                 ddmLength = adjustDdmLength(ddmLength, length);
810                 peekCP = peekCodePoint();
811             }
812
813             if (peekCP == CodePoint.QRYATTSNS) {
814                 foundInPass = true;
815                 qryattsnsReceived = checkAndGetReceivedFlag(qryattsnsReceived);
816                 length = peekedLength_;
817                 qryattsns = parseFastQRYATTSNS();
818                 ddmLength = adjustDdmLength(ddmLength, length);
819                 peekCP = peekCodePoint();
820             }
821
822             if (peekCP == CodePoint.QRYATTUPD) {
823                 foundInPass = true;
824                 qryattupdReceived = checkAndGetReceivedFlag(qryattupdReceived);
825                 length = peekedLength_;
826                 qryattupd = parseFastQRYATTUPD();
827                 ddmLength = adjustDdmLength(ddmLength, length);
828                 peekCP = peekCodePoint();
829             }
830
831             if (peekCP == CodePoint.QRYINSID) {
832                 foundInPass = true;
833                 qryinsidReceived = checkAndGetReceivedFlag(qryinsidReceived);
834                 length = peekedLength_;
835                 qryinsid = parseFastQRYINSID();
836                 ddmLength = adjustDdmLength(ddmLength, length);
837                 peekCP = peekCodePoint();
838             }
839
840             if (peekCP == CodePoint.QRYATTSET) {
841                 foundInPass = true;
842                 qryattsetReceived = checkAndGetReceivedFlag(qryattsetReceived);
843                 length = peekedLength_;
844                 qryattset = parseFastQRYATTSET();
845                 ddmLength = adjustDdmLength(ddmLength, length);
846                 peekCP = peekCodePoint();
847             }
848
849
850             if (!foundInPass) {
851                 doPrmnsprmSemantics(peekCP);
852             }
853
854         }
855         checkRequiredObjects(svrcodReceived, qryprctypReceived, qryinsidReceived);
856
857         netAgent_.setSvrcod(svrcod);
858
859         // hack for now until event methods are used below
860
Statement statement = (Statement) statementI;
861
862         // if there is a cached Cursor object, then use the cached cursor object.
863
NetResultSet rs = null;
864         if (statement.cachedCursor_ != null) {
865             statement.cachedCursor_.resetDataBuffer();
866             ((NetCursor) statement.cachedCursor_).extdtaData_.clear();
867             try {
868                 rs = (NetResultSet)ClientDriver.getFactory().newNetResultSet
869                         (netAgent_,
870                         (NetStatement) statement.materialStatement_,
871                         statement.cachedCursor_,
872                         qryprctyp, //protocolType, CodePoint.FIXROWPRC |
873
// CodePoint.LMTBLKPRC
874
sqlcsrhld, //holdOption, 0xF0 for false (default) | 0xF1 for true.
875
qryattscr, //scrollOption, 0xF0 for false (default) | 0xF1 for true.
876
qryattsns, //sensitivity, CodePoint.QRYUNK |
877
// CodePoint.QRYINS |
878
// CodePoint.QRYSNSSTC
879
qryattset,
880                         qryinsid, //instanceIdentifier, 0 (if not returned, check default) or number
881
calculateResultSetType(qryattscr, qryattsns, statement.resultSetType_),
882                         calculateResultSetConcurrency(qryattupd, statement.resultSetConcurrency_),
883                         calculateResultSetHoldability(sqlcsrhld));
884             } catch(SqlException sqle) {
885                 throw new DisconnectException(netAgent_,sqle);
886             }
887         } else {
888             try {
889                 rs = (NetResultSet)ClientDriver.getFactory().newNetResultSet
890                         (netAgent_,
891                         (NetStatement) statement.materialStatement_,
892                         new NetCursor(netAgent_, qryprctyp),
893                         qryprctyp, //protocolType, CodePoint.FIXROWPRC |
894
// CodePoint.LMTBLKPRC
895
sqlcsrhld, //holdOption, 0xF0 for false (default) | 0xF1 for true.
896
qryattscr, //scrollOption, 0xF0 for false (default) | 0xF1 for true.
897
qryattsns, //sensitivity, CodePoint.QRYUNK | CodePoint.QRYINS
898
qryattset,
899                         qryinsid, //instanceIdentifier, 0 (if not returned, check default) or number
900
calculateResultSetType(qryattscr, qryattsns, statement.resultSetType_),
901                         calculateResultSetConcurrency(qryattupd, statement.resultSetConcurrency_),
902                         calculateResultSetHoldability(sqlcsrhld));
903             } catch(SqlException sqle) {
904                throw new DisconnectException(netAgent_,sqle);
905             }
906             
907         }
908
909         // QRYCLSIMP only applies to OPNQRY, not EXCSQLSTT
910
final boolean qryclsimp =
911             isOPNQRYreply &&
912             (rs.resultSetType_ == java.sql.ResultSet.TYPE_FORWARD_ONLY) &&
913             netAgent_.netConnection_.serverSupportsQryclsimp();
914         rs.netCursor_.setQryclsimpEnabled(qryclsimp);
915
916         return rs;
917     }
918
919
920     // Also called by NetResultSetReply subclass.
921
// The End of Query Reply Message indicates that the query process has
922
// terminated in such a manner that the query or result set is now closed.
923
// It cannot be resumed with the CNTQRY command or closed with the CLSQRY command.
924
// The ENDQRYRM is always followed by an SQLCARD.
925
protected void parseENDQRYRM(ResultSetCallbackInterface resultSetI) throws DisconnectException {
926         boolean svrcodReceived = false;
927         int svrcod = CodePoint.SVRCOD_INFO;
928         boolean rdbnamReceived = false;
929         String JavaDoc rdbnam = null;
930
931         parseLengthAndMatchCodePoint(CodePoint.ENDQRYRM);
932         pushLengthOnCollectionStack();
933         int peekCP = peekCodePoint();
934
935         while (peekCP != Reply.END_OF_COLLECTION) {
936
937             boolean foundInPass = false;
938
939             if (peekCP == CodePoint.SVRCOD) {
940                 foundInPass = true;
941                 svrcodReceived = checkAndGetReceivedFlag(svrcodReceived);
942                 svrcod = parseSVRCOD(CodePoint.SVRCOD_WARNING, CodePoint.SVRCOD_ERROR);
943                 peekCP = peekCodePoint();
944             }
945
946             if (peekCP == CodePoint.RDBNAM) {
947                 foundInPass = true;
948                 rdbnamReceived = checkAndGetReceivedFlag(rdbnamReceived);
949                 rdbnam = parseRDBNAM(true);
950                 peekCP = peekCodePoint();
951             }
952             if (!foundInPass) {
953                 doPrmnsprmSemantics(peekCP);
954             }
955
956         }
957         popCollectionStack();
958         checkRequiredObjects(svrcodReceived);
959
960         netAgent_.setSvrcod(svrcod);
961
962     }
963
964
965     // Query Previously Opened Reply Message is issued when an
966
// OPNQRY command is issued for a query that is already open.
967
// A previous OPNQRY command might have opened the query
968
// which may not be closed.
969
// PROTOCOL Architects an SQLSTATE of 58008 or 58009.
970
//
971
// Messages
972
// SQLSTATE : 58009
973
// Execution failed due to a distribution protocol error that caused deallocation of the conversation.
974
// SQLCODE : -30020
975
// Execution failed because of a Distributed Protocol
976
// Error that will affect the successful execution of subsequent
977
// commands and SQL statements: Reason Code <reason-code>.
978
// Some possible reason codes include:
979
// 121C Indicates that the user is not authorized to perform the requested command.
980
// 1232 The command could not be completed because of a permanent error.
981
// In most cases, the server will be in the process of an abend.
982
// 220A The target server has received an invalid data description.
983
// If a user SQLDA is specified, ensure that the fields are
984
// initialized correctly. Also, ensure that the length does not
985
// exceed the maximum allowed length for the data type being used.
986
//
987
// The command or statement cannot be processed. The current
988
// transaction is rolled back and the application is disconnected
989
// from the remote database.
990
//
991
//
992
// Returned from Server:
993
// SVRCOD - required (8 - ERROR)
994
// RDBNAM - required
995
// PKGNAMCSN - required
996
// SRVDGN - optional
997
//
998
private void parseQRYPOPRM() throws DisconnectException {
999         boolean svrcodReceived = false;
1000        int svrcod = CodePoint.SVRCOD_INFO;
1001        boolean rdbnamReceived = false;
1002        String JavaDoc rdbnam = null;
1003        boolean pkgnamcsnReceived = false;
1004        Object JavaDoc pkgnamcsn = null;
1005
1006        parseLengthAndMatchCodePoint(CodePoint.QRYPOPRM);
1007        pushLengthOnCollectionStack();
1008        int peekCP = peekCodePoint();
1009
1010        while (peekCP != Reply.END_OF_COLLECTION) {
1011
1012            boolean foundInPass = false;
1013
1014            if (peekCP == CodePoint.SVRCOD) {
1015                foundInPass = true;
1016                svrcodReceived = checkAndGetReceivedFlag(svrcodReceived);
1017                svrcod = parseSVRCOD(CodePoint.SVRCOD_ERROR, CodePoint.SVRCOD_ERROR);
1018                peekCP = peekCodePoint();
1019            }
1020
1021            if (peekCP == CodePoint.RDBNAM) {
1022                foundInPass = true;
1023                rdbnamReceived = checkAndGetReceivedFlag(rdbnamReceived);
1024                rdbnam = parseRDBNAM(true);
1025                peekCP = peekCodePoint();
1026            }
1027            if (peekCP == CodePoint.PKGNAMCSN) {
1028                foundInPass = true;
1029                pkgnamcsnReceived = checkAndGetReceivedFlag(pkgnamcsnReceived);
1030                pkgnamcsn = parsePKGNAMCSN(true);
1031                peekCP = peekCodePoint();
1032            }
1033
1034            if (!foundInPass) {
1035                doPrmnsprmSemantics(peekCP);
1036            }
1037
1038        }
1039        popCollectionStack();
1040        checkRequiredObjects(svrcodReceived,
1041                rdbnamReceived,
1042                pkgnamcsnReceived);
1043
1044        netAgent_.setSvrcod(svrcod);
1045        agent_.accumulateChainBreakingReadExceptionAndThrow(new DisconnectException(agent_,
1046            new ClientMessageId(SQLState.DRDA_CONNECTION_TERMINATED),
1047            MessageUtil.getCompleteMessage(MessageId.CONN_DRDA_QRYOPEN,
1048                SqlException.CLIENT_MESSAGE_RESOURCE_NAME,
1049                (Object JavaDoc [])null)));
1050    }
1051
1052    // Open Query Failure (OPNQFLRM) Reply Message indicates that the
1053
// OPNQRY command failed to open the query. The reason that the
1054
// target relational database was unable to open the query is reported in an
1055
// SQLCARD reply data object.
1056
// Whenever an OPNQFLRM is returned, an SQLCARD object must also be returned
1057
// following the OPNQFLRM.
1058
//
1059
// Returned from Server:
1060
// SVRCOD - required (8 - ERROR)
1061
// RDBNAM - required
1062
// SRVDGN - optional
1063
private void parseOPNQFLRM(StatementCallbackInterface statement) throws DisconnectException {
1064        boolean svrcodReceived = false;
1065        int svrcod = CodePoint.SVRCOD_INFO;
1066        boolean rdbnamReceived = false;
1067        String JavaDoc rdbnam = null;
1068
1069        parseLengthAndMatchCodePoint(CodePoint.OPNQFLRM);
1070        pushLengthOnCollectionStack();
1071        int peekCP = peekCodePoint();
1072
1073        while (peekCP != Reply.END_OF_COLLECTION) {
1074
1075            boolean foundInPass = false;
1076
1077            if (peekCP == CodePoint.SVRCOD) {
1078                foundInPass = true;
1079                svrcodReceived = checkAndGetReceivedFlag(svrcodReceived);
1080                svrcod = parseSVRCOD(CodePoint.SVRCOD_ERROR, CodePoint.SVRCOD_ERROR);
1081                peekCP = peekCodePoint();
1082            }
1083
1084            if (peekCP == CodePoint.RDBNAM) {
1085                // skip the rdbnam since it doesn't tell us anything new.
1086
// there is no way to return it to the application anyway.
1087
// not having to convert this to a string is a time saver also.
1088
foundInPass = true;
1089                rdbnamReceived = checkAndGetReceivedFlag(rdbnamReceived);
1090                rdbnam = parseRDBNAM(true);
1091                peekCP = peekCodePoint();
1092            }
1093            if (!foundInPass) {
1094                doPrmnsprmSemantics(peekCP);
1095            }
1096
1097        }
1098        popCollectionStack();
1099        checkRequiredObjects(svrcodReceived, rdbnamReceived);
1100
1101        netAgent_.setSvrcod(svrcod);
1102
1103        // get SQLSTATE from SQLCARD...
1104
}
1105
1106    // RDB Result Set Reply Message (RSLSETRM) indicates that an
1107
// EXCSQLSTT command invoked a stored procedure, that the execution
1108
// of the stored procedure generated one or more result sets, and
1109
// additional information aobut these result sets follows the SQLCARD and
1110
// SQLDTARD in the reply data of the response
1111
//
1112
// Returned from Server:
1113
// SVRCOD - required (0 INFO)
1114
// PKGSNLST - required
1115
// SRVDGN - optional
1116
protected java.util.ArrayList JavaDoc parseRSLSETRM() throws DisconnectException {
1117        boolean svrcodReceived = false;
1118        int svrcod = CodePoint.SVRCOD_INFO;
1119        boolean pkgsnlstReceived = false;
1120        java.util.ArrayList JavaDoc pkgsnlst = null;
1121
1122        parseLengthAndMatchCodePoint(CodePoint.RSLSETRM);
1123        pushLengthOnCollectionStack();
1124        int peekCP = peekCodePoint();
1125
1126        while (peekCP != Reply.END_OF_COLLECTION) {
1127
1128            boolean foundInPass = false;
1129
1130            if (peekCP == CodePoint.SVRCOD) {
1131                foundInPass = true;
1132                svrcodReceived = checkAndGetReceivedFlag(svrcodReceived);
1133                svrcod = parseSVRCOD(CodePoint.SVRCOD_INFO, CodePoint.SVRCOD_INFO);
1134                peekCP = peekCodePoint();
1135            }
1136
1137            if (peekCP == CodePoint.PKGSNLST) {
1138                // contain repeatable PKGNAMCSN
1139
foundInPass = true;
1140                pkgsnlstReceived = checkAndGetReceivedFlag(pkgsnlstReceived);
1141                pkgsnlst = parsePKGSNLST();
1142                peekCP = peekCodePoint();
1143            }
1144
1145            if (!foundInPass) {
1146                doPrmnsprmSemantics(peekCP);
1147            }
1148
1149        }
1150        popCollectionStack();
1151        checkRequiredObjects(svrcodReceived, pkgsnlstReceived);
1152
1153        netAgent_.setSvrcod(svrcod);
1154
1155        return pkgsnlst;
1156    }
1157
1158    //--------------------- parse DDM Reply Data--------------------------------------
1159

1160
1161    // SQL Data Reply Data consists of output data from the relational database (RDB)
1162
// processing of an SQL statement. It also includes a description of the data.
1163
//
1164
// Returned from Server:
1165
// FDODSC - required
1166
// FDODTA - required
1167
protected NetSqlca parseSQLDTARD(NetSqldta netSqldta) throws DisconnectException {
1168        boolean fdodscReceived = false;
1169        boolean fdodtaReceived = false;
1170
1171        parseLengthAndMatchCodePoint(CodePoint.SQLDTARD);
1172        pushLengthOnCollectionStack();
1173
1174        NetSqlca netSqlca = null;
1175        int peekCP = peekCodePoint();
1176        while (peekCP != Reply.END_OF_COLLECTION) {
1177
1178            boolean foundInPass = false;
1179
1180            if (peekCP == CodePoint.FDODSC) {
1181                foundInPass = true;
1182                fdodscReceived = checkAndGetReceivedFlag(fdodscReceived);
1183                parseFDODSC(netSqldta);
1184                peekCP = peekCodePoint();
1185            }
1186
1187            if (peekCP == CodePoint.FDODTA) {
1188                foundInPass = true;
1189                fdodtaReceived = checkAndGetReceivedFlag(fdodtaReceived);
1190                netSqlca = parseFDODTA(netSqldta);
1191                peekCP = peekCodePoint();
1192            }
1193
1194            if (!foundInPass) {
1195                doPrmnsprmSemantics(peekCP);
1196            }
1197
1198        }
1199        popCollectionStack();
1200        checkRequiredObjects(fdodscReceived, fdodtaReceived);
1201        netSqldta.calculateColumnOffsetsForRow();
1202        return netSqlca;
1203    }
1204
1205    protected void parseQRYDSC(NetCursor cursor) throws DisconnectException {
1206        parseLengthAndMatchCodePoint(CodePoint.QRYDSC);
1207        parseSQLDTARDarray(cursor, false); // false means don't just skip the bytes
1208
}
1209
1210    private void parseFDODSC(NetCursor cursor) throws DisconnectException {
1211        parseLengthAndMatchCodePoint(CodePoint.FDODSC);
1212        parseSQLDTARDarray(cursor, false); // false means don't just skip the bytes
1213
}
1214
1215    private void parseSQLDTARDarray(NetCursor cursor, boolean skipBytes) throws DisconnectException {
1216        if (skipBytes) {
1217            skipBytes();
1218        }
1219        int previousTripletType = FdocaConstants.SQLDTARD_TRIPLET_TYPE_START;
1220        int previousTripletId = FdocaConstants.SQLDTARD_TRIPLET_ID_START;
1221        int mddProtocolType = 0;
1222        int columnCount = 0;
1223        netAgent_.targetTypdef_.clearMddOverrides();
1224
1225        int ddmLength = getDdmLength();
1226        ensureBLayerDataInBuffer(ddmLength);
1227
1228        while (ddmLength > 0) {
1229
1230            int tripletLength = readFastUnsignedByte();
1231            int tripletType = readFastUnsignedByte();
1232            int tripletId = readFastUnsignedByte();
1233
1234            switch (tripletType) {
1235
1236            case FdocaConstants.MDD_TRIPLET_TYPE:
1237                if ((tripletLength != FdocaConstants.MDD_TRIPLET_SIZE) ||
1238                        (tripletId != FdocaConstants.NULL_LID)) {
1239                    descriptorErrorDetected();
1240                }
1241                checkPreviousSQLDTARDtriplet(previousTripletType,
1242                        FdocaConstants.SQLDTARD_TRIPLET_TYPE_MDD,
1243                        previousTripletId,
1244                        FdocaConstants.SQLDTARD_TRIPLET_ID_0);
1245                previousTripletType = FdocaConstants.SQLDTARD_TRIPLET_TYPE_MDD;
1246                previousTripletId = FdocaConstants.SQLDTARD_TRIPLET_ID_0;
1247
1248                // read in remaining MDD bytes
1249
int mddClass = readFastUnsignedByte();
1250                int mddType = readFastUnsignedByte();
1251                int mddRefType = readFastUnsignedByte();
1252                mddProtocolType = readFastUnsignedByte();
1253                break;
1254
1255            case FdocaConstants.NGDA_TRIPLET_TYPE: // rename to NGDA_TRIPLET_CODEPOINT
1256
if (tripletId != FdocaConstants.SQLDTAGRP_LID) {
1257                    descriptorErrorDetected();
1258                }
1259                checkPreviousSQLDTARDtriplet(previousTripletType,
1260                        FdocaConstants.SQLDTARD_TRIPLET_TYPE_GDA,
1261                        previousTripletId,
1262                        FdocaConstants.SQLDTARD_TRIPLET_ID_D0);
1263                previousTripletType = FdocaConstants.SQLDTARD_TRIPLET_TYPE_GDA;
1264                previousTripletId = FdocaConstants.SQLDTARD_TRIPLET_ID_0;
1265
1266                // add a quick check to see if the table is altered (columns are added or deleted)
1267
// before reusing the cached cursor. note: this check does not catch the case
1268
// where the number of columns stay the same, but the column type or length changes,
1269
// i.e. from integer to char.
1270
int columns = peekTotalColumnCount(tripletLength);
1271                // peek ahead to get the total number of columns.
1272
cursor.initializeColumnInfoArrays(netAgent_.targetTypdef_, columns, netAgent_.targetSqlam_);
1273                columnCount += parseSQLDTAGRPdataLabelsAndUpdateColumn(cursor, columnCount, tripletLength);
1274                break;
1275
1276
1277            case FdocaConstants.RLO_TRIPLET_TYPE: // rename to RLO_TRIPLET_CODEPOINT
1278

1279                switch (tripletId) {
1280                case FdocaConstants.SQLCADTA_LID:
1281                    if (tripletLength != FdocaConstants.SQLCADTA_RLO_SIZE) {
1282                        descriptorErrorDetected(); // DSCERRCD_06
1283
}
1284                    checkPreviousSQLDTARDtriplet(previousTripletType,
1285                            FdocaConstants.SQLDTARD_TRIPLET_TYPE_RLO,
1286                            previousTripletId,
1287                            FdocaConstants.SQLDTARD_TRIPLET_ID_E0);
1288                    previousTripletType = FdocaConstants.SQLDTARD_TRIPLET_TYPE_RLO;
1289                    previousTripletId = FdocaConstants.SQLDTARD_TRIPLET_ID_E0;
1290                    checkFastRLO(FdocaConstants.RLO_SQLCADTA);
1291                    break;
1292
1293                case FdocaConstants.SQLDTARD_LID:
1294                    if (tripletLength != FdocaConstants.SQLDTARD_RLO_SIZE) {
1295                        descriptorErrorDetected(); // DSCERRCD_06
1296
}
1297                    checkPreviousSQLDTARDtriplet(previousTripletType,
1298                            FdocaConstants.SQLDTARD_TRIPLET_TYPE_RLO,
1299                            previousTripletId,
1300                            FdocaConstants.SQLDTARD_TRIPLET_ID_F0);
1301                    previousTripletType = FdocaConstants.SQLDTARD_TRIPLET_TYPE_RLO;
1302                    previousTripletId = FdocaConstants.SQLDTARD_TRIPLET_ID_F0;
1303                    checkFastRLO(FdocaConstants.RLO_SQLDTARD);
1304                    break;
1305                default:
1306                    descriptorErrorDetected(); // DSCERRCD_07
1307
break;
1308                }
1309                break;
1310
1311            case FdocaConstants.CPT_TRIPLET_TYPE: // rename to CPT_TRIPLET_CODEPOINT
1312
if (tripletId != FdocaConstants.NULL_LID) {
1313                    descriptorErrorDetected();
1314                }
1315                checkPreviousSQLDTARDtriplet(previousTripletType,
1316                        FdocaConstants.SQLDTARD_TRIPLET_TYPE_CPT,
1317                        previousTripletId,
1318                        FdocaConstants.SQLDTARD_TRIPLET_ID_0);
1319                previousTripletType = FdocaConstants.SQLDTARD_TRIPLET_TYPE_CPT;
1320                previousTripletId = FdocaConstants.SQLDTARD_TRIPLET_ID_0;
1321
1322                columnCount += parseSQLDTAGRPdataLabelsAndUpdateColumn(cursor, columnCount, tripletLength);
1323                break;
1324
1325
1326            case FdocaConstants.SDA_TRIPLET_TYPE: // rename to SDA_TRIPLET_CODEPOINT
1327
if (tripletLength != FdocaConstants.SDA_TRIPLET_SIZE) {
1328                    descriptorErrorDetected(); // DSCERRCD_06
1329
}
1330                checkPreviousSQLDTARDtriplet(previousTripletType,
1331                        FdocaConstants.SQLDTARD_TRIPLET_TYPE_SDA,
1332                        previousTripletId,
1333                        FdocaConstants.SQLDTARD_TRIPLET_ID_SDA);
1334                previousTripletType = FdocaConstants.SQLDTARD_TRIPLET_TYPE_SDA;
1335                previousTripletId = FdocaConstants.SQLDTARD_TRIPLET_ID_SDA;
1336                netAgent_.targetTypdef_.setMddOverride(mddProtocolType, // mdd protocol type
1337
tripletId, // fdocaTripletLid
1338
readFastUnsignedByte(), // fdocaFieldType
1339
readFastInt(), // ccsid
1340
readFastUnsignedByte(), // characterSize
1341
readFastUnsignedByte(), // mode
1342
readFastShort());
1343                break;
1344
1345            default:
1346                descriptorErrorDetected(); //DSCERRCD_01
1347
break;
1348            }
1349
1350            ddmLength -= tripletLength;
1351        }
1352
1353        adjustLengths(getDdmLength());
1354
1355        // Allocate a char buffer after all of the descriptors have been parsed out.
1356
cursor.allocateCharBuffer();
1357
1358        checkPreviousSQLDTARDtriplet(previousTripletType,
1359                FdocaConstants.SQLDTARD_TRIPLET_TYPE_END,
1360                previousTripletId,
1361                FdocaConstants.SQLDTARD_TRIPLET_ID_END);
1362
1363    }
1364
1365    private void checkPreviousSQLDTARDtriplet(int previousTripletType,
1366                                              int tripletType,
1367                                              int previousTripletId,
1368                                              int tripletId) throws DisconnectException {
1369        if (FdocaConstants.SQLDTARD_TRIPLET_TYPES[previousTripletType][tripletType] == false) {
1370            descriptorErrorDetected(); // DSCERRCD_02 move error identity into array
1371
}
1372        if (FdocaConstants.SQLDTARD_TRIPLET_IDS[previousTripletId][tripletId] == false) {
1373            descriptorErrorDetected(); // DSCERRCD_02 move error identity into array
1374
}
1375    }
1376
1377
1378    private void checkFastRLO(int[][] rlo) throws DisconnectException {
1379        for (int i = 0; i < rlo.length; i++) {
1380            int lid = readFastUnsignedByte();
1381            if (lid != rlo[i][FdocaConstants.RLO_GROUP_LID]) {
1382                descriptorErrorDetected(); // DSCERRCD_42
1383
}
1384            int elementTaken = readFastUnsignedByte();
1385            if (elementTaken != rlo[i][FdocaConstants.RLO_ELEMENT_TAKEN]) {
1386                descriptorErrorDetected(); // DSCERRCD_07
1387
}
1388            int repFactor = readFastUnsignedByte();
1389            if (repFactor != rlo[i][FdocaConstants.RLO_REP_FACTOR]) {
1390                descriptorErrorDetected(); // DSCERRCD_07
1391
}
1392        }
1393    }
1394
1395    // Possible errors to detect include:
1396
// DSCERRCD_01 - FDOCA triplet is not used in PROTOCOL descriptors or type code is invalid
1397
// DSCERRCD_02 - FDOCA triplet sequence error
1398
// DSCERRCD_03 - An array description is required and this is not one
1399
// (too many or too few RLO triplets)
1400
// DSCERRCD_04 - A row description is required and this is not one
1401
// (too many or too few RLO triplets)
1402
// DSCERRCD_05 - Late Environmental Descriptor just received not supported
1403
// DSCERRCD_06 - Malformed triplet, required parameter is missing
1404
// DSCERRCD_07 - Parameter value is not acceptable
1405
// DSCERRCD_11 - MDD present is not recognized as an SQL descriptor
1406
// DSCERRCD_12 - MDD class is not recognized as a valid SQL class
1407
// DSCERRCD_13 - MDD type not recognized as a valid SQL type
1408
// DSCERRCD_21 - Representation is incompatible with SQL type (in prior MDD)
1409
// DSCERRCD_22 - CCSID is not supported
1410
// DSCERRCD_32 - GDA references a local identifier which is not an SDA or GDA
1411
// DSCERRCD_33 - GDA length override exceeds limits
1412
// DSCERRCD_34 - GDA precision exceeds limits
1413
// DSCERRCD_35 - GDA scale greater than precision or scale negative
1414
// DSCERRCD_36 - GDA length override missing or incompatible with data type
1415
// DSCERRCD_41 - RLO references a LID which is not an RLO or GDA.
1416
// DSCERRCD_42 - RLO fails to reference a required GDA or RLO.
1417
private void descriptorErrorDetected() throws DisconnectException {
1418        agent_.accumulateChainBreakingReadExceptionAndThrow(new DisconnectException(agent_,
1419            new ClientMessageId(SQLState.DRDA_CONNECTION_TERMINATED),
1420            MessageUtil.getCompleteMessage(MessageId.CONN_DRDA_INVALIDFDOCA,
1421                SqlException.CLIENT_MESSAGE_RESOURCE_NAME,
1422                (Object JavaDoc [])null)));
1423    }
1424
1425    protected void parseQRYDTA(NetResultSet netResultSet) throws DisconnectException {
1426        parseLengthAndMatchCodePoint(CodePoint.QRYDTA);
1427        if (longValueForDecryption_ == null) {
1428            int ddmLength = getDdmLength();
1429            ensureBLayerDataInBuffer(ddmLength);
1430        }
1431        parseSQLDTARDdata(netResultSet.netCursor_);
1432        if (longValueForDecryption_ == null) {
1433            adjustLengths(getDdmLength());
1434        } else {
1435            longValueForDecryption_ = null;
1436        }
1437        if (longBufferForDecryption_ != null) {
1438            buffer_ = longBufferForDecryption_;
1439            pos_ = longPosForDecryption_;
1440            if (count_ > longBufferForDecryption_.length) {
1441                count_ = longBufferForDecryption_.length;
1442            } else if (longCountForDecryption_ != 0) {
1443                count_ = longCountForDecryption_;
1444                longCountForDecryption_ = 0;
1445            }
1446            dssLength_ = 0;
1447            longBufferForDecryption_ = null;
1448        }
1449
1450
1451    }
1452
1453    NetSqlca parseFDODTA(NetCursor netCursor) throws DisconnectException {
1454        parseLengthAndMatchCodePoint(CodePoint.FDODTA);
1455        int ddmLength = getDdmLength();
1456        ensureBLayerDataInBuffer(ddmLength);
1457        mark();
1458        NetSqlca netSqlca = parseSQLCARDrow(null);
1459        int length = getFastSkipSQLCARDrowLength();
1460        adjustLengths(length);
1461        parseFastSQLDTARDdata(netCursor);
1462        return netSqlca;
1463    }
1464
1465    void parseFastSQLDTARDdata(NetCursor netCursor) throws DisconnectException {
1466        netCursor.dataBufferStream_ = getFastData(netCursor.dataBufferStream_);
1467        netCursor.dataBuffer_ = netCursor.dataBufferStream_.toByteArray();
1468        netCursor.lastValidBytePosition_ = netCursor.dataBuffer_.length;
1469    }
1470
1471    void parseSQLDTARDdata(NetCursor netCursor) throws DisconnectException {
1472        if (longValueForDecryption_ == null) {
1473            netCursor.dataBufferStream_ = getData(netCursor.dataBufferStream_);
1474            netCursor.dataBuffer_ = netCursor.dataBufferStream_.toByteArray();
1475        } else {
1476            int size = netCursor.dataBufferStream_.size();
1477            if (size == 0) {
1478                netCursor.dataBuffer_ = longValueForDecryption_;
1479                //longValue_ = null;
1480
} else {
1481                byte[] newArray = new byte[size + longValueForDecryption_.length];
1482                System.arraycopy(netCursor.dataBuffer_, 0, newArray, 0, size);
1483                System.arraycopy(longValueForDecryption_, 0, newArray, size, longValueForDecryption_.length);
1484                netCursor.dataBuffer_ = newArray;
1485                //longValue_ = null;
1486
}
1487        }
1488
1489        netCursor.lastValidBytePosition_ = netCursor.dataBuffer_.length;
1490    }
1491
1492    protected void copyEXTDTA(NetCursor netCursor) throws DisconnectException {
1493        try {
1494            parseLengthAndMatchCodePoint(CodePoint.EXTDTA);
1495            byte[] data = null;
1496            if (longValueForDecryption_ == null) {
1497                data = (getData(null)).toByteArray();
1498            } else {
1499                data = longValueForDecryption_;
1500                dssLength_ = 0;
1501                longValueForDecryption_ = null;
1502            }
1503            netCursor.extdtaData_.add(data);
1504        } catch (java.lang.OutOfMemoryError JavaDoc e) {
1505            agent_.accumulateChainBreakingReadExceptionAndThrow(new DisconnectException(agent_,
1506                new ClientMessageId(SQLState.NET_LOB_DATA_TOO_LARGE_FOR_JVM), null, e));
1507        }
1508    }
1509
1510    //------------------------parse DDM Scalars-----------------------------
1511

1512    // RDB Package name, consistency token, and section number
1513
// specifies the fully qualified name of a relational
1514
// database package, its consistency token, and a specific
1515
// section within a package.
1516
//
1517
// Only called for generated secctions from a callable statement.
1518
//
1519
protected Object JavaDoc parsePKGNAMCSN(boolean skip) throws DisconnectException {
1520        parseLengthAndMatchCodePoint(CodePoint.PKGNAMCSN);
1521        if (skip) {
1522            skipBytes();
1523            return null;
1524        }
1525
1526        // Still need to populate the logical members in case of an "set current packageset"
1527
String JavaDoc rdbnam = null;
1528        String JavaDoc rdbcolid = null;
1529        String JavaDoc pkgid = null;
1530        byte[] pkgcnstkn = null;
1531
1532        int pkgsn = 0;
1533        byte[] pkgnamcsnBytes = null;
1534        int pkgnamcsnLength = 0;
1535
1536        int ddmLength = getDdmLength();
1537        int offset = 0;
1538
1539        ensureBLayerDataInBuffer(ddmLength);
1540
1541        if (ddmLength == 64) {
1542            // read all the bytes except the section number into the byte[] for caching
1543
pkgnamcsnLength = ddmLength - 2;
1544            //pkgnamcsnBytes = readBytes (pkgnamcsnLength);
1545
pkgnamcsnBytes = new byte[pkgnamcsnLength];
1546            // readFast() does a read without moving the read head.
1547
offset = peekFastBytes(pkgnamcsnBytes, offset, pkgnamcsnLength);
1548
1549            // populate the logical members
1550
rdbnam = readFastString(18); // RDB name
1551
rdbcolid = readFastString(18); // RDB Collection ID
1552
pkgid = readFastString(18); // RDB Package ID
1553
pkgcnstkn = readFastBytes(8); // Package Consistency Token
1554
} else if ((ddmLength >= 71) && (ddmLength <= 781)) {
1555            // this is the new SCLDTA format.
1556

1557            // new up a byte[] to cache all the bytes except the 2-byte section number
1558
pkgnamcsnBytes = new byte[ddmLength - 2];
1559
1560            // get rdbnam
1561
int scldtaLen = peekFastLength();
1562            if (scldtaLen < 18 || scldtaLen > 255) {
1563                agent_.accumulateChainBreakingReadExceptionAndThrow(
1564                    new DisconnectException(agent_,
1565                        new ClientMessageId(
1566                            SQLState.NET_SQLCDTA_INVALID_FOR_RDBNAM),
1567                    new Integer JavaDoc(scldtaLen)));
1568                return null;
1569            }
1570            // read 2+scldtaLen number of bytes from the reply buffer into the pkgnamcsnBytes
1571
//offset = readBytes (pkgnamcsnBytes, offset, 2+scldtaLen);
1572
offset = peekFastBytes(pkgnamcsnBytes, offset, 2 + scldtaLen);
1573            skipFastBytes(2);
1574            rdbnam = readFastString(scldtaLen);
1575
1576            // get rdbcolid
1577
scldtaLen = peekFastLength();
1578            if (scldtaLen < 18 || scldtaLen > 255) {
1579                agent_.accumulateChainBreakingReadExceptionAndThrow(new DisconnectException(agent_,
1580                    new ClientMessageId(SQLState.NET_SQLCDTA_INVALID_FOR_RDBCOLID),
1581                    new Integer JavaDoc(scldtaLen)));
1582                return null;
1583            }
1584            // read 2+scldtaLen number of bytes from the reply buffer into the pkgnamcsnBytes
1585
offset = peekFastBytes(pkgnamcsnBytes, offset, 2 + scldtaLen);
1586            skipFastBytes(2);
1587            rdbcolid = readFastString(scldtaLen);
1588
1589            // get pkgid
1590
scldtaLen = peekFastLength();
1591            if (scldtaLen < 18 || scldtaLen > 255) {
1592                agent_.accumulateChainBreakingReadExceptionAndThrow(new DisconnectException(agent_,
1593                    new ClientMessageId(SQLState.NET_SQLCDTA_INVALID_FOR_PKGID),
1594                    new Integer JavaDoc(scldtaLen)));
1595                return null; // To make compiler happy.
1596
}
1597            // read 2+scldtaLen number of bytes from the reply buffer into the pkgnamcsnBytes
1598
offset = peekFastBytes(pkgnamcsnBytes, offset, 2 + scldtaLen);
1599            skipFastBytes(2);
1600            pkgid = readFastString(scldtaLen);
1601
1602            // get consistency token
1603
offset = peekFastBytes(pkgnamcsnBytes, offset, 8);
1604            pkgcnstkn = readFastBytes(8);
1605
1606        } else {
1607            agent_.accumulateChainBreakingReadExceptionAndThrow(new DisconnectException(agent_,
1608                new ClientMessageId(SQLState.NET_PGNAMCSN_INVALID_AT_SQLAM),
1609                new Integer JavaDoc(ddmLength), new Integer JavaDoc(netAgent_.targetSqlam_)));
1610            return null; // To make compiler happy.
1611
}
1612
1613        pkgsn = readFastUnsignedShort(); // Package Section Number.
1614
adjustLengths(ddmLength);
1615        // this is a server generated section
1616
// the -1 is set for holdability and it is not used for generated sections
1617
Section section = new Section(this.agent_, pkgid, pkgsn, null, -1, true);
1618        section.setPKGNAMCBytes(pkgnamcsnBytes);
1619        return section;
1620    }
1621
1622    // Query Protocol type specifies the type of query protocol
1623
// the target SQLAM uses.
1624
protected int parseQRYPRCTYP() throws DisconnectException {
1625        parseLengthAndMatchCodePoint(CodePoint.QRYPRCTYP);
1626        int qryprctyp = parseCODPNTDR();
1627        if ((qryprctyp != CodePoint.FIXROWPRC) && (qryprctyp != CodePoint.LMTBLKPRC)) {
1628            doValnsprmSemantics(CodePoint.QRYPRCTYP, qryprctyp);
1629        }
1630        return qryprctyp;
1631    }
1632
1633    protected int parseFastQRYPRCTYP() throws DisconnectException {
1634        matchCodePoint(CodePoint.QRYPRCTYP);
1635        int qryprctyp = readFastUnsignedShort();
1636        if ((qryprctyp != CodePoint.FIXROWPRC) && (qryprctyp != CodePoint.LMTBLKPRC)) {
1637            doValnsprmSemantics(CodePoint.QRYPRCTYP, qryprctyp);
1638        }
1639        return qryprctyp;
1640    }
1641
1642    // hold cursor position state indicates whether the requester specified
1643
// the HOLD option on the SQL DECLARE CURSOR statement. When the HOLD
1644
// option is specified, the cursor is not closed upon execution of a
1645
// commit operation.
1646
// The value TRUE indicates that the requester specifies the HOLD
1647
// operation. The value FALSSE indicates that the requeter is not
1648
// specifying the HOLD option.
1649
protected int parseSQLCSRHLD() throws DisconnectException {
1650        parseLengthAndMatchCodePoint(CodePoint.SQLCSRHLD);
1651        int sqlcsrhld = readUnsignedByte();
1652        // 0xF0 is false (default), 0xF1 is true // use constants in if
1653
if ((sqlcsrhld != 0xF0) && (sqlcsrhld != 0xF1)) {
1654            doValnsprmSemantics(CodePoint.SQLCSRHLD, sqlcsrhld);
1655        }
1656        return sqlcsrhld;
1657    }
1658
1659    protected int parseFastSQLCSRHLD() throws DisconnectException {
1660        matchCodePoint(CodePoint.SQLCSRHLD);
1661        int sqlcsrhld = readFastUnsignedByte();
1662        // 0xF0 is false (default), 0xF1 is true // use constants in if
1663
if ((sqlcsrhld != 0xF0) && (sqlcsrhld != 0xF1)) {
1664            doValnsprmSemantics(CodePoint.SQLCSRHLD, sqlcsrhld);
1665        }
1666        return sqlcsrhld;
1667    }
1668
1669    // Query Attribute for Scrollability indicates whether
1670
// a cursor is scrollable or non-scrollable
1671
protected int parseQRYATTSCR() throws DisconnectException {
1672        parseLengthAndMatchCodePoint(CodePoint.QRYATTSCR);
1673        int qryattscr = readUnsignedByte(); // use constants in if
1674
if ((qryattscr != 0xF0) && (qryattscr != 0xF1)) {
1675            doValnsprmSemantics(CodePoint.QRYATTSCR, qryattscr);
1676        }
1677        return qryattscr;
1678    }
1679
1680    protected int parseFastQRYATTSCR() throws DisconnectException {
1681        matchCodePoint(CodePoint.QRYATTSCR);
1682        int qryattscr = readFastUnsignedByte(); // use constants in if
1683
if ((qryattscr != 0xF0) && (qryattscr != 0xF1)) {
1684            doValnsprmSemantics(CodePoint.QRYATTSCR, qryattscr);
1685        }
1686        return qryattscr;
1687    }
1688
1689    // enabled for rowset positioning.
1690
protected int parseQRYATTSET() throws DisconnectException {
1691        parseLengthAndMatchCodePoint(CodePoint.QRYATTSET);
1692        int qryattset = readUnsignedByte(); // use constants in if
1693
if ((qryattset != 0xF0) && (qryattset != 0xF1)) {
1694            doValnsprmSemantics(CodePoint.QRYATTSET, qryattset);
1695        }
1696        return qryattset;
1697    }
1698
1699    protected int parseFastQRYATTSET() throws DisconnectException {
1700        matchCodePoint(CodePoint.QRYATTSET);
1701        int qryattset = readFastUnsignedByte(); // use constants in if
1702
if ((qryattset != 0xF0) && (qryattset != 0xF1)) {
1703            doValnsprmSemantics(CodePoint.QRYATTSET, qryattset);
1704        }
1705        return qryattset;
1706    }
1707
1708    // Query attribute for Sensitivity indicats the sensitivity
1709
// of an opened cursor to changes made to the underlying
1710
// base table.
1711
protected int parseQRYATTSNS() throws DisconnectException {
1712        parseLengthAndMatchCodePoint(CodePoint.QRYATTSNS);
1713        int qryattsns = readUnsignedByte();
1714        switch (qryattsns) {
1715        case CodePoint.QRYUNK:
1716        case CodePoint.QRYINS:
1717            break;
1718        default:
1719            doValnsprmSemantics(CodePoint.QRYATTSNS, qryattsns);
1720            break;
1721        }
1722        return qryattsns;
1723    }
1724
1725    protected int parseFastQRYATTSNS() throws DisconnectException {
1726        matchCodePoint(CodePoint.QRYATTSNS);
1727        int qryattsns = readFastUnsignedByte();
1728        switch (qryattsns) {
1729        case CodePoint.QRYUNK:
1730        case CodePoint.QRYSNSSTC:
1731        case CodePoint.QRYINS:
1732            break;
1733        default:
1734            doValnsprmSemantics(CodePoint.QRYATTSNS, qryattsns);
1735            break;
1736        }
1737        return qryattsns;
1738    }
1739
1740    // Query Attribute for Updatability indicates the updatability
1741
// of an opened cursor.
1742
protected int parseQRYATTUPD() throws DisconnectException {
1743        parseLengthAndMatchCodePoint(CodePoint.QRYATTUPD);
1744        int qryattupd = readUnsignedByte();
1745        switch (qryattupd) {
1746        case CodePoint.QRYUNK:
1747        case CodePoint.QRYRDO:
1748        case CodePoint.QRYUPD:
1749            break;
1750        default:
1751            doValnsprmSemantics(CodePoint.QRYATTUPD, qryattupd);
1752            break;
1753        }
1754        return qryattupd;
1755    }
1756
1757    protected int parseFastQRYATTUPD() throws DisconnectException {
1758        matchCodePoint(CodePoint.QRYATTUPD);
1759        int qryattupd = readFastUnsignedByte();
1760        switch (qryattupd) {
1761        case CodePoint.QRYUNK:
1762        case CodePoint.QRYRDO:
1763        case CodePoint.QRYUPD:
1764            break;
1765        default:
1766            doValnsprmSemantics(CodePoint.QRYATTUPD, qryattupd);
1767            break;
1768        }
1769        return qryattupd;
1770    }
1771
1772
1773    private long parseFastQRYINSID() throws DisconnectException {
1774        matchCodePoint(CodePoint.QRYINSID);
1775        return readFastLong();
1776    }
1777
1778
1779    // RDB Package Namce, Consistency Token, and Section Number List
1780
// specifies a list of fully qualified names of specific sections
1781
// within one or more packages.
1782
protected java.util.ArrayList JavaDoc parsePKGSNLST() throws DisconnectException {
1783        Object JavaDoc pkgnamcsn = null;
1784        java.util.ArrayList JavaDoc pkgsnlst = new java.util.ArrayList JavaDoc(); // what default size should we use
1785

1786        parseLengthAndMatchCodePoint(CodePoint.PKGSNLST);
1787        pushLengthOnCollectionStack();
1788        while (peekCodePoint() != Reply.END_OF_COLLECTION) {
1789            pkgnamcsn = parsePKGNAMCSN(false);
1790            pkgsnlst.add(pkgnamcsn);
1791        }
1792        popCollectionStack();
1793        return pkgsnlst;
1794    }
1795
1796    protected NetSqlca parseSQLDARD(ColumnMetaData columnMetaData,
1797                                    boolean skipBytes) throws DisconnectException {
1798        parseLengthAndMatchCodePoint(CodePoint.SQLDARD);
1799        return parseSQLDARDarray(columnMetaData, skipBytes);
1800    }
1801
1802    protected int parseSQLRSLRD(java.util.ArrayList JavaDoc sectionAL) throws DisconnectException {
1803        parseLengthAndMatchCodePoint(CodePoint.SQLRSLRD);
1804        return parseSQLRSLRDarray(sectionAL);
1805    }
1806
1807    protected ColumnMetaData parseSQLCINRD() throws DisconnectException {
1808        parseLengthAndMatchCodePoint(CodePoint.SQLCINRD);
1809        int ddmLength = getDdmLength();
1810        ensureBLayerDataInBuffer(ddmLength);
1811        ColumnMetaData cm = parseSQLCINRDarray();
1812        adjustLengths(getDdmLength());
1813        return cm;
1814    }
1815
1816
1817    //--------------------------parse FDOCA objects------------------------
1818

1819    // SQLDARD : FDOCA EARLY ARRAY
1820
// SQL Descriptor Area Row Description with SQL Communications Area
1821
//
1822
// FORMAT FOR SQLAM <= 6
1823
// SQLCARD; ROW LID 0x64; ELEMENT TAKEN 0(all); REP FACTOR 1
1824
// SQLNUMROW; ROW LID 0x68; ELEMENT TAKEN 0(all); REP FACTOR 1
1825
// SQLDAROW; ROW LID 0x60; ELEMENT TAKEN 0(all); REP FACTOR 0(all)
1826
//
1827
// FORMAT FOR SQLAM >= 7
1828
// SQLCARD; ROW LID 0x64; ELEMENT TAKEN 0(all); REP FACTOR 1
1829
// SQLDHROW; ROW LID 0xE0; ELEMENT TAKEN 0(all); REP FACTOR 1
1830
// SQLNUMROW; ROW LID 0x68; ELEMENT TAKEN 0(all); REP FACTOR 1
1831
// SQLDAROW; ROW LID 0x60; ELEMENT TAKEN 0(all); REP FACTOR 0(all)
1832
NetSqlca parseSQLDARDarray(ColumnMetaData columnMetaData,
1833                               boolean skipBytes) throws DisconnectException {
1834        int ddmLength = 0;
1835        if (!ensuredLengthForDecryption_ && longValueForDecryption_ == null) { //if ensuredLength = true, means we already ensured length in decryptData, so don't need to do it again
1836
ddmLength = getDdmLength();
1837            ensureBLayerDataInBuffer(ddmLength);
1838
1839        }
1840        if (longValueForDecryption_ != null) {
1841            buffer_ = longValueForDecryption_;
1842            pos_ = 0;
1843            count_ = longValueForDecryption_.length;
1844            //dssLength_ = 0;
1845
}
1846
1847
1848        NetSqlca netSqlca = null;
1849        if (skipBytes) {
1850            mark();
1851            netSqlca = parseSQLCARDrow(null);
1852            skipFastBytes(ddmLength - getFastSkipSQLCARDrowLength());
1853            adjustLengths(getDdmLength());
1854            return netSqlca;
1855        } else {
1856            netSqlca = parseSQLCARDrow(null);
1857        }
1858
1859        parseSQLDHROW(columnMetaData);
1860
1861        int columns = parseSQLNUMROW();
1862        if (columns > columnMetaData.columns_) // this will only be true when columnMetaData.columns_ = 0 under deferred prepare
1863
// under deferred prepare the CMD arrays are not allocated until now, no guesses were made
1864
{
1865            columnMetaData.initializeCache(columns);
1866        } else // column count was guessed, don't bother reallocating arrays, just truncate their lengths
1867
{
1868            columnMetaData.columns_ = columns;
1869        }
1870
1871        // is this correct for 0 SQLNUMROW
1872
// does rest of code expect a null ColumnMetaData object
1873
// or does rest of code expect an non null object
1874
// with columns_ set to 0
1875

1876        for (int i = 0; i < columnMetaData.columns_; i++) {
1877            parseSQLDAROW(columnMetaData, i);
1878        }
1879
1880        if (longValueForDecryption_ == null) {
1881            adjustLengths(getDdmLength());
1882        } else {
1883            dssLength_ = 0;
1884            longValueForDecryption_ = null;
1885        }
1886
1887
1888        return netSqlca;
1889    }
1890
1891
1892    // SQLRSLRD : FDOCA EARLY ARRAY
1893
// Data Array of a Result Set
1894
//
1895
// FORMAT FOR ALL SQLAM LEVELS
1896
// SQLNUMROW; ROW LID 0x68; ELEMENT TAKEN 0(all); REP FACTOR 1
1897
// SQLRSROW; ROW LID 0x6F; ELEMENT TAKEN 0(all); REP FACTOR 0(all)
1898
//
1899
// SQL Result Set Reply Data (SQLRSLRD) is a byte string that specifies
1900
// information about result sets returned as reply data in the response to
1901
// an EXCSQLSTT command that invokes a stored procedure
1902
int parseSQLRSLRDarray(java.util.ArrayList JavaDoc sectionAL) throws DisconnectException {
1903        int numOfResultSets = parseSQLNUMROW();
1904        for (int i = 0; i < numOfResultSets; i++) {
1905            parseSQLRSROW((Section) sectionAL.get(i));
1906        }
1907        return numOfResultSets;
1908    }
1909
1910    // SQLCINRD : FDOCA EARLY ARRAY
1911
// SQL Result Set Column Array Description
1912
//
1913
// FORMAT FOR SQLAM <= 6
1914
// SQLNUMROW; ROW LID 0x68; ELEMENT TAKEN 0(all); REP FACTOR 1
1915
// SQLCIROW; ROW LID 0x6B; ELEMENT TAKEN 0(all); REP FACTOR 0(all)
1916
//
1917
// FORMAT FOR SQLAM >= 7
1918
// SQLDHROW; ROW LID 0xE0; ELEMENT TAKEN 0(all); REP FACTOR 1
1919
// SQLNUMROW; ROW LID 0x68; ELEMENT TAKEN 0(all); REP FACTOR 1
1920
// SQLDAROW; ROW LID 0x60; ELEMENT TAKEN 0(all); REP FACTOR 0(all)
1921
//
1922
// SQL Result Set Column Information Reply Data (SQLCINRD) is a byte string
1923
// that specifies information about columns for a result set returned as
1924
// reply data in the response to an EXCSQLSTT command that invodes a stored
1925
// procedure
1926
ColumnMetaData parseSQLCINRDarray() throws DisconnectException {
1927        ColumnMetaData columnMetaData = ClientDriver.getFactory().newColumnMetaData(netAgent_.logWriter_);
1928
1929        parseSQLDHROW(columnMetaData);
1930
1931        // possibly change initializeCache to not new up arrays if
1932
// parseSQLNUMROW returns 0
1933
columnMetaData.initializeCache(parseFastSQLNUMROW());
1934
1935        // is this correct for 0 SQLNUMROW,
1936
// does rest of code expect a null ColumnMetaData object
1937
// or does rest of code expect an non null object
1938
// with columns_ set to 0
1939
for (int i = 0; i < columnMetaData.columns_; i++) {
1940            parseSQLDAROW(columnMetaData, i);
1941        }
1942
1943        return columnMetaData;
1944    }
1945
1946    // SQLDAROW : FDOCA EARLY ROW
1947
// SQL Data Area Row Description
1948
//
1949
// FORMAT FOR ALL SQLAM LEVELS
1950
// SQLDAGRP; GROUP LID 0x50; ELEMENT TAKEN 0(all); REP FACTOR 1
1951
private void parseSQLDAROW(ColumnMetaData columnMetaData,
1952                               int columnNumber) throws DisconnectException {
1953        parseSQLDAGRP(columnMetaData, columnNumber);
1954    }
1955
1956    // SQLDHROW : FDOCA EARLY ROW
1957
// SQL Descriptor Header Row Description
1958
//
1959
// FORMAT FOR SQLAM >= 7
1960
// SQLDHGRP; GROUP LID 0xD0; ELEMENT TAKEN 0(all); REP FACTOR 1
1961
private void parseSQLDHROW(ColumnMetaData columnMetaData) throws DisconnectException {
1962        parseSQLDHGRP(columnMetaData);
1963    }
1964
1965    // SQLRSROW : FDOCA EARLY ROW
1966
// SQL Row Description for One Result Set Row
1967
//
1968
// FORMAT FOR ALL SQLAM LEVELS
1969
// SQLRSGRP; GROUP LID 0x5F; ELEMENT TAKEN 0(all); REP FACTOR 1
1970
private void parseSQLRSROW(Section section) throws DisconnectException {
1971        parseSQLRSGRP(section);
1972    }
1973
1974
1975    // These methods are "private protected", which is not a recognized java privilege,
1976
// but means that these methods are private to this class and to subclasses,
1977
// and should not be used as package-wide friendly methods.
1978

1979    // SQLDAGRP : EARLY FDOCA GROUP
1980
// SQL Data Area Group Description
1981
//
1982
// FORMAT FOR SQLAM <= 6
1983
// SQLPRECISION; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
1984
// SQLSCALE; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
1985
// SQLLENGTH; PROTOCOL TYPE I4; ENVLID 0x02; Length Override 4
1986
// SQLTYPE; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
1987
// SQLCCSID; PROTOCOL TYPE FB; ENVLID 0x26; Length Override 2
1988
// SQLNAME_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 30
1989
// SQLNAME_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 30
1990
// SQLLABEL_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 30
1991
// SQLLABEL_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 30
1992
// SQLCOMMENTS_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 254
1993
// SQLCOMMENTS_m; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 254
1994
//
1995
// FORMAT FOR SQLAM == 6
1996
// SQLPRECISION; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
1997
// SQLSCALE; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
1998
// SQLLENGTH; PROTOCOL TYPE I8; ENVLID 0x16; Length Override 8
1999
// SQLTYPE; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2000
// SQLCCSID; PROTOCOL TYPE FB; ENVLID 0x26; Length Override 2
2001
// SQLNAME_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 30
2002
// SQLNAME_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 30
2003
// SQLLABEL_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 30
2004
// SQLLABEL_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 30
2005
// SQLCOMMENTS_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 254
2006
// SQLCOMMENTS_m; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 254
2007
// SQLUDTGRP; PROTOCOL TYPE N-GDA; ENVLID 0x51; Length Override 0
2008
//
2009
// FORMAT FOR SQLAM >= 7
2010
// SQLPRECISION; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2011
// SQLSCALE; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2012
// SQLLENGTH; PROTOCOL TYPE I8; ENVLID 0x16; Length Override 8
2013
// SQLTYPE; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2014
// SQLCCSID; PROTOCOL TYPE FB; ENVLID 0x26; Length Override 2
2015
// SQLDOPTGRP; PROTOCOL TYPE N-GDA; ENVLID 0xD2; Length Override 0
2016
private void parseSQLDAGRP(ColumnMetaData columnMetaData,
2017                               int columnNumber) throws DisconnectException {
2018        long columnLength = 0;
2019
2020        // 2-byte precision
2021
int precision = readFastShort();
2022
2023        // 2-byte scale
2024
int scale = readFastShort();
2025
2026        // 8 byte sqllength
2027
columnLength = readFastLong();
2028
2029        // create a set method after sqlType and ccsid is read
2030
// possibly have it set the nullable
2031
int sqlType = readFastShort();
2032
2033        // 2-byte sqlccsid
2034
// (NOTE: SQLCCSID is always flown as BIG ENDIAN, not as data!)
2035
// The C-Common Client also does the following:
2036
// 1. Determine which type of code page is to be used for this variable:
2037
// 2. Map the CCSID to the correct codepage:
2038
// 3. "Split" the CCSID to see whether it is for SBCS or MBCS:
2039
int ccsid = readFastUnsignedShort();
2040
2041        columnMetaData.sqlPrecision_[columnNumber] = precision;
2042        columnMetaData.sqlScale_[columnNumber] = scale;
2043        columnMetaData.sqlLength_[columnNumber] = columnLength;
2044        columnMetaData.sqlType_[columnNumber] = sqlType;
2045        // Set the nullables
2046
columnMetaData.nullable_[columnNumber] = Utils.isSqlTypeNullable(sqlType);
2047        columnMetaData.sqlCcsid_[columnNumber] = ccsid;
2048        columnMetaData.types_[columnNumber] =
2049                Types.mapDERBYTypeToDriverType(true, sqlType, columnLength, ccsid); // true means isDescribed
2050
parseSQLDOPTGRP(columnMetaData, columnNumber);
2051    }
2052
2053    // SQLUDTGRP : EARLY FDOCA GROUP
2054
// SQL User-Defined Data Group Description
2055
//
2056
// FORMAT FOR SQLAM >= 7
2057
// SQLUDTXTYPE; PROTOCOL TYPE I4; ENVLID 0X02; Length Override 4
2058
// SQLUDTRDB; PROTOCOL TYPE VCS; ENVLID 0X32; Length Override 255
2059
// SQLUDTSCHEMA_m; PROTOCOL TYPE VCM; ENVLID 0X3E; Length Override 255
2060
// SQLUDTSCHEMA_s; PROTOCOL TYPE VCS; ENVLID 0X32; Length Override 255
2061
// SQLUDTNAME_m; PROTOCOL TYPE VCM; ENVLID 0X3E; Length Override 255
2062
// SQLUDTNAME_s; PROTOCOL TYPE VCS; ENVLID 0X32; Length Override 255
2063
private void parseSQLUDTGRP(ColumnMetaData columnMetaData,
2064                                int columnNumber) throws DisconnectException {
2065        if (readFastUnsignedByte() == CodePoint.NULLDATA) {
2066            return;
2067        }
2068
2069    }
2070
2071    // SQLDOPTGRP : EARLY FDOCA GROUP
2072
// SQL Descriptor Optional Group Description
2073
//
2074
// FORMAT FOR SQLAM >= 7
2075
// SQLUNNAMED; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2076
// SQLNAME_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 255
2077
// SQLNAME_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2078
// SQLLABEL_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 255
2079
// SQLLABEL_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2080
// SQLCOMMENTS_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 255
2081
// SQLCOMMENTS_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2082
// SQLUDTGRP; PROTOCOL TYPE N-GDA; ENVLID 0x5B; Length Override 0
2083
// SQLDXGRP; PROTOCOL TYPE N-GDA; ENVLID 0xD4; Length Override 0
2084
private void parseSQLDOPTGRP(ColumnMetaData columnMetaData,
2085                                 int columnNumber) throws DisconnectException {
2086        if (readFastUnsignedByte() == CodePoint.NULLDATA) {
2087            return;
2088        }
2089
2090        // SQLUNNAMED; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2091
short sqlunnamed = readFastShort();
2092
2093        // SQLNAME_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 255
2094
// SQLNAME_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2095
String JavaDoc name = parseFastVCMorVCS();
2096
2097        // SQLLABEL_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 255
2098
// SQLLABEL_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2099
String JavaDoc label = parseFastVCMorVCS();
2100
2101        // SQLCOMMENTS_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 255
2102
// SQLCOMMENTS_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2103
String JavaDoc colComments = parseFastVCMorVCS();
2104
2105        if (columnMetaData.sqlName_ == null) {
2106            columnMetaData.sqlName_ = new String JavaDoc[columnMetaData.columns_];
2107        }
2108        if (columnMetaData.sqlLabel_ == null) {
2109            columnMetaData.sqlLabel_ = new String JavaDoc[columnMetaData.columns_];
2110        }
2111        if (columnMetaData.sqlUnnamed_ == null) {
2112            columnMetaData.sqlUnnamed_ = new short[columnMetaData.columns_];
2113        }
2114        if (columnMetaData.sqlComment_ == null) {
2115            columnMetaData.sqlComment_ = new String JavaDoc[columnMetaData.columns_];
2116        }
2117        columnMetaData.sqlName_[columnNumber] = name;
2118        columnMetaData.sqlLabel_[columnNumber] = label;
2119        columnMetaData.sqlUnnamed_[columnNumber] = sqlunnamed;
2120        columnMetaData.sqlComment_[columnNumber] = colComments;
2121
2122        // possibly move all the assignments into a single method on the columnMetaData object
2123

2124        parseSQLUDTGRP(columnMetaData, columnNumber);
2125        parseSQLDXGRP(columnMetaData, columnNumber);
2126    }
2127
2128    // SQLDXGRP : EARLY FDOCA GROUP
2129
// SQL Descriptor Extended Group Description
2130
//
2131
// FORMAT FOR SQLAM >=7
2132
// SQLXKEYMEM; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2133
// SQLXUPDATEABLE; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2134
// SQLXGENERATED; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2135
// SQLXPARMMODE; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2136
// SQLXRDBNAM; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2137
// SQLXCORNAME_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 255
2138
// SQLXCORNAME_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2139
// SQLXBASENAME_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 255
2140
// SQLXBASENAME_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2141
// SQLXSCHEMA_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 255
2142
// SQLXSCHEMA_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2143
// SQLXNAME_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 255
2144
// SQLXNAME_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2145
private void parseSQLDXGRP(ColumnMetaData columnMetaData,
2146                               int column) throws DisconnectException {
2147        if (readFastUnsignedByte() == CodePoint.NULLDATA) {
2148            return;
2149        }
2150
2151
2152        // SQLXKEYMEM; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2153
short sqlxkeymem = readFastShort();
2154
2155        // SQLXUPDATEABLE; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2156
short sqlxupdateable = readFastShort();
2157
2158        // SQLXGENERATED; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2159
short sqlxgenerated = readFastShort();
2160
2161        // SQLXPARMMODE; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2162
short sqlxparmmode = readFastShort();
2163
2164        // SQLXRDBNAM; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2165
String JavaDoc sqlxrdbnam = parseFastVCS();
2166
2167        // SQLXCORNAME_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 255
2168
// SQLXCORNAME_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2169
String JavaDoc sqlxcorname = parseFastVCMorVCS();
2170
2171        // SQLXBASENAME_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 255
2172
// SQLXBASENAME_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2173
String JavaDoc sqlxbasename = parseFastVCMorVCS();
2174
2175        // SQLXSCHEMA_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 255
2176
// SQLXSCHEMA_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2177
String JavaDoc sqlxschema = parseFastVCMorVCS();
2178
2179        // SQLXNAME_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 255
2180
// SQLXNAME_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2181
String JavaDoc sqlxname = parseFastVCMorVCS();
2182
2183        if (columnMetaData.sqlxKeymem_ == null) {
2184            columnMetaData.sqlxKeymem_ = new short[columnMetaData.columns_];
2185        }
2186        if (columnMetaData.sqlxGenerated_ == null) {
2187            columnMetaData.sqlxGenerated_ = new short[columnMetaData.columns_];
2188        }
2189        if (columnMetaData.sqlxParmmode_ == null) {
2190            columnMetaData.sqlxParmmode_ = new short[columnMetaData.columns_];
2191        }
2192        if (columnMetaData.sqlxCorname_ == null) {
2193            columnMetaData.sqlxCorname_ = new String JavaDoc[columnMetaData.columns_];
2194        }
2195        if (columnMetaData.sqlxName_ == null) {
2196            columnMetaData.sqlxName_ = new String JavaDoc[columnMetaData.columns_];
2197        }
2198        if (columnMetaData.sqlxBasename_ == null) {
2199            columnMetaData.sqlxBasename_ = new String JavaDoc[columnMetaData.columns_];
2200        }
2201        if (columnMetaData.sqlxUpdatable_ == null) {
2202            columnMetaData.sqlxUpdatable_ = new int[columnMetaData.columns_];
2203        }
2204        if (columnMetaData.sqlxSchema_ == null) {
2205            columnMetaData.sqlxSchema_ = new String JavaDoc[columnMetaData.columns_];
2206        }
2207        if (columnMetaData.sqlxRdbnam_ == null) {
2208            columnMetaData.sqlxRdbnam_ = new String JavaDoc[columnMetaData.columns_];
2209        }
2210
2211        columnMetaData.sqlxKeymem_[column] = sqlxkeymem;
2212        columnMetaData.sqlxGenerated_[column] = sqlxgenerated;
2213        columnMetaData.sqlxParmmode_[column] = sqlxparmmode;
2214        columnMetaData.sqlxCorname_[column] = sqlxcorname;
2215        columnMetaData.sqlxName_[column] = sqlxname;
2216        columnMetaData.sqlxBasename_[column] = sqlxbasename;
2217        columnMetaData.sqlxUpdatable_[column] = sqlxupdateable;
2218        columnMetaData.sqlxSchema_[column] = (sqlxschema == null) ? columnMetaData.sqldSchema_ : sqlxschema;
2219        columnMetaData.sqlxRdbnam_[column] = (sqlxrdbnam == null) ? columnMetaData.sqldRdbnam_ : sqlxrdbnam;
2220    }
2221
2222    // SQLDHGRP : EARLY FDOCA GROUP
2223
// SQL Descriptor Header Group Description
2224
//
2225
// FORMAT FOR SQLAM >= 7
2226
// SQLDHOLD; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2227
// SQLDRETURN; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2228
// SQLDSCROLL; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2229
// SQLDSENSITIVE; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2230
// SQLDFCODE; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2231
// SQLDKEYTYPE; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2232
// SQLDRDBNAM; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2233
// SQLDSCHEMA_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 255
2234
// SQLDSCHEMA_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2235
private void parseSQLDHGRP(ColumnMetaData columnMetaData) throws DisconnectException {
2236        if (readFastUnsignedByte() == CodePoint.NULLDATA) {
2237            return;
2238        }
2239
2240
2241        // SQLDHOLD; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2242
short sqldhold = readFastShort();
2243
2244        // SQLDRETURN; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2245
short sqldreturn = readFastShort();
2246
2247        // SQLDSCROLL; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2248
short sqldscroll = readFastShort();
2249
2250        // SQLDSENSITIVE; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2251
short sqldsensitive = readFastShort();
2252
2253        // SQLDFCODE; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2254
short sqldfcode = readFastShort();
2255
2256        // SQLDKEYTYPE; PROTOCOL TYPE I2; ENVLID 0x04; Length Override 2
2257
short sqldkeytype = readFastShort();
2258
2259        // SQLDRDBNAM; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2260
String JavaDoc sqldrdbnam = parseFastVCS();
2261
2262        // SQLDSCHEMA_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 255
2263
// SQLDSCHEMA_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2264
String JavaDoc sqldschema = parseFastVCMorVCS();
2265
2266        columnMetaData.sqldHold_ = sqldhold;
2267        columnMetaData.sqldReturn_ = sqldreturn;
2268        columnMetaData.sqldScroll_ = sqldscroll;
2269        columnMetaData.sqldSensitive_ = sqldsensitive;
2270        columnMetaData.sqldFcode_ = sqldfcode;
2271        columnMetaData.sqldKeytype_ = sqldkeytype;
2272        columnMetaData.sqldRdbnam_ = sqldrdbnam;
2273        columnMetaData.sqldSchema_ = sqldschema;
2274    }
2275
2276    // SQLRSGRP : EARLY FDOCA GROUP
2277
// SQL Result Set Group Description
2278
//
2279
// FORMAT FOR SQLAM >= 7
2280
// SQLRSLOCATOR; PROTOCOL TYPE RSL; ENVLID 0x14; Length Override 4
2281
// SQLRSNAME_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 255
2282
// SQLRSNAME_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255
2283
// SQLRSNUMROWS; PROTOCOL TYPE I4; ENVLID 0x02; Length Override 4
2284
private void parseSQLRSGRP(Section section) throws DisconnectException {
2285
2286        int rsLocator = readInt();
2287        String JavaDoc rsName = parseVCMorVCS(); // ignore length change bt SQLAM 6 and 7
2288
int rsNumRows = readInt();
2289        // currently rsLocator and rsNumRows are not being used.
2290
section.setCursorName(rsName);
2291    }
2292
2293
2294    // this is duplicated in parseColumnMetaData, but different
2295
// DAGroup under NETColumnMetaData requires a lot more stuffs including
2296
// precsion, scale and other stuffs
2297
private String JavaDoc parseFastVCMorVCS() throws DisconnectException {
2298        String JavaDoc stringToBeSet = null;
2299
2300        int vcm_length = readFastUnsignedShort();
2301        if (vcm_length > 0) {
2302            stringToBeSet = readFastString(vcm_length, netAgent_.targetTypdef_.getCcsidMbcEncoding());
2303        }
2304        int vcs_length = readFastUnsignedShort();
2305        if (vcm_length > 0 && vcs_length > 0) {
2306            agent_.accumulateChainBreakingReadExceptionAndThrow(new DisconnectException(agent_,
2307                new ClientMessageId(SQLState.NET_VCM_VCS_LENGTHS_INVALID)));
2308        } else if (vcs_length > 0) {
2309            stringToBeSet = readFastString(vcs_length, netAgent_.targetTypdef_.getCcsidSbcEncoding());
2310        }
2311
2312        return stringToBeSet;
2313    }
2314
2315    private String JavaDoc parseVCMorVCS() throws DisconnectException {
2316        String JavaDoc stringToBeSet = null;
2317
2318        int vcm_length = readUnsignedShort();
2319        if (vcm_length > 0) {
2320            stringToBeSet = readString(vcm_length, netAgent_.targetTypdef_.getCcsidMbcEncoding());
2321        }
2322        int vcs_length = readUnsignedShort();
2323        if (vcm_length > 0 && vcs_length > 0) {
2324            agent_.accumulateChainBreakingReadExceptionAndThrow(new DisconnectException(agent_,
2325                new ClientMessageId(SQLState.NET_VCM_VCS_LENGTHS_INVALID)));
2326        } else if (vcs_length > 0) {
2327            stringToBeSet = readString(vcs_length, netAgent_.targetTypdef_.getCcsidSbcEncoding());
2328        }
2329
2330        return stringToBeSet;
2331    }
2332
2333    //----------------------non-parsing computational helper methods--------------
2334
private int calculateResultSetType(int qryattscr, int qryattsns, int defaultType) {
2335        // We are passing in defaultType "FOWARD_ONLY", in case desired type
2336
// cannot be obtained,we don't want to set the type to Statement's type,
2337
// but we will set it to the default.
2338

2339        if (qryattscr == 0xF0) {
2340            return java.sql.ResultSet.TYPE_FORWARD_ONLY;
2341        }
2342
2343        switch (qryattsns) {
2344        case CodePoint.QRYINS:
2345            return java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE;
2346        default:
2347            return defaultType;
2348        }
2349    }
2350
2351    private int calculateResultSetConcurrency(int qryattupd, int defaultConcurrency) {
2352        // QRYATTUPD does come back for forward-only cursors if the desired concurrency cannot be
2353
// obtained, in which case we don't want to set the concurrency to the default, but
2354
// we want to set it to the actual concurrency.
2355
switch (qryattupd) {
2356        case CodePoint.QRYRDO:
2357            return java.sql.ResultSet.CONCUR_READ_ONLY;
2358        case CodePoint.QRYUPD:
2359            return java.sql.ResultSet.CONCUR_UPDATABLE;
2360        default:
2361            return defaultConcurrency;
2362        }
2363    }
2364
2365    private int calculateResultSetHoldability(int sqlcsrhld) {
2366        if (sqlcsrhld == 0xF0) {
2367            return JDBC30Translation.CLOSE_CURSORS_AT_COMMIT;
2368        } else {
2369            return JDBC30Translation.HOLD_CURSORS_OVER_COMMIT;
2370        }
2371    }
2372
2373    private int parseSQLDTAGRPdataLabelsAndUpdateColumn(NetCursor cursor, int columnIndex, int tripletLength)
2374            throws DisconnectException {
2375        int numColumns = (tripletLength - 3) / 3;
2376        for (int i = columnIndex; i < columnIndex + numColumns; i++) {
2377            cursor.qrydscTypdef_.updateColumn(cursor, i, readFastUnsignedByte(), readFastUnsignedShort());
2378        }
2379        return numColumns;
2380    }
2381
2382
2383    private String JavaDoc parseSQLSTT() throws DisconnectException {
2384        parseLengthAndMatchCodePoint(CodePoint.SQLSTT);
2385        return parseSQLSTTGRP();
2386    }
2387
2388    private String JavaDoc parseSQLSTTGRP() throws DisconnectException {
2389        int mixedNullInd = readUnsignedByte();
2390        int singleNullInd = 0;
2391        String JavaDoc sqlsttString = null;
2392        int stringLength = 0;
2393
2394        if (mixedNullInd == CodePoint.NULLDATA) {
2395            singleNullInd = readUnsignedByte();
2396            if (singleNullInd == CodePoint.NULLDATA) {
2397                // throw DTAMCHRM
2398
doDtamchrmSemantics();
2399            }
2400            // read 4-byte length
2401
stringLength = readInt();
2402            // read sqlstt string
2403
sqlsttString = readString(stringLength, netAgent_.targetTypdef_.getCcsidSbcEncoding());
2404        } else {
2405            // read 4-byte length
2406
stringLength = readInt();
2407            // read sqlstt string
2408
sqlsttString = readString(stringLength, netAgent_.targetTypdef_.getCcsidMbcEncoding());
2409            // read null indicator
2410
singleNullInd = readUnsignedByte();
2411        }
2412        return sqlsttString;
2413    }
2414
2415    public void readSetSpecialRegister(StatementCallbackInterface statement) throws DisconnectException {
2416        startSameIdChainParse();
2417        parseEXCSQLSETreply(statement);
2418        endOfSameIdChainData();
2419    }
2420}
2421
2422
2423
2424
2425
Popular Tags