Skip to content

fix(jdbc): return all xerial table types - #90

Merged
magnusp merged 1 commit into
mainfrom
fix/50-table-types
Oct 22, 2026
Merged

magnusp merged 1 commit into
mainfrom
fix/50-table-types

Conversation

@magnusp

@magnusp magnusp commented Oct 21, 2026

Copy link
Copy Markdown
Owner

Part of #50. Covers defect (1), table-types completeness, only. The statement leaks, getIndexInfo table-name escaping, and getMetaData caching remain for the later PRs under #50.

What changed

  • LibsqlDatabaseMetaData.getTableTypes now returns all four table types xerial 3.53.4.0 reports: TABLE, VIEW, SYSTEM TABLE, and GLOBAL TEMPORARY.
  • Added getTableTypesReturnsEveryXerialTableType, which calls the metadata method end to end and asserts the returned TABLE_TYPE values rather than the generated SQL.

Contract decision

Parity with xerial 3.53.4.0 JDBC3DatabaseMetaData.getTableTypes (lines 1754-1772). The implementation uses the same four-way UNION of constant selects. It does not add an ORDER BY, matching xerial, which leaves row order unspecified. No Hrana or sqld limitation required a different shape.

Evidence

The new test failed on the pre-fix code:

./mvnw -pl libsql-jdbc -am test -Dtest=LibsqlDatabaseMetaDataTest -Dsurefire.failIfNoSpecifiedTests=false
[ERROR] LibsqlDatabaseMetaDataTest.getTableTypesReturnsEveryXerialTableType:138
Expecting actual:
  ["TABLE", "VIEW"]
to contain exactly in any order:
  ["TABLE", "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY"]
but could not find the following elements:
  ["SYSTEM TABLE", "GLOBAL TEMPORARY"]
Tests run: 11, Failures: 1, Errors: 0, Skipped: 0

It passes after the fix:

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

Regression runs:

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

./mvnw spotless:apply
BUILD SUCCESS

The conformance suite does not currently call getTableTypes; it ran as a regression guard for the surrounding metadata behavior.

Deviations

none

Defects covered

  • (1) getTableTypes completeness.
  • (2) Statement leaks in the listed metadata methods.
  • (3) getIndexInfo table-name escaping.
  • (4) getMetaData caching.

Out-of-scope defects noticed

The other three defects in #50 are still present and intentionally untouched. I did not find additional defects outside this PR's scope.

Files touched

  • libsql-jdbc/src/main/java/com/github/magnusp/libsql/jdbc/LibsqlDatabaseMetaData.java
  • libsql-jdbc/src/test/java/com/github/magnusp/libsql/jdbc/LibsqlDatabaseMetaDataTest.java

@magnusp
magnusp merged commit 08326ed into main Oct 22, 2026
5 checks passed
@magnusp
magnusp deleted the fix/50-table-types branch October 22, 2026 00:02
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`
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.

1 participant