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

SQLite "Cannot parse or interpret sql for table" error with both unique columns and foreign key constraints #16675

Closed
vptp opened this issue May 14, 2024 · 5 comments

Comments

@vptp
Copy link

vptp commented May 14, 2024

Expected behavior

Code generation maven plugin to run successfully without logging any errors.
Generate unique keys for all UNIQUE columns.
Generate DAO.fetchOneByX functions for all UNIQUE columns.

Actual behavior

Error logged during code generation:

[INFO] Cannot parse or interpret sql for table test2: CREATE TABLE test2
...
org.jooq.exception.DataDefinitionException: TableImpl does not exist: test

Unique keys missing for some tables.
Test2Dao.fetchOneByCd function generated.

Steps to reproduce the problem

MCVE jOOQ-mcve-kotlin-sqlite directory

The problem appears to require the combination of columns with UNIQUE constraints and columns with FOREIGN KEY constraints in the same table.
It appears that while processing the unique keys for each table, parsing the foreign keys in the SQL causes an exception which results in aborting processing unique keys. Hence the DAO.fetchOneByX method is not generated.

jOOQ 3.14.16 generates the DAO.fetchOneByX as expected. jOOQ versions 3.15.0 to 3.19.8 omit the DAO.fetchOneByX in some cases.

jOOQ Version

jOOQ 3.19.8

Database product and version

SQLite 3.40.1.0

Java Version

openjdk version "17.0.10" 2024-01-16

JDBC / R2DBC driver name and version (include name if unofficial driver)

org.xerial:sqlite-jdbc:3.40.1.0

@lukaseder
Copy link
Member

Thanks a lot for your report. I can reproduce the problem. Will look into this right away.

@lukaseder
Copy link
Member

I see, we're interpreting meta DDL SQL table by table, with eager foreign key resolution. But the tables are ordered alphabetically, not in their key order (which can have cycles), so we should delay the foreign key checks, e.g. using Settings.interpreterDelayForeignKeyDeclarations

@lukaseder lukaseder changed the title SQLite "Cannot parse or interpret sql for table" error with both unique columns and foreign key constraints SQLite "Cannot parse or interpret sql for table" error with both unique columns and foreign key constraint on same column May 14, 2024
@lukaseder
Copy link
Member

It doesn't happen without the unique constraint, because that particular code path that interprets all the DDL is only invoked when looking up unique constraints.

@lukaseder lukaseder changed the title SQLite "Cannot parse or interpret sql for table" error with both unique columns and foreign key constraint on same column SQLite "Cannot parse or interpret sql for table" error with both unique columns and foreign key constraints May 14, 2024
lukaseder added a commit that referenced this issue May 14, 2024
…both unique columns and foreign key constraints
lukaseder added a commit that referenced this issue May 14, 2024
…both unique columns and foreign key constraints
lukaseder added a commit that referenced this issue May 14, 2024
…both unique columns and foreign key constraints
lukaseder added a commit that referenced this issue May 14, 2024
…both unique columns and foreign key constraints
3.20 Other improvements automation moved this from To do to Done May 14, 2024
@vptp
Copy link
Author

vptp commented May 14, 2024

Thanks for looking at this so quickly

@lukaseder lukaseder reopened this May 15, 2024
3.20 Other improvements automation moved this from Done to In progress May 15, 2024
3.20 Other improvements automation moved this from In progress to Done May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants