Skip to content
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

Merged
merged 3 commits into from
Dec 9, 2016
Merged

Read SQL Server error message if status flag has DONE_ERROR set. #73

merged 3 commits into from
Dec 9, 2016

Conversation

Suraiya-Hameed
Copy link
Contributor

When using client side cursors, if end of TDS packet is reached, check the status flag for error and handle it.

@@ -16,6 +16,7 @@ local.properties
.classpath
.settings/
.loadpath
*.class
Copy link
Contributor

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) {
Copy link
Contributor

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() ?

Copy link
Contributor Author

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) {
Copy link
Contributor

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 ?

Copy link
Contributor Author

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();
Copy link
Contributor

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 = ...
                 .....
           } 
   }
}

Copy link
Contributor Author

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.

@xiangyushawn xiangyushawn merged commit 13fe3e8 into microsoft:dev Dec 9, 2016
@lilgreenbird lilgreenbird added this to Closed/Merged PRs in MSSQL JDBC Apr 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
MSSQL JDBC
  
Closed/Merged PRs
Development

Successfully merging this pull request may close these issues.

None yet

3 participants