-
Notifications
You must be signed in to change notification settings - Fork 454
Improvement | Added new APIs to retrieve SQL Server error information received with SQLServerException #905
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cf1c4cc
Improvement | Added new APIs to retrieve SQL Server error information…
cheenamalhotra 819e89b
Serialize newly added public class.
cheenamalhotra 069ca70
Minor changes
cheenamalhotra f2645ca
Add tests
cheenamalhotra 0f73e03
Remove unwanted Exception check
cheenamalhotra 0c665d7
Remove hostname comparison + reflect review comments
cheenamalhotra 03c6f10
Organize Imports (all files)
cheenamalhotra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
src/main/java/com/microsoft/sqlserver/jdbc/SQLServerError.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| /* | ||
| * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made | ||
| * available under the terms of the MIT License. See the LICENSE file in the project root for more information. | ||
| */ | ||
|
|
||
| package com.microsoft.sqlserver.jdbc; | ||
|
|
||
| import java.io.Serializable; | ||
|
|
||
| /** | ||
| * StreamError represents a TDS error or message event. | ||
| */ | ||
|
|
||
cheenamalhotra marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public final class SQLServerError extends StreamPacket implements Serializable { | ||
| /** | ||
| * Always update serialVersionUID when prompted | ||
| */ | ||
| private static final long serialVersionUID = -7304033613218700719L; | ||
| private String errorMessage = ""; | ||
| private int errorNumber; | ||
| private int errorState; | ||
| private int errorSeverity; | ||
| private String serverName; | ||
| private String procName; | ||
| private long lineNumber; | ||
|
|
||
| /** | ||
| * Returns error message as received from SQL Server | ||
| * | ||
| * @return Error Message | ||
| */ | ||
| public String getErrorMessage() { | ||
| return errorMessage; | ||
| } | ||
|
|
||
| /** | ||
| * Returns error number as received from SQL Server | ||
| * | ||
| * @return Error Number | ||
| */ | ||
| public int getErrorNumber() { | ||
| return errorNumber; | ||
| } | ||
|
|
||
| /** | ||
| * Returns error state as received from SQL Server | ||
| * | ||
| * @return Error State | ||
| */ | ||
| public int getErrorState() { | ||
| return errorState; | ||
| } | ||
|
|
||
| /** | ||
| * Returns Severity of error (as int value) as received from SQL Server | ||
| * | ||
| * @return Error Severity | ||
| */ | ||
| public int getErrorSeverity() { | ||
| return errorSeverity; | ||
| } | ||
|
|
||
| /** | ||
| * Returns name of the server where exception occurs as received from SQL Server | ||
| * | ||
| * @return Server Name | ||
| */ | ||
| public String getServerName() { | ||
| return serverName; | ||
| } | ||
|
|
||
| /** | ||
| * Returns name of the stored procedure where exception occurs as received from SQL Server | ||
| * | ||
| * @return Procedure Name | ||
| */ | ||
| public String getProcedureName() { | ||
| return procName; | ||
| } | ||
|
|
||
| /** | ||
| * Returns line number where the error occurred in Stored Procedure returned by <code>getProcedureName()</code> as | ||
| * received from SQL Server | ||
| * | ||
| * @return Line Number | ||
| */ | ||
| public long getLineNumber() { | ||
| return lineNumber; | ||
| } | ||
|
|
||
| SQLServerError() { | ||
| super(TDS.TDS_ERR); | ||
| } | ||
|
|
||
| void setFromTDS(TDSReader tdsReader) throws SQLServerException { | ||
| if (TDS.TDS_ERR != tdsReader.readUnsignedByte()) | ||
| assert false; | ||
| setContentsFromTDS(tdsReader); | ||
| } | ||
|
|
||
| void setContentsFromTDS(TDSReader tdsReader) throws SQLServerException { | ||
| tdsReader.readUnsignedShort(); // token length (ignored) | ||
| errorNumber = tdsReader.readInt(); | ||
| errorState = tdsReader.readUnsignedByte(); | ||
| errorSeverity = tdsReader.readUnsignedByte(); // matches master.dbo.sysmessages | ||
| errorMessage = tdsReader.readUnicodeString(tdsReader.readUnsignedShort()); | ||
| serverName = tdsReader.readUnicodeString(tdsReader.readUnsignedByte()); | ||
| procName = tdsReader.readUnicodeString(tdsReader.readUnsignedByte()); | ||
| lineNumber = tdsReader.readUnsignedInt(); | ||
|
|
||
cheenamalhotra marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 0 additions & 63 deletions
63
src/main/java/com/microsoft/sqlserver/jdbc/StreamError.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.