You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PDO PostreSQL - parser is broken for '...\' #13958
the extension does not support it (AFAIK part of this extension still rely on old postgresql versions behavior), I do not think it qualifies for php 8.2/8.3 though.
The relation with PostgreSQL 9.1 is my pure guess, but if true, the version was released more than 12 years ago. So I would say we have a bug in SQL parsing affecting basically all pdo pgsql users.
Well, as far as quoting goes, recognising '\' as a string literal containing a single backslash isn't so much PostgreSQL-specific as standard ISO/ANSI behaviour.
Activity
[-]PDO_PGSQL - PDOException: SQLSTATE[HY093]: Invalid parameter number: :b[/-][+]PDO PostreSQL - parser is broken for `'...\'`[/+]mvorisek commentedon Apr 14, 2024
@devnexen this is definitely a bug, the SQL is parsed somehow by php wrongly.
devnexen commentedon Apr 14, 2024
the extension does not support it (AFAIK part of this extension still rely on old postgresql versions behavior), I do not think it qualifies for php 8.2/8.3 though.
mvorisek commentedon Apr 14, 2024
The relation with PostgreSQL 9.1 is my pure guess, but if true, the version was released more than 12 years ago. So I would say we have a bug in SQL parsing affecting basically all pdo pgsql users.
MorganLOCode commentedon Apr 14, 2024
Note in contrast that the PostgreSQL extension does parse the string literal correctly:
devnexen commentedon Apr 14, 2024
pdo pgsql and pgsql are distinct code wise :)
mvorisek commentedon Apr 14, 2024
It seems the parsing is called in https://github.com/php/php-src/blob/php-8.3.0/ext/pdo_pgsql/pgsql_driver.c#L292 and done in https://github.com/php/php-src/blob/php-8.3.0/ext/pdo/pdo_sql_parser.re#L58 where it assumes MySQL behaviour instead of ANSI.
here are two correct examples of how it should be done:
MorganLOCode commentedon Apr 14, 2024
Yes, I know. One works correctly (it defers to libpq), the other doesn't.
SakiTakamachi commentedon Apr 15, 2024
After some testing, I think this might qualify as a bug.
However, I think this is a bit of a gray area, right on the border between a bug and a feature request.
As mentioned, this is due to PDO's common query parser not taking into account PostgreSQL-specific behavior.
I'm not sure how much change will be needed until I work a bit more into this, but I'll get started.
MorganLOCode commentedon Apr 15, 2024
Well, as far as quoting goes, recognising
'\'as a string literal containing a single backslash isn't so much PostgreSQL-specific as standard ISO/ANSI behaviour.mvorisek commentedon Apr 16, 2024
Thank you for looking into this.
Here is big testcase string: https://github.com/atk4/data/blob/c2baf07324/tests/Persistence/Sql/WithDb/SelectTest.php#L552-L582
and testcase for identifiers: https://github.com/atk4/data/blob/c2baf07324/tests/Persistence/Sql/WithDb/SelectTest.php#L622-L648 (plus all cases prefixed /w
\\- https://github.com/atk4/data/blob/c2baf07324/tests/Persistence/Sql/WithDb/SelectTest.php#L675)mbeccati commentedon Apr 17, 2024
Pls see https://wiki.php.net/rfc/pdo_driver_specific_parsers ;-)
mvorisek commentedon Apr 23, 2024
Can this be fixed for PHP 8.2/8.3?
mbeccati commentedon Apr 23, 2024
@mvorisek I'm afraid not. The required changes are too deep for anything but the next 8.x version.
devnexen commentedon Apr 23, 2024
@mvorisek See why I put the feature label first, it was not to bother you.
mvorisek commentedon Apr 23, 2024
We ended up with this workaround https://github.com/atk4/data/blob/c2baf07324/src/Persistence/Sql/Postgresql/ExpressionTrait.php#L28-L36
however native fix would be much faster
also for identifiers such workaround is not possible, possibly there is no workaround
and for SQL server we have to workaround https://github.com/atk4/data/blob/c2baf07324/src/Persistence/Sql/Mssql/ExpressionTrait.php#L34-L43 - would that be fixed by #14035? The SQL driver calls the PDO parsing in https://github.com/microsoft/msphpsql/blob/v5.12.0/source/pdo_sqlsrv/pdo_dbh.cpp#L836.
kamil-tekiela commentedon Nov 9, 2026
I believe this has been solved by PHP 8.4 via #14035.