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

DatabaseMetaData#getImportedKeys() returns wrong value for DELETE_RULE #467

Closed
rdicroce opened this issue Aug 31, 2017 · 4 comments
Closed
Assignees
Labels
Waiting for Response Waiting for a reply from the original poster, or affiliated party
Projects

Comments

@rdicroce
Copy link
Contributor

Driver version or jar name

6.1.7

SQL Server version

13.0.4001.0

Client operating system

Windows 10

Java/JVM version

Oracle 8u144

Table schema

dbo

Problem description

DatabaseMetaData#getImportedKeys() returns UPDATE_RULE and DELETE_RULE columns with incorrect values.

Expected behavior and actual behavior

For a foreign key created with ON DELETE SET NULL, the JavaDoc says DELETE_RULE should be equal to the importedKeySetNull constant, which has a value of 2. But the driver reports 1.

The cause is that the data is obtained by executing sp_fkeys on the server. sp_fkeys only returns 0 or 1 for the delete and update actions (i.e. it does not provide detail at the level of granularity required). This also affects any other APIs (e.g. getExportedKeys()) that use sp_fkeys to get their data.

Possible solutions:

  • The sys.foreign_keys table has more granular information. It could be joined to various other tables to return all of the relevant data.
  • sp_fkeys could be changed. There was an issue about this but it was closed as Won't Fix.
@xiangyushawn
Copy link
Contributor

Hello @rdicroce , thank you very much for reporting the error and providing the idea to fix it. We created a PR for it. If you have time, could you please take a look at the PR and any suggestions would be very appreciated too. Thank you!

@ajlam ajlam added PR Under Review Waiting for Response Waiting for a reply from the original poster, or affiliated party labels Sep 12, 2017
@rdicroce
Copy link
Contributor Author

The PR looks okay to me. I don't have any way of testing it because the code I was working on that exposed this problem has since been removed.

@xiangyushawn
Copy link
Contributor

@rdicroce thank you. Let's wait for the PR to be reviewed and then we can close this issue after the PR is merged. Thank you 😄

@xiangyushawn
Copy link
Contributor

Closing the issue since PR is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Waiting for Response Waiting for a reply from the original poster, or affiliated party
Projects
MSSQL JDBC
  
Closed Issues
Development

No branches or pull requests

3 participants