Skip to content

fix(jdbc): only report isAutoIncrement for a real AUTOINCREMENT primary key - #56

Merged
magnusp merged 1 commit into
mainfrom
fix/38-autoincrement-detection
Oct 21, 2026
Merged

magnusp merged 1 commit into
mainfrom
fix/38-autoincrement-detection

Conversation

@magnusp

@magnusp magnusp commented Oct 21, 2026

Copy link
Copy Markdown
Owner

Closes #38. Part of #54.

What changed

  • LibsqlResultSetMetaData.isAutoIncrement no longer scans the whole CREATE TABLE text for the word AUTOINCREMENT. It now checks the definition of the matching column.
  • Added a reusable package-private helper, LibsqlResultSetMetaData.isAutoIncrementColumn(String createSql, String columnName), so DatabaseMetaData.getColumns reports wrong types and sizes #42 can reuse the detection for getColumns instead of reimplementing the parsing.
  • The helper tokenizes the CREATE TABLE statement, skipping comments, string literals, and quoted identifiers, splits the table body into column and table constraint definitions, and looks for an unquoted AUTOINCREMENT keyword in the matching column definition or table-level PRIMARY KEY (column AUTOINCREMENT) constraint.
  • Added behavior tests for a column named myautoincrement, a table-level PRIMARY KEY (id AUTOINCREMENT) constraint, and a quoted identifier named AUTOINCREMENT. The existing real-AUTOINCREMENT, comment, and string-literal tests remain.

Contract decision

Parity with xerial 3.53.4.0. Probed xerial 3.53.4.0 directly for the cases below:

DDL xerial isAutoIncrement
create table t(myautoincrement integer primary key) false
create table t(id integer primary key autoincrement) true
create table t(id integer primary key /* AUTOINCREMENT */) false
create table t(id integer primary key, note text default 'AUTOINCREMENT') false
create table t(id integer, primary key(id autoincrement)) true
create table t("AUTOINCREMENT" integer primary key) false

The fix matches all six.

Evidence

Failing before the fix (new test on f38bd24):

[ERROR] LibsqlResultSetMetaDataTest.doesNotReportAutoIncrementForColumnNamedAutoincrement:101
Expecting value to be false but was true
[ERROR] Tests run: 9, Failures: 1, Errors: 0, Skipped: 0

Passing after the fix:

./mvnw -pl libsql-jdbc -am test
[INFO] Tests run: 39, Failures: 0, Errors: 0, Skipped: 0
[INFO] BUILD SUCCESS

./mvnw spotless:check
(no output; exit 0)

Deviations

Base automatically changed from feat/jdbc-xerial-conformance to main October 21, 2026 21:34
@magnusp
magnusp force-pushed the fix/38-autoincrement-detection branch from 0cb9c38 to a5ed7c5 Compare October 21, 2026 21:37
@magnusp
magnusp merged commit 5202fae into main Oct 21, 2026
5 checks passed
@magnusp
magnusp deleted the fix/38-autoincrement-detection branch October 21, 2026 21:41
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.

isAutoIncrement false-positives on identifiers containing AUTOINCREMENT

1 participant