Repository navigation
fix(jdbc): report declared types and sizes from getColumns - #88
Merged
Merged
Conversation
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.
Closes #42. Part of #54.
What changed
LibsqlDatabaseMetaData.getColumnsnow derives its metadata row from the declared SQLite type andPRAGMA table_xinfoinstead of hard-coding BIGINT/OTHER, zero sizes, andIS_AUTOINCREMENT = NO.DATA_TYPEfollows xerial's declared-type patterns:INT|BOOL->Types.INTEGER,CHAR|CLOB|TEXT|BLOB->Types.VARCHAR,REAL|FLOA|DOUB|DEC|NUM->Types.FLOAT, catch-all ->Types.VARCHAR.COLUMN_SIZEandDECIMAL_DIGITSare parsed from a parenthesized type dimension exactly as xerial does. Untyped/typeless columns keep xerial's defaults (2000000000,10, or0for integer/text).TYPE_NAMEis the uppercased declared type with the dimension removed.NULLABLE/IS_NULLABLEcome from the pragmanotnullflag.IS_AUTOINCREMENTuses the isAutoIncrement false-positives on identifiers containing AUTOINCREMENT #38 helperLibsqlResultSetMetaData.isAutoIncrementColumnon the table'sCREATESQL, gated on the pragma primary-key flag, so no parsing is duplicated and identifiers containingAUTOINCREMENTdo not false-positive.IS_GENERATEDCOLUMNuses the xerial hidden-column rule (hidden2 or 3).LIKEwith the existing literal escaping, now with an explicitESCAPE '\'.The result is assembled from the schema/pragma query in Java and returned as an in-memory
LibsqlResultSet, so no extra statement is left open by this metadata call.Contract decision
xerial 3.53.4.0
JDBC3DatabaseMetaData.getColumnsis the contract. The type patterns, defaults, dimension parsing, nullable encoding, and generated-column rule are copied from that implementation. Auto-increment detection intentionally reuses the #38 helper as required by Steering; for a genuineAUTOINCREMENTprimary key the result is identical to xerial, while the helper additionally ignores the keyword when it appears in comments, string literals, or non-autoincrement identifiers.Evidence
Acceptance test:
LibsqlDatabaseMetaDataTest.getColumnsReportsDeclaredTypesSizesNullabilityAndAutoIncrement.Failing before the fix (
./mvnw -q -pl libsql-jdbc -am -Dtest=LibsqlDatabaseMetaDataTest -Dsurefire.failIfNoSpecifiedTests=false test):Passing after the fix:
Additional verification run in this environment:
./mvnw spotless:applythen./mvnw spotless:checkpass.The pinned xerial 3.53.4.0 was also run directly against the same schema; it reports
i INTEGER(4) size 2000000000 digits 0,d DECIMAL(6) size 15 digits 5,k INTEGER(4) autoincrement YES,n TEXT(12) nullable 0.Deviations
None from xerial.
Note on the acceptance criterion "DECIMAL(10,5) reports size 10 and 5 decimal digits": this cannot be met together with xerial parity. xerial computes
COLUMN_SIZEfor a two-part dimension asprecision + scale, so pinned 3.53.4.0 reportsCOLUMN_SIZE = 15forDECIMAL(10,5)(verified by running the pinned jar). This PR follows the binding Steering contract ("match xerial … computed COLUMN_SIZE") and reports 15, withDECIMAL_DIGITS = 5. The test asserts the xerial value and documents the conflict.No Hrana or sqld limitation was encountered;
PRAGMA table_xinfoworks against live sqld.