SQLite PDO fails to replace ? parameters on sub queries
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 44/100
Rechercherichtung
Start by reproducing the issue with the supplied PDO SQLite example, checking both \PDO and \Pdo\Sqlite drivers. Compare the failing bound parameters before and after the subquery with the successful simple queries, then inspect the PDO SQLite parameter binding path. Done means the supplied subquery cases return the expected results on Windows and Linux.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Description
It appears that ? parameter substitution does not work in sub queries. Results from hard coded queries work fine, as they do from a SQLite command line. See examples in the code.
MySQL, MariaDB and PostGre all work fine. I was only testing on Windows, but I believe it fails on Linux as well. Happens with the standard \PDO and \Pdo\Sqlite drivers.
The following code:
$pdo = new \PDO('sqlite::memory:');
//$pdo = new \Pdo\Sqlite('sqlite::memory:');
$pdo->exec('DROP TABLE IF EXISTS `order`; CREATE TABLE IF NOT EXISTS `order` (`order_id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT);');
$pdo->exec("DROP TABLE IF EXISTS `order_detail`; CREATE TABLE IF NOT EXISTS `order_detail` (
`order_detail_id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
`order_id` INTEGER NOT NULL,
`quantity` DECIMAL(18,4) NOT NULL DEFAULT '0.0000',
`unit_price` DECIMAL(19,4) NULL DEFAULT '0.0000');");
$pdo->exec('insert into `order` (`order_id`) values (1);');
$pdo->exec('insert into `order_detail` (`order_detail_id`, `order_id`, `quantity`, `unit_price`) values (1, 1, 10, 100);');
runQuery($pdo, 'SELECT * FROM `order` WHERE order_id = 1;');
runQuery($pdo, 'SELECT * FROM `order` WHERE order_id = ?;', 1);
runQuery($pdo, 'SELECT * FROM `order` WHERE 1 = order_id;');
runQuery($pdo, 'SELECT * FROM `order` WHERE ? = order_id', 1);
runQuery($pdo, 'SELECT * FROM `order` WHERE 1000 >= (SELECT (quantity * unit_price) FROM `order_detail` WHERE order_detail_id = `order`.order_id);');
runQuery($pdo, 'SELECT * FROM `order` WHERE (SELECT (quantity * unit_price) FROM `order_detail` WHERE order_detail_id = `order`.order_id) >= 1000;');
runQuery($pdo, 'SELECT * FROM `order` WHERE 1 >= (SELECT (quantity * unit_price) FROM `order_detail` WHERE order_detail_id = `order`.order_id);', expected:false);
runQuery($pdo, 'SELECT * FROM `order` WHERE ? >= (SELECT (quantity * unit_price) FROM `order_detail` WHERE order_detail_id = `order`.order_id);', 1, expected:false);
runQuery($pdo, 'SELECT * FROM `order` WHERE ? >= (SELECT (quantity * unit_price) FROM `order_detail` WHERE order_detail_id = `order`.order_id);', 1, expected:false);
runQuery($pdo, 'SELECT * FROM `order` WHERE (SELECT (quantity * unit_price) FROM `order_detail` WHERE order_detail_id = `order`.order_id) >= ?;', 1000);
function runQuery(\PDO $pdo, string $sql, ?int $input = null, int|bool $expected = 1): void
{
$statement = $pdo->prepare($sql);
if ($statement)
{
$data = [];
if ($input !== null)
{
$data[] = $input;
}
if ($statement->execute($data))
{
$total = $statement->fetch(\PDO::FETCH_NUM);
if ($total === false)
{
if (is_bool($expected) && ! $expected)
{
echo "SQLite query worked: ";
}
else
{
echo "PDOStatement::fetch returned false: ";
}
}
else if (is_array($total))
{
$value = $total[0];
if ($value !== $expected)
{
echo "PDOStatement::fetch failed and returned {$value}, expecting {$expected}: ";
}
else
{
echo "SQLite query worked: ";
}
}
}
else
{
echo "PDOStatement::execute failed: ";
}
}
else
{
echo "PDO::prepare failed: ";
}
echo $sql . "\n";
}
Resulted in this output:
SQLite query worked: SELECT * FROM `order` WHERE order_id = 1;
SQLite query worked: SELECT * FROM `order` WHERE order_id = ?;
SQLite query worked: SELECT * FROM `order` WHERE 1 = order_id;
SQLite query worked: SELECT * FROM `order` WHERE ? = order_id
SQLite query worked: SELECT * FROM `order` WHERE 1000 >= (SELECT (quantity * unit_price) FROM `order_detail` WHERE order_detail_id = `order`.order_id);
SQLite query worked: SELECT * FROM `order` WHERE (SELECT (quantity * unit_price) FROM `order_detail` WHERE order_detail_id = `order`.order_id) >= 1000;
SQLite query worked: SELECT * FROM `order` WHERE 1 >= (SELECT (quantity * unit_price) FROM `order_detail` WHERE order_detail_id = `order`.order_id);
PDOStatement::fetch failed and returned 1, expecting : SELECT * FROM `order` WHERE ? >= (SELECT (quantity * unit_price) FROM `order_detail` WHERE order_detail_id = `order`.order_id);
PDOStatement::fetch failed and returned 1, expecting : SELECT * FROM `order` WHERE ? >= (SELECT (quantity * unit_price) FROM `order_detail` WHERE order_detail_id = `order`.order_id);
PDOStatement::fetch returned false: SELECT * FROM `order` WHERE (SELECT (quantity * unit_price) FROM `order_detail` WHERE order_detail_id = `order`.order_id) >= ?;
But I expected this output instead:
SQLite query worked: SELECT * FROM `order` WHERE order_id = 1;
SQLite query worked: SELECT * FROM `order` WHERE order_id = ?;
SQLite query worked: SELECT * FROM `order` WHERE 1 = order_id;
SQLite query worked: SELECT * FROM `order` WHERE ? = order_id
SQLite query worked: SELECT * FROM `order` WHERE 1000 >= (SELECT (quantity * unit_price) FROM `order_detail` WHERE order_detail_id = `order`.order_id);
SQLite query worked: SELECT * FROM `order` WHERE (SELECT (quantity * unit_price) FROM `order_detail` WHERE order_detail_id = `order`.order_id) >= 1000;
SQLite query worked: SELECT * FROM `order` WHERE 1 >= (SELECT (quantity * unit_price) FROM `order_detail` WHERE order_detail_id = `order`.order_id);
SQLite query worked: SELECT * FROM `order` WHERE ? >= (SELECT (quantity * unit_price) FROM `order_detail` WHERE order_detail_id = `order`.order_id);
SQLite query worked: SELECT * FROM `order` WHERE ? >= (SELECT (quantity * unit_price) FROM `order_detail` WHERE order_detail_id = `order`.order_id);
SQLite query worked: SELECT * FROM `order` WHERE (SELECT (quantity * unit_price) FROM `order_detail` WHERE order_detail_id = `order`.order_id) >= ?;
PHP Version
PHP 8.5.12 (cli) (built: Oct 20 2026 04:19:35) (ZTS Visual C++ 2022 x64)
Copyright (c) The PHP Group
Built by The PHP Group
Zend Engine v4.5.12, Copyright (c) Zend Technologies
with Xdebug v3.5.3, Copyright (c) 2002-2026, by Derick Rethans
with Zend OPcache v8.5.12, Copyright (c), by Zend Technologies
Operating System
Windows 11
- Vorherrschende Sprache
- C
- Sterne
- 41.8k
- Forks
- 8.6k
- Ø Merge
- 2 T. 15 Std.
- Gemergte PRs (30 T.)
- 125
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus php/php-src
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag
-
ext/openssl: 8.2.31+/8.3.31+ fail to build against OpenSSL 1.0.2 (ASN1_STRING_get0_data in xp_ssl.c)OffenExtension: openssl Status: Needs Triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 79/100
php/php-src#25402 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Bug Status: Needs Triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
php/php-src#25397 · 3 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
SNMP accepts malformed remote portsEvtl. vergeben @somethingwithproof hat das vor 21 Tagen übernommen. Offen
Schwierigkeit 2/5 Ein halber Tag Anfängerfreundlichkeit 62/100
php/php-src#25137 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Bug Status: Needs Triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 64/100
Maintainer antworten meist innerhalb von 1 Tag
Ähnliche Issues
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag
-
ZIP/ZIPS decode dereferences NULL when the cached libdeflate decompressor can't be allocated (3.5 regression)Evtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
AcademySoftwareFoundation/openexr#2884 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
python-pillow/Pillow#10590 ·
Maintainer antworten meist innerhalb von 1 Tag
-
status: needs-triage type: bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
openwrt/packages#31407 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag