Skip to content

refactor(jdbc): extract SqliteRealText from LibsqlResultSet - #216

Merged
magnusp merged 2 commits into
mainfrom
refactor/i198-sqlite-real-text
Oct 24, 2026
Merged

magnusp merged 2 commits into
mainfrom
refactor/i198-sqlite-real-text

Conversation

@magnusp

@magnusp magnusp commented Oct 24, 2026

Copy link
Copy Markdown
Owner

Fixes #198

Pure move, zero behavior change. Extracts the SQLite REAL text formatter from LibsqlResultSet into a package-private SqliteRealText with a package-private static String format(double).

Base note: this PR targets test/i195-pin-jdbc-behaviors, the parent stack link (wave 0 characterization tests, 9 new tests). It is not based on main.

Diff stat

 .../magnusp/libsql/jdbc/LibsqlResultSet.java       | 264 +-------------------
 .../github/magnusp/libsql/jdbc/SqliteRealText.java | 272 +++++++++++++++++++++
 2 files changed, 274 insertions(+), 262 deletions(-)

Proof the moved lines are unchanged

Old LibsqlResultSet.java lines 187–444 (258 lines) vs SqliteRealText.java lines 14–271 — the only differing line is the entry-method signature, which the issue requires renaming and widening to package-private:

$ git show origin/test/i195-pin-jdbc-behaviors:.../LibsqlResultSet.java | sed -n '187,444p' > /tmp/blk-old.txt
$ sed -n '14,271p' .../SqliteRealText.java > /tmp/blk-new.txt
$ diff /tmp/blk-old.txt /tmp/blk-new.txt
32c32
<     private static String sqliteRealText(double value) {
---
>     static String format(double value) {

Everything else — the two explanatory comments, the four power tables (FP_POWERS_OF_TEN, FP_POWER_SCALES, FP_POWER_SCALE_LOW, plus FP_POWER_SCALE_HIGH), roundTripsTo, fpPowerOfTenToTwo, fpPowerOfTwoToTen, fpPowerOfTen, fpNormalizeHigh, fpMultiplyWide, fpMultiplyHigh, and fpUnsigned — is identical text, at identical indentation, with method names, constants, comments, and arithmetic byte for byte. No BigDecimal.toPlainString, Double.toString, String.format, or %g.

The only other edit in LibsqlResultSet is removing the now-unused java.math.BigInteger import (its only use lived in the moved code; BigDecimal is still used).

Call sites repointed:

  • getString (was 181, now 180): case Value.Float f -> SqliteRealText.format(f.value());
  • getBytes (was 641, now 381): case Value.Float f -> SqliteRealText.format(f.value()).getBytes(...);

Behavior preserved: negative zero renders 0.0, exponents render signed and zero padded to two digits, NaN renders NaN, and fixed notation applies when the decimal exponent is between -4 and 16.

Line counts

File Before After
LibsqlResultSet.java 1498 1238 (under the 1250 gate)
SqliteRealText.java — 272

Lanes

$ ./mvnw -pl libsql-jdbc -am test
[INFO] Tests run: 383, Failures: 0, Errors: 0, Skipped: 0
[INFO] BUILD SUCCESS
$ ./mvnw spotless:apply
[INFO] BUILD SUCCESS
$ ./mvnw spotless:check
[INFO] BUILD SUCCESS
$ ./mvnw -pl libsql-conformance -am verify
[INFO] Tests run: 272, Failures: 0, Errors: 0, Skipped: 7
[INFO] BUILD SUCCESS

No test file, dependency, or pom.xml change. No public surface change. Nothing else in LibsqlResultSet moved or renamed.

Characterization tests for the four unpinned behaviors in the JDBC
refactor Wave 0:

- attached-schema table metadata through pragma_database_list
- date/time text tails (offset, Z, bare time) and BLOB rejection
- duplicate savepoint names and releasing the outermost savepoint of
  an auto-commit-started transaction
- executeBatch racing statement close

Tests only; no production code, pom or dependency change.
@magnusp

magnusp commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

Root verdict: PASS at 9ee30e6.

Verifier proved the 258-line block moved byte-identically, with only sqliteRealText renamed to format. Both types stay package-private. 383 unit tests, 272 conformance tests, spotless green, and a negative-zero probe that bit and was reverted. Diff is 2 files, +274/-262.

The Xerial Control lane failed in PreparedStatementThreadTest.testPreparedStmtConcurrentCloseSegFault, which runs the vendored xerial driver and never loads this module. It is a known race in the reference driver and unrelated to the patch. Re-running that job. Countersign: root, 9ee30e6.

Base automatically changed from test/i195-pin-jdbc-behaviors to main October 24, 2026 14:38
@magnusp
magnusp merged commit 94b3703 into main Oct 24, 2026
8 of 9 checks passed
@magnusp
magnusp deleted the refactor/i198-sqlite-real-text branch October 24, 2026 14: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.

Extract SqliteRealText from LibsqlResultSet

1 participant