Read SQL Server error message if status flag has DONE_ERROR set.#73
Read SQL Server error message if status flag has DONE_ERROR set.#73xiangyushawn merged 3 commits intomicrosoft:devfrom Suraiya-Hameed:dev
Conversation
| .classpath | ||
| .settings/ | ||
| .loadpath | ||
| *.class |
There was a problem hiding this comment.
I guess we can create a separate PR for this
|
|
||
| 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.
should we check it is not the end of payload using ensurePayload() ?
There was a problem hiding this comment.
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.
| int packetType = tdsReader.peekTokenType(); | ||
| if (TDS.TDS_DONE == packetType) { | ||
| short status = tdsReader.peekStatusFlag(); | ||
| if ((status & 0x0002) != 0) { |
There was a problem hiding this comment.
can we add a comment to explain why we need this & 0x0002 ?
There was a problem hiding this comment.
sure, will do that.
| // 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.
SUGGESTION: You can add one method in TDSReader.
boolean isError() throws SQLServerException {
//Get Status.
short status = peekStatusFlag();
return (status & 0x0002) != 0;
}
Usage might be...
Boolean onDone(TDSReader tdsReader) throws SQLServerException {
...
...
if(TDS.TDS_DONE == packetType) {
if(tdsReader.isError()) {
StreamDone doneTaken = ...
.....
}
}
}
There was a problem hiding this comment.
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.
When using client side cursors, if end of TDS packet is reached, check the status flag for error and handle it.