Repository navigation
fix(jdbc): escape quoted table names in getIndexInfo - #93
Merged
Merged
Conversation
magnusp
added a commit
that referenced
this pull request
Oct 22, 2026
Closes #50 Part of #54. ## What changed `LibsqlConnection.getMetaData()` now creates `LibsqlDatabaseMetaData` on first use and returns the same instance for the lifetime of the connection. Separate connections get separate instances. A closed connection still throws. The method Javadoc documents the caching contract. The behavior test `LibsqlConnectionTest#getMetaDataIsCachedPerConnection` pins both halves: repeated calls on one connection return the same object, and another connection returns a different object. ## Contract decision Parity with xerial sqlite-jdbc 3.53.4.0. `SQLiteConnection.getSQLiteDatabaseMetaData()` caches its metadata object in a `meta` field and `getMetaData()` delegates to it, so the same instance is returned per connection. This change matches that behavior. No Hrana or sqld constraint makes parity impossible. ## Evidence Failing before the fix: ``` ./mvnw -q -pl libsql-jdbc -am -Dtest=LibsqlConnectionTest#getMetaDataIsCachedPerConnection -Dsurefire.failIfNoSpecifiedTests=false test ``` ``` [ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0 java.lang.AssertionError: Expecting actual: com.github.magnusp.libsql.jdbc.LibsqlDatabaseMetaData@58c34bb3 and: com.github.magnusp.libsql.jdbc.LibsqlDatabaseMetaData@56a4479a to refer to the same object ``` Passing after the fix: ``` ./mvnw -q -pl libsql-jdbc -am -Dtest=LibsqlConnectionTest#getMetaDataIsCachedPerConnection -Dsurefire.failIfNoSpecifiedTests=false test ``` No failures (exit 0). Full module suite after the fix: ``` ./mvnw -pl libsql-jdbc -am test ``` ``` Tests run: 170, Failures: 0, Errors: 0, Skipped: 0 BUILD SUCCESS ``` Formatting: ``` ./mvnw spotless:apply BUILD SUCCESS ``` `libsql-itests` and `libsql-conformance` were not run: the #50 Steering evidence asks for `./mvnw -pl libsql-jdbc -am test` and `./mvnw spotless:apply`, and this change touches no live-sqld or conformance path. ## Deviations None. ## Defect coverage This is defect (4) of the four sequenced defects under #50: `getMetaData` caching. It does not reopen the earlier three defects, which were delivered in #90 (`getTableTypes`), #91 (statement leaks), and #93 (`getIndexInfo` escaping). Files touched: - `libsql-jdbc/src/main/java/com/github/magnusp/libsql/jdbc/LibsqlConnection.java` - `libsql-jdbc/src/test/java/com/github/magnusp/libsql/jdbc/LibsqlConnectionTest.java`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #50. Covers defect (3),
getIndexInfotable-name escaping, only. It does not changegetMetaDatacaching (defect 4), which remains for the final PR under #50.What changed
LibsqlDatabaseMetaData.getIndexInfonow escapes the table name with the existingescapeLiteralhelper (single quotes doubled) before interpolating it into both theTABLE_NAMEliteral and thepragma_index_list(...)argument.LibsqlDatabaseMetaDataTest.getIndexInfoRoundTripsQuotedTableName. The test callsgetIndexInfo(null, null, "t'x", false, false)end to end against a connection that interprets the generated SQL string literals the way SQLite does. It asserts the returned row carriesTABLE_NAME = "t'x", the expected index name, and the expected column name.Contract decision
Parity with xerial 3.53.4.0
JDBC3DatabaseMetaData.getIndexInfo(src/main/java/org/sqlite/jdbc3/JDBC3DatabaseMetaData.java:1525), which applies itsescape(table)helper to both places the table name is interpolated. This implementation uses the existingescapeLiteral, whose quote-doubling rule is identical. The Hrana transport and sqld require no different shape. No deviation.Evidence
The new test fails on the pre-fix code:
The same test passes after the fix:
Full module run:
Regression guard:
Formatting:
libsql-itestswas not required by the #50 Steering verification steps and was not run. The conformance suite does not currently callgetIndexInfo; it ran as a regression guard for the surrounding metadata behavior.Deviations
None.
Defects covered
getTableTypescompleteness.getIndexInfotable-name escaping.getMetaDatacaching.Files touched
libsql-jdbc/src/main/java/com/github/magnusp/libsql/jdbc/LibsqlDatabaseMetaData.javalibsql-jdbc/src/test/java/com/github/magnusp/libsql/jdbc/LibsqlDatabaseMetaDataTest.javaOut-of-scope defects noticed
LibsqlConnection.getMetaDatareturning an uncached object, is still present and is intentionally left for the final PR.getIndexInfopath.