PDO PostreSQL - parser is broken for `'...\'`
Abierto
@SakiTakamachi ya está trabajando en esto.
Desde el 15/4/2024.
Bug
Extension: pdo_pgsql
Status: Needs Triage
- Lenguaje dominante
- C
- Estrellas
- 40.4k
- Forks
- 8.2k
- Merge medio
- 2 d 13 h
- PR fusionados (30 d)
- 96
Descripción
Description
The following code:
<?php
$pdo = new PDO('pgsql:host=127.0.0.1;dbname=xxx', 'user', 'pass');
$sql = <<<'EOF'
select :a x, '\' x2
EOF;
$statement = $pdo->prepare($sql);
$statement->bindValue('a', 'va');
$statement->execute();
$res = $statement->fetchAll(PDO::FETCH_ASSOC);
var_dump($res);
$sql = <<<'EOF'
select :a x, '\' x2, :b y, '\' y2
EOF;
$statement = $pdo->prepare($sql);
$statement->bindValue('a', 'va');
$statement->bindValue('b', 'vb');
$statement->execute();
$res = $statement->fetchAll(PDO::FETCH_ASSOC);
var_dump($res);
Resulted in this output:
array(1) {
[0]=>
array(2) {
["x"]=>
string(2) "va"
["x2"]=>
string(1) "\"
}
}
Warning: PDOStatement::bindValue(): SQLSTATE[HY093]: Invalid parameter number: :b in C:\...\repro.php on line 20
array(0) {
}
But I expected this output instead:
array(1) {
[0]=>
array(2) {
["x"]=>
string(2) "va"
["x2"]=>
string(1) "\"
}
}
array(1) {
[0]=>
array(4) {
["x"]=>
string(2) "va"
["x2"]=>
string(1) "\"
["y"]=>
string(2) "vb"
["y2"]=>
string(1) "\"
}
}
'\' is causing the issue - but it is absolutely correct string syntax.
Identifier escaping ("\") is broken as well.
It seems php-src parses the SQL using the old mode (default until PostgreSQL 9.1) - https://www.postgresql.org/docs/current/runtime-config-compatible.html#GUC-STANDARD-CONFORMING-STRINGS.
PHP Version
any (tested 7.4 and 8.3)
Operating System
any (tested Windows and linux)
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Evaluación
Este issue todavía no se ha evaluado.