-
Notifications
You must be signed in to change notification settings - Fork 431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Read SQL Server error message if status flag has DONE_ERROR set. #73
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6844,6 +6844,17 @@ final int peekTokenType() throws SQLServerException | |
return currentPacket.payload[payloadOffset] & 0xFF; | ||
} | ||
|
||
|
||
final short peekStatusFlag() throws SQLServerException { | ||
// skip the current packet(i.e, TDS packet type) and peek into the status flag (USHORT) | ||
if (payloadOffset + 3 <= currentPacket.payloadLength) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we check it is not the end of payload using ensurePayload() ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ensurePayload() makes sense only for packet type. Since we already have determined the packet type to be TDS_DONE, there must be a status flag that follows as per TDS standards. |
||
short value = Util.readShort(currentPacket.payload, payloadOffset + 1); | ||
return value; | ||
} | ||
|
||
return Util.readShort(readWrappedBytes(3), 1); | ||
} | ||
|
||
final int readUnsignedByte() throws SQLServerException | ||
{ | ||
// Ensure that we have a packet to read from. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -327,13 +327,25 @@ boolean onError(TDSReader tdsReader) throws SQLServerException | |
return false; | ||
} | ||
|
||
boolean onDone(TDSReader tdsReader) throws SQLServerException | ||
{ | ||
// When initializing client-cursored ResultSets, a DONE token | ||
// following the column metadata indicates an empty result set. | ||
rowCount = 0; | ||
return false; | ||
} | ||
boolean onDone(TDSReader tdsReader) throws SQLServerException { | ||
// When initializing client-cursored ResultSets, a DONE token | ||
// following the column metadata indicates an empty result set. | ||
rowCount = 0; | ||
|
||
// Continue to read the error message if DONE packet has error flag | ||
int packetType = tdsReader.peekTokenType(); | ||
if (TDS.TDS_DONE == packetType) { | ||
short status = tdsReader.peekStatusFlag(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SUGGESTION: You can add one method in TDSReader.
Usage might be...
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function of methods in TDSReader are restricted to read operation, it doesn't do any data validation, it's good to keep it that way. |
||
if ((status & 0x0002) != 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we add a comment to explain why we need this & 0x0002 ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure, will do that. |
||
// Consume the DONE packet if there is error | ||
StreamDone doneToken = new StreamDone(); | ||
doneToken.setFromTDS(tdsReader); | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
|
||
this.stmt = stmtIn; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we can create a separate PR for this