-
Notifications
You must be signed in to change notification settings - Fork 426
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
Conversation
@@ -16,6 +16,7 @@ local.properties | |||
.classpath | |||
.settings/ | |||
.loadpath | |||
*.class |
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
|
||
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 comment
The 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 comment
The 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.
int packetType = tdsReader.peekTokenType(); | ||
if (TDS.TDS_DONE == packetType) { | ||
short status = tdsReader.peekStatusFlag(); | ||
if ((status & 0x0002) != 0) { |
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The 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.
When using client side cursors, if end of TDS packet is reached, check the status flag for error and handle it.