Skip to content

Add SQLite 3 support - #20

Merged
ellisgl merged 2 commits into
mainfrom
sqlite-support
Nov 25, 2026
Merged

ellisgl merged 2 commits into
mainfrom
sqlite-support

Conversation

@ellisgl

@ellisgl ellisgl commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Summary

This adds SQLite 3 alongside MySQL and PostgreSQL. Build the statement with SQLiteBindingFactory::build(), and sql() reads the SQL by SQLite's rules.

SQLite's rules in the lexer

  • Strings: '...' only. A backslash is a plain character and '' is an escaped quote.
  • Identifiers: "...", `...` and [...] are all names, and %% is a placeholder inside each of them, as with MySQL backticks.
  • Comments: -- needs no space after it, and /* */ comments don't nest.
  • No special meaning: # and $ are ordinary characters, and ?? is two placeholders, because SQLite has no ? operator.

The lexer in Statement::sql() is generalised so each dialect sets its own string, identifier and comment rules. MySQL and PostgreSQL behave as before.

New classes

  • Dialect::SQLite
  • SQLiteBindingFactory
  • SQLiteIdentifierBindings, which uses double quotes
  • SQLiteNumericBindings

Unsigned integers are capped on SQLite. SQLite integers are signed 64-bit, and it reads any larger number as a float. In testing, 2⁶⁴−1 and 2⁶⁴−2 were stored as the same value, even in a TEXT column. With SQLiteNumericBindings, bUInt() and bUIntArray() throw above 9223372036854775807 instead of storing a wrong value. The limit is now a protected UINT_MAX constant on MySQLNumericBindings, so the subclass just lowers it.

No PDO limits for SQLite. pdo_sqlite passes placeholders through to SQLite rather than rewriting them, so the PostgreSQL limits that come from PDO don't apply. This was checked on PHP 8.3, 8.4 and 8.5.

Testing

  • StatementSQLitePlaceholderTest covers the lexer and needs no database.
  • GLPDO2SQLiteTest runs real queries against an in-memory database, so it needs no server and runs locally as well as in CI. It covers all three identifier quotes, literals and comments, ->>, booleans, dates and unsigned values.
  • CI now installs pdo_sqlite.
  • The full suite passed locally against MySQL 8.4, PostgreSQL 17 and SQLite on PHP 8.5 (212 tests), and the SQLite tests also passed on PHP 8.3. PHPStan level 8 and PSR-12 are clean.

🤖 Generated with Claude Code

ellisgl and others added 2 commits November 25, 2026 11:54
- Dialect::SQLite and SQLiteBindingFactory. With it, sql() reads '...'
  strings without backslash escapes, "...", `...` and [...] identifiers
  ('%%' is still a placeholder in all three), "--" comments without a
  following space and non-nesting block comments; '#' is not a comment.
- Generalise the sql() lexer so each dialect sets its own string,
  identifier and comment rules. MySQL and PostgreSQL are unchanged.
- SQLiteNumericBindings: bUInt()/bUIntArray() stop at 2^63 - 1. SQLite
  reads larger numbers as floats, so 2^64 - 1 and 2^64 - 2 would be
  stored as the same value. MySQLNumericBindings' maximum is now the
  protected UINT_MAX constant.
- Unit tests and an in-memory SQLite integration test; CI installs
  pdo_sqlite.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The lexer's standalone $i++ and lexDepth++ become ++$i and
++$this->lexDepth. getNextName() keeps its post-increments, since it
uses the old value to number placeholders from 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ellisgl
ellisgl merged commit 115885e into main Nov 25, 2026
5 checks passed
@ellisgl
ellisgl deleted the sqlite-support branch November 25, 2026 17:58
@ellisgl ellisgl mentioned this pull request Nov 25, 2026
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