Repository navigation
Add PostgreSQL support and bIdent() identifier quoting - #17
Merged
Merged
Conversation
- Statement::bIdent() quotes table, column and database names for the
database in use ('db.users.id', 'users.*', arrays for column lists).
- IdentifierBindingInterface with QuotedIdentifierBindings,
MySQLIdentifierBindings and PostgreSQLIdentifierBindings.
- Dialect enum and PostgreSQLBindingFactory. With the PostgreSQL dialect,
sql() reads standard '...' strings, E'...' strings, dollar quoting,
"..." identifiers, "--" comments and nesting block comments; "#" is not
a comment, and "??" is a literal "?" for the jsonb operators.
- Bindings takes optional identifier and dialect arguments, defaulting to
MySQL, so existing code is unchanged.
- Fix raw ('%%') values containing '$1' or '\' being read as regex back
references.
- PostgreSQL integration tests, run in CI against a postgres:17 service.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
The docs quote names with MySQL backticks, and
sql()only understood MySQL's rules for strings and comments. This PR adds portable identifier quoting and PostgreSQL rules forsql().Identifier quoting
Statement::bIdent()fills a%%placeholder with quoted names:`users`for MySQL,"users"for PostgreSQL.'db.users.id'quotes each part,'users.*'leaves the star unquoted, and an array gives a column list.InvalidArgumentException.IdentifierBindingInterface, withQuotedIdentifierBindings(any quote characters, e.g.[]for SQL Server),MySQLIdentifierBindingsandPostgreSQLIdentifierBindings.PostgreSQL dialect
Dialectenum andPostgreSQLBindingFactory.Statementreads the dialect from itsBindings.Dialect::PostgreSQL,sql():'...'as a plain character, but as an escape inE'...'$$...$$and$tag$...$tag$as strings, and"..."as an identifier--as a comment without needing a space after it, and lets/* */comments nest#as a comment, so#>and#>>work??as a literal?, for the jsonb?,?|and?&operatorsBindingstakes optional$identifierand$dialectarguments, both defaulting to MySQL, so existing code is unchanged.Bug fix
%%) values containing$1or\were read as regex back references when they were put into the SQL. They're now inserted as is.Known limits from PDO
PDO scans the SQL again before sending it, and its scanner doesn't follow every PostgreSQL rule. Both limits are documented in the README.
?inside a dollar-quoted string fails with "mixed named and positional parameters". PHP 8.4 and newer handle it.*/, so a?in the outer comment after a nested one closes is read as a placeholder.Testing
IdentifierBindingsTestandStatementPostgreSQLPlaceholderTest.GLPDO2PostgreSQLTestruns against a real server and is skipped unlessPGHOSTis set. The two dollar-quote tests require PHP 8.4.postgres:17service alongside MySQL. The MySQL integration tests weren't run locally because no MySQL server was available.🤖 Generated with Claude Code