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

Fix empty FK_NAME reported by DatabaseMetaData#getImportedKeys when created using quotes. #506

Closed
ppcedric opened this issue Jun 22, 2020 · 2 comments
Labels
enhancement:JDBC Enhancement specific to the JDBC standard released Issue has been released

Comments

@ppcedric
Copy link

Hi,

The method DatabaseMetaData#getImportedKeys() reports empty string for the FK_NAME column when the foreign key was created using a quoted form such as:

CREATE TABLE "MAIN"."REFERENCEDENTITY" ("ID" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,"ENUMSTRCOL" TEXT, CONSTRAINT "REFERENCEDENTITY_94OR1OTBGSDVTRJCVZ6OWAPZR_FK" FOREIGN KEY ("ENUMSTRCOL") REFERENCES "TESTINGENUM" ("NAME"))

The problem is the regular expression FK_NAMED_PATTERN in src/main/java/org/sqlite/jdbc3/JDBC3DatabaseMetaData.java that do not take into account the optional "" arround the foreign key name, which is "REFERENCEDENTITY_94OR1OTBGSDVTRJCVZ6OWAPZR_FK" in this example.

This fix on the regex resolve the issue:

--- a/src/main/java/org/sqlite/jdbc3/JDBC3DatabaseMetaData.java
+++ b/src/main/java/org/sqlite/jdbc3/JDBC3DatabaseMetaData.java
@@ -2067,7 +2067,7 @@ public abstract class JDBC3DatabaseMetaData extends org.sqlite.core.CoreDatabase
          * Pattern used to extract a named primary key.
          */
          private final Pattern FK_NAMED_PATTERN =
-            Pattern.compile("CONSTRAINT\\s*([A-Za-z_][A-Za-z\\d_]*)?\\s*FOREIGN\\s+KEY\\s*\\((.*?)\\)",
+            Pattern.compile("CONSTRAINT\\s*\"?([A-Za-z_][A-Za-z\\d_]*)?\"?\\s*FOREIGN\\s+KEY\\s*\\((.*?)\\)",
                 Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
          
        private String fkTableName;

Maybe a similar issue occurs with PK_NAMED_PATTERN and getPrimaryKeys() .

Kind regards,
Cédric.

@gotson
Copy link
Collaborator

gotson commented Jul 27, 2022

Seems like you have a solution ready, do you want to submit a PR with some tests (failing on master), as well as the fix?

@gotson gotson added the waiting for feedback Waiting for a feedback from the issue creator label Jul 27, 2022
@gotson gotson added the enhancement:JDBC Enhancement specific to the JDBC standard label Sep 13, 2022
@gotson gotson removed the waiting for feedback Waiting for a feedback from the issue creator label Nov 25, 2022
@gotson gotson closed this as completed in ba69b2e Nov 25, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Feb 2, 2023

🎉 This issue has been resolved in 3.40.1.0 (Release Notes)

@github-actions github-actions bot added the released Issue has been released label Feb 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement:JDBC Enhancement specific to the JDBC standard released Issue has been released
Projects
None yet
Development

No branches or pull requests

2 participants