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

[FEATURE REQUEST] separate exception for constraint violation #1199

Open
GitMensch opened this issue Dec 2, 2019 · 3 comments
Open

[FEATURE REQUEST] separate exception for constraint violation #1199

GitMensch opened this issue Dec 2, 2019 · 3 comments
Labels
Enhancement An enhancement to the driver. Lower priority than bugs.

Comments

@GitMensch
Copy link

context

Often a constraint exception is something "special" to catch. The current JDBC driver (deeper checked with 7.4.1) seems to have no straight forward way to do so.

preferred solution

Instead of wrapping this error in a SQLServerException (which sub-classes java.sql.SQLException) raise an SQLIntegrityConstraintViolationException (which sub-classes the same, since Java 1.6), likely also wrapped for SQL-Server.

alternatives I've considered

Check if the already catched SQLException is an instance of SQLServerException, if it is: check the error code and handle the correct magic number accordingly, otherwise throw the original exception.

side-question

What is the currently best way to check for this?

also likely applies to other standard SQLExceptions/Errors

SQLInvalidAuthorizationSpecException,SQLTransientConnectionException, SQLNonTransientConnectionException, SQLSyntaxErrorException, SQLTransactionRollbackException

@GitMensch GitMensch added the Enhancement An enhancement to the driver. Lower priority than bugs. label Dec 2, 2019
@GitMensch GitMensch changed the title [FEATURE REQUEST] separate exception for contraint violation [FEATURE REQUEST] separate exception for constraint violation Dec 2, 2019
@peterbae
Copy link
Contributor

peterbae commented Dec 2, 2019

Thanks @GitMensch, the team will look into putting this item in the backlog.

@GitMensch
Copy link
Author

Thank you @peterbae for the note. As this is also part of this issue (I just can't add the "question" label:

What is the current best way to check for [constraint violations]?

@peterbae
Copy link
Contributor

peterbae commented Dec 3, 2019

The best way would be to get SQL Server error code and use that to check if the code is for constraint violations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement An enhancement to the driver. Lower priority than bugs.
Projects
Status: Backlog
Development

No branches or pull requests

2 participants