Repository navigation
Commit db5cd60
authored
fix(jdbc): honor table types in getTables metadata (#84)
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
none1 parent 8b7f967 commit db5cd60
2 files changed
Lines changed: 94 additions & 5 deletions
File tree
- libsql-jdbc/src
- main/java/com/github/magnusp/libsql/jdbc
- test/java/com/github/magnusp/libsql/jdbc
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
284 | 284 | | |
285 | 285 | | |
286 | 286 | | |
287 | | - | |
288 | | - | |
289 | | - | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
290 | 310 | | |
291 | 311 | | |
292 | 312 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
47 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
48 | 117 | | |
49 | 118 | | |
50 | 119 | | |
| |||
0 commit comments