📄 netcursor.java
字号:
// so there is no need to drive a flowFetch (continue query) request for singleton select. if (position_ == lastValidBytePosition_) { // Check for ENDQRYRM, throw SqlException if already received one. checkAndThrowReceivedEndqryrm(); // Send CNTQRY to complete the row/rowset. int lastValidByteBeforeFetch = completeSplitRow(); // if lastValidBytePosition_ has not changed, and an ENDQRYRM was received, // throw a SqlException for the ENDQRYRM. checkAndThrowReceivedEndqryrm(lastValidByteBeforeFetch); } return dataBuffer_[position_++] & 0xff; } // Reads 1-byte from the dataBuffer from the current position. // If position is already at the end of the buffer, send CNTQRY to get more data. private int readFdocaOneByte(int index) throws org.apache.derby.client.am.DisconnectException, SqlException { // For singleton select, the complete row always comes back, even if multiple query blocks are required, // so there is no need to drive a flowFetch (continue query) request for singleton select. if (position_ == lastValidBytePosition_) { // Check for ENDQRYRM, throw SqlException if already received one. checkAndThrowReceivedEndqryrm(); // Send CNTQRY to complete the row/rowset. int lastValidByteBeforeFetch = completeSplitRow(index); // if lastValidBytePosition_ has not changed, and an ENDQRYRM was received, // throw a SqlException for the ENDQRYRM. checkAndThrowReceivedEndqryrm(lastValidByteBeforeFetch); } return dataBuffer_[position_++] & 0xff; } // Reads <i>length</i> number of bytes from the dataBuffer starting from the // current position. Returns a new byte array which contains the bytes read. // If current position plus length goes past the lastValidBytePosition, send // CNTQRY to get more data. private byte[] readFdocaBytes(int length) throws org.apache.derby.client.am.DisconnectException, SqlException { byte[] b = new byte[length]; ; // For singleton select, the complete row always comes back, even if multiple query blocks are required, // so there is no need to drive a flowFetch (continue query) request for singleton select. if ((position_ + length) > lastValidBytePosition_) { // Check for ENDQRYRM, throw SqlException if already received one. checkAndThrowReceivedEndqryrm(); // Send CNTQRY to complete the row/rowset. int lastValidByteBeforeFetch = completeSplitRow(); // if lastValidBytePosition_ has not changed, and an ENDQRYRM was received, // throw a SqlException for the ENDQRYRM. checkAndThrowReceivedEndqryrm(lastValidByteBeforeFetch); } for (int i = 0; i < length; i++) { b[i] = dataBuffer_[position_++]; } return b; } // Reads 2-bytes from the dataBuffer starting from the current position, and // returns an integer constructed from the 2-bytes. If current position plus // 2 bytes goes past the lastValidBytePosition, send CNTQRY to get more data. private int readFdocaTwoByteLength() throws org.apache.derby.client.am.DisconnectException, SqlException { // For singleton select, the complete row always comes back, even if multiple query blocks are required, // so there is no need to drive a flowFetch (continue query) request for singleton select. if ((position_ + 2) > lastValidBytePosition_) { // Check for ENDQRYRM, throw SqlException if already received one. checkAndThrowReceivedEndqryrm(); // Send CNTQRY to complete the row/rowset. int lastValidByteBeforeFetch = completeSplitRow(); // if lastValidBytePosition_ has not changed, and an ENDQRYRM was received, // throw a SqlException for the ENDQRYRM. checkAndThrowReceivedEndqryrm(lastValidByteBeforeFetch); } return ((dataBuffer_[position_++] & 0xff) << 8) + ((dataBuffer_[position_++] & 0xff) << 0); } private int readFdocaTwoByteLength(int index) throws org.apache.derby.client.am.DisconnectException, SqlException { // For singleton select, the complete row always comes back, even if multiple query blocks are required, // so there is no need to drive a flowFetch (continue query) request for singleton select. if ((position_ + 2) > lastValidBytePosition_) { // Check for ENDQRYRM, throw SqlException if already received one. checkAndThrowReceivedEndqryrm(); // Send CNTQRY to complete the row/rowset. int lastValidByteBeforeFetch = completeSplitRow(index); // if lastValidBytePosition_ has not changed, and an ENDQRYRM was received, // throw a SqlException for the ENDQRYRM. checkAndThrowReceivedEndqryrm(lastValidByteBeforeFetch); } return ((dataBuffer_[position_++] & 0xff) << 8) + ((dataBuffer_[position_++] & 0xff) << 0); } // Check if position plus length goes past the lastValidBytePosition. // If so, send CNTQRY to get more data. // length - number of bytes to skip // returns the number of bytes skipped private int skipFdocaBytes(int length) throws org.apache.derby.client.am.DisconnectException, SqlException { // For singleton select, the complete row always comes back, even if multiple query blocks are required, // so there is no need to drive a flowFetch (continue query) request for singleton select. if ((position_ + length) > lastValidBytePosition_) { // Check for ENDQRYRM, throw SqlException if already received one. checkAndThrowReceivedEndqryrm(); // Send CNTQRY to complete the row/rowset. int lastValidByteBeforeFetch = completeSplitRow(); // if lastValidBytePosition_ has not changed, and an ENDQRYRM was received, // throw a SqlException for the ENDQRYRM. checkAndThrowReceivedEndqryrm(lastValidByteBeforeFetch); } position_ += length; return length; } private int skipFdocaBytes(int length, int index) throws org.apache.derby.client.am.DisconnectException, SqlException { // For singleton select, the complete row always comes back, even if multiple query blocks are required, // so there is no need to drive a flowFetch (continue query) request for singleton select. if ((position_ + length) > lastValidBytePosition_) { // Check for ENDQRYRM, throw SqlException if already received one. checkAndThrowReceivedEndqryrm(); // Send CNTQRY to complete the row/rowset. int lastValidByteBeforeFetch = completeSplitRow(index); // if lastValidBytePosition_ has not changed, and an ENDQRYRM was received, // throw a SqlException for the ENDQRYRM. checkAndThrowReceivedEndqryrm(lastValidByteBeforeFetch); } position_ += length; return length; } // Shift partial row bytes to beginning of dataBuffer, // and resets current row position, and lastValidBytePosition. // When we shift partial row, we'll have to recalculate column offsets // up to this column. private void shiftPartialRowToBeginning() { // Get the length to shift from the beginning of the partial row. int length = lastValidBytePosition_ - currentRowPosition_; // shift the data in the dataBufferStream dataBufferStream_.reset(); if (dataBuffer_ != null) { dataBufferStream_.write(dataBuffer_, currentRowPosition_, length); } for (int i = 0; i < length; i++) { dataBuffer_[i] = dataBuffer_[currentRowPosition_ + i]; } position_ = length - (lastValidBytePosition_ - position_); lastValidBytePosition_ = length; } private void adjustColumnOffsetsForColumnsPreviouslyCalculated(int index) { for (int j = 0; j <= index; j++) { columnDataPosition_[j] -= currentRowPosition_; } } private void resetCurrentRowPosition() { currentRowPosition_ = 0; } // Calculates the column index for Lob objects constructed from EXTDTA data. // Describe information isn't sufficient because we have to check // for trivial values (nulls or zero-length) and exclude them. void calculateLobColumnPositionsForRow() { int currentPosition = 0; for (int i = 0; i < columns_; i++) { if (isNonTrivialDataLob(i)) // key = column position, data = index to corresponding data in extdtaData_ // ASSERT: the server always returns the EXTDTA objects in ascending order { extdtaPositions_.put(new Integer(i + 1), new Integer(currentPosition++)); } } } // prereq: the base data for the cursor has been processed for offsets and lengths boolean isNonTrivialDataLob(int index) { long length = 0L; if (isNull_[index] || (jdbcTypes_[index] != Types.BLOB && jdbcTypes_[index] != Types.CLOB)) { return false; } int position = columnDataPosition_[index]; // if the high-order bit is set, length is unknown -> set value to x'FF..FF' if (((dataBuffer_[position]) & 0x80) == 0x80) { length = -1; } else { byte[] lengthBytes = new byte[columnDataComputedLength_[index]]; byte[] longBytes = new byte[8]; System.arraycopy(dataBuffer_, position, lengthBytes, 0, columnDataComputedLength_[index]); // right-justify for BIG ENDIAN int j = 0; for (int i = 8 - columnDataComputedLength_[index]; i < 8; i++) { longBytes[i] = lengthBytes[j]; j++; } length = SignedBinary.getLong(longBytes, 0); } return (length != 0L) ? true : false; } protected void clearLobData_() { extdtaData_.clear(); extdtaPositions_.clear(); } // SQLCARD : FDOCA EARLY ROW // SQL Communications Area Row Description // // FORMAT FOR ALL SQLAM LEVELS // SQLCAGRP; GROUP LID 0x54; ELEMENT TAKEN 0(all); REP FACTOR 1 NetSqlca parseSQLCARD(Typdef typdef) throws org.apache.derby.client.am.DisconnectException, SqlException { return parseSQLCAGRP(typdef); } // SQLCAGRP : FDOCA EARLY GROUP // SQL Communcations Area Group Description // // FORMAT FOR SQLAM <= 6 // SQLCODE; PROTOCOL TYPE I4; ENVLID 0x02; Length Override 4 // SQLSTATE; PROTOCOL TYPE FCS; ENVLID 0x30; Length Override 5 // SQLERRPROC; PROTOCOL TYPE FCS; ENVLID 0x30; Length Override 8 // SQLCAXGRP; PROTOCOL TYPE N-GDA; ENVLID 0x52; Length Override 0 // // FORMAT FOR SQLAM >= 7 // SQLCODE; PROTOCOL TYPE I4; ENVLID 0x02; Length Override 4 // SQLSTATE; PROTOCOL TYPE FCS; ENVLID 0x30; Length Override 5 // SQLERRPROC; PROTOCOL TYPE FCS; ENVLID 0x30; Length Override 8 // SQLCAXGRP; PROTOCOL TYPE N-GDA; ENVLID 0x52; Length Override 0 // SQLDIAGGRP; PROTOCOL TYPE N-GDA; ENVLID 0x56; Length Override 0 private NetSqlca parseSQLCAGRP(Typdef typdef) throws org.apache.derby.client.am.DisconnectException, SqlException { if (readFdocaOneByte() == CodePoint.NULLDATA) { return null; } int sqlcode = readFdocaInt(); byte[] sqlstate = readFdocaBytes(5); byte[] sqlerrproc = readFdocaBytes(8); NetSqlca netSqlca = new NetSqlca(netAgent_.netConnection_, sqlcode, sqlstate, sqlerrproc, typdef.getCcsidSbc()); parseSQLCAXGRP(typdef, netSqlca); parseSQLDIAGGRP(); return netSqlca; } // SQLCAXGRP : EARLY FDOCA GROUP // SQL Communications Area Exceptions Group Description // // FORMAT FOR SQLAM <= 6 // SQLRDBNME; PROTOCOL TYPE FCS; ENVLID 0x30; Length Override 18 // SQLERRD1; PROTOCOL TYPE I4; ENVLID 0x02; Length Override 4 // SQLERRD2; PROTOCOL TYPE I4; ENVLID 0x02; Length Override 4 // SQLERRD3; PROTOCOL TYPE I4; ENVLID 0x02; Length Override 4 // SQLERRD4; PROTOCOL TYPE I4; ENVLID 0x02; Length Override 4 // SQLERRD5; PROTOCOL TYPE I4; ENVLID 0x02; Length Override 4 // SQLERRD6; PROTOCOL TYPE I4; ENVLID 0x02; Length Override 4 // SQLWARN0; PROTOCOL TYPE FCS; ENVLID 0x30; Length Override 1 // SQLWARN1; PROTOCOL TYPE FCS; ENVLID 0x30; Length Override 1 // SQLWARN2; PROTOCOL TYPE FCS; ENVLID 0x30; Length Override 1 // SQLWARN3; PROTOCOL TYPE FCS; ENVLID 0x30; Length Override 1 // SQLWARN4; PROTOCOL TYPE FCS; ENVLID 0x30; Length Override 1 // SQLWARN5; PROTOCOL TYPE FCS; ENVLID 0x30; Length Override 1 // SQLWARN6; PROTOCOL TYPE FCS; ENVLID 0x30; Length Override 1 // SQLWARN7; PROTOCOL TYPE FCS; ENVLID 0x30; Length Override 1 // SQLWARN8; PROTOCOL TYPE FCS; ENVLID 0x30; Length Override 1 // SQLWARN9; PROTOCOL TYPE FCS; ENVLID 0x30; Length Override 1 // SQLWARNA; PROTOCOL TYPE FCS; ENVLID 0x30; Length Override 1 // SQLERRMSG_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 70 // SQLERRMSG_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 70 // // FORMAT FOR SQLAM >= 7 // SQLERRD1; PROTOCOL TYPE I4; ENVLID 0x02; Length Override 4 // SQLERRD2; PROTOCOL TYPE I4; ENVLID 0x02; Length Override 4 // SQLERRD3; PROTOCOL TYPE I4; ENVLID 0x02; Length Override 4 // SQLERRD4; PROTOCOL TYPE I4; ENVLID 0x02; Length Override 4 // SQLERRD5; PROTOCOL TYPE I4; ENVLID 0x02; Length Override 4 // SQLERRD6; PROTOCOL TYPE I4; ENVLID 0x02; Length Override 4 // SQLWARN0; PROTOCOL TYPE FCS; ENVLID 0x30; Length Override 1 // SQLWARN1; PROTOCOL TYPE FCS; ENVLID 0x30; Length Override 1 // SQLWARN2; PROTOCOL TYPE FCS; ENVLID 0x30; Length Override 1 // SQLWARN3; PROTOCOL TYPE FCS; ENVLID 0x30; Length Override 1 // SQLWARN4; PROTOCOL TYPE FCS; ENVLID 0x30; Length Override 1 // SQLWARN5; PROTOCOL TYPE FCS; ENVLID 0x30; Length Override 1 // SQLWARN6; PROTOCOL TYPE FCS; ENVLID 0x30; Length Override 1 // SQLWARN7; PROTOCOL TYPE FCS; ENVLID 0x30; Length Override 1 // SQLWARN8; PROTOCOL TYPE FCS; ENVLID 0x30; Length Override 1 // SQLWARN9; PROTOCOL TYPE FCS; ENVLID 0x30; Length Override 1 // SQLWARNA; PROTOCOL TYPE FCS; ENVLID 0x30; Length Override 1 // SQLRDBNAME; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255 // SQLERRMSG_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 70 // SQLERRMSG_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 70 private void parseSQLCAXGRP(Typdef typdef, NetSqlca netSqlca) throws DisconnectException, SqlException { if (readFdocaOneByte() == CodePoint.NULLDATA) { netSqlca.setContainsSqlcax(false); return; } // SQLERRD1 to SQLERRD6; PROTOCOL TYPE I4; ENVLID 0x02; Length Override 4 int[] sqlerrd = new int[6]; for (int i = 0; i < sqlerrd.length; i++) { sqlerrd[i] = readFdocaInt(); } // SQLWARN0 to SQLWARNA; PROTOCOL TYPE FCS; ENVLID 0x30; Length Override 1 byte[] sqlwarn = readFdocaBytes(11); // skip over the rdbnam for now // SQLRDBNAME; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 255 parseVCS(typdef); // SQLERRMSG_m; PROTOCOL TYPE VCM; ENVLID 0x3E; Length Override 70 // SQLERRMSG_s; PROTOCOL TYPE VCS; ENVLID 0x32; Length Override 70 int varcharLength = readFdocaTwoByteLength(); // mixed length byte[] sqlerrmc = null; int sqlerrmcCcsid = 0; if (varcharLength != 0) { // if mixed sqlerrmc = readFdocaBytes(varcharLength); // read mixed bytes sqlerrmcCcsid = typdef.getCcsidMbc();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -