Skip to content

fix(jdbc): honor table types in getTables metadata - #84

Merged
magnusp merged 1 commit into
mainfrom
fix/41-get-tables-types
Oct 21, 2026
Merged

magnusp merged 1 commit into
mainfrom
fix/41-get-tables-types

Conversation

@magnusp

@magnusp magnusp commented Oct 21, 2026

Copy link
Copy Markdown
Owner

Closes #41. Part of #54.

What changed

  • LibsqlDatabaseMetaData.getTables now builds the xerial-shaped union instead of selecting every sqlite_master row:
    • a sqlite_schema SYSTEM TABLE row,
    • user rows filtered to UPPER(TYPE) IN ('TABLE', 'VIEW'),
    • sqlite_temp_master rows as GLOBAL TEMPORARY,
    • sqlite_% rows as SYSTEM TABLE.
  • The types argument is honored. null and an empty array add no filter; a non-empty array is uppercased and emitted as TABLE_TYPE IN (...).
  • A null or empty table-name pattern maps to %, matching xerial. Single quotes are still escaped, and the pattern uses LIKE ... ESCAPE '\'.
  • Tests cover null types, an empty array, {"TABLE"}, {"VIEW"}, mixed-case multiple types, an empty name pattern, and the existing quote-escape case.

Contract decision

Parity with xerial 3.53.4.0 JDBC3DatabaseMetaData.getTables (lines 1682-1750). The union, the TABLE/VIEW user-row filter, the system and temporary rows, the types filter behavior, the LIKE ... ESCAPE '\' pattern handling, and the ORDER BY TABLE_TYPE, TABLE_NAME ordering all match. No transport limitation required a different shape.

Evidence

Tests were added first and failed on the pre-fix code:

./mvnw -pl libsql-jdbc -am test -Dtest=LibsqlDatabaseMetaDataTest -Dsurefire.failIfNoSpecifiedTests=false
[ERROR] Tests run: 9, Failures: 7, Errors: 0, Skipped: 0

Representative failures: the pre-fix SQL had no sqlite_schema/SYSTEM TABLE branch, no sqlite_temp_master/GLOBAL TEMPORARY branch, no UPPER(TYPE) IN ('TABLE', 'VIEW') filter, no TABLE_TYPE IN (...) filter for {"TABLE"}/{"VIEW"}, and turned an empty pattern into LIKE ''.

After the fix:

./mvnw -pl libsql-jdbc -am test
Tests run: 154, Failures: 0, Errors: 0, Skipped: 0
BUILD SUCCESS

./mvnw -pl libsql-conformance -am verify
Tests run: 115, Failures: 0, Errors: 0, Skipped: 1
BUILD SUCCESS

The conformance run exercises real sqld and includes MetadataLeakTest, which calls getTables(null, null, null, null).

I also executed the generated union against a real SQLite engine (xerial 3.53.4.0) with a table, a view, an index, a trigger, and a temp table. Null types returned tmp (GLOBAL TEMPORARY), sqlite_schema (SYSTEM TABLE), t (TABLE), and v (VIEW); {"TABLE"} returned only t; the index and trigger never appeared.

./mvnw spotless:apply completed successfully before the final commit.

Deviations

none

@magnusp
magnusp merged commit db5cd60 into main Oct 21, 2026
5 checks passed
@magnusp
magnusp deleted the fix/41-get-tables-types branch October 21, 2026 23:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DatabaseMetaData.getTables ignores the types filter and returns non-table rows

1 participant