Repository navigation
Add SQLite 3 support - #20
Merged
Merged
Conversation
- 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>
Merged
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.
Summary
This adds SQLite 3 alongside MySQL and PostgreSQL. Build the statement with
SQLiteBindingFactory::build(), andsql()reads the SQL by SQLite's rules.SQLite's rules in the lexer
'...'only. A backslash is a plain character and''is an escaped quote."...",`...`and[...]are all names, and%%is a placeholder inside each of them, as with MySQL backticks.--needs no space after it, and/* */comments don't nest.#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::SQLiteSQLiteBindingFactorySQLiteIdentifierBindings, which uses double quotesSQLiteNumericBindingsUnsigned 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
TEXTcolumn. WithSQLiteNumericBindings,bUInt()andbUIntArray()throw above 9223372036854775807 instead of storing a wrong value. The limit is now a protectedUINT_MAXconstant onMySQLNumericBindings, so the subclass just lowers it.No PDO limits for SQLite.
pdo_sqlitepasses 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
StatementSQLitePlaceholderTestcovers the lexer and needs no database.GLPDO2SQLiteTestruns 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.pdo_sqlite.🤖 Generated with Claude Code