[php-src] Issue #22497: Add PDO::SQLITE_ATTR_DQS to disable SQLite Double-Quoted String literals configuration
| From: | agnes-ze-yerman | Date: | Sun, 28 Jun 2026 09:05:47 +0000 |
| Subject: | [php-src] Issue #22497: Add PDO::SQLITE_ATTR_DQS to disable SQLite Double-Quoted String literals configuration | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-252298@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/22497
Author: agnes-ze-yerman
### Description
Full disclosure: This feature request was written by an LLM but I've double checked it and also
implemented it on my machine to confirm it working.
# Problem description:
By default, SQLite maintains a legacy fallback behavior known as "Double-Quoted String
Literals" (DQS). If a developer uses a double-quoted string in a query (e.g., "foo")
and it does not match an existing column name, SQLite silently falls back to treating it as a string
literal instead of throwing a syntax/identifier error.
This behavior frequently hides typos in queries, leads to unexpected runtime bugs, and diverges from
standard SQL behavior found in databases like PostgreSQL and MySQL.
The official SQLite documentation explicitly warns against this legacy misfeature and recommends
disabling it:
> "The use of double-quoted string literals is an explicit misfeature of SQLite. [...]
> Applications should be compiled with -DSQLITE_DQS=0 to disable this behavior, or they should use the
> sqlite3_db_config(db, SQLITE_DBCONFIG_DQS_DML, 0, NULL) and sqlite3_db_config(db,
> SQLITE_DBCONFIG_DQS_DDL, 0, NULL) interfaces at runtime to turn it off."
# Proposed Solution:
To bring PHP's pdo_sqlite driver up to modern safety standards without breaking existing
applications, we propose exposing a new driver-specific attribute: \Pdo\Sqlite::ATTR_DQS (or
PDO::SQLITE_ATTR_DQS).
This allows developers to explicitly disable DQS on a per-connection basis via their PDO options
array:
```
$pdo = new PDO('sqlite:database.sqlite', null, null, [
\Pdo\Sqlite::ATTR_DQS => false, // Disables unsafe DQS DML/DDL fallbacks
]);
```
# Implementation Overview:
1. php_pdo_sqlite_int.h: Add PDO_SQLITE_ATTR_DQS to the driver-specific attributes enum.
2. pdo_sqlite.c: Register the class constant under PHP_MINIT_FUNCTION(pdo_sqlite).
3. sqlite_driver.c:
- In sqlite_handle_factory, check if the option is passed via driver_options.
- Use sqlite3_db_config(H->db, SQLITE_DBCONFIG_DQS_DML, setting, NULL) and
SQLITE_DBCONFIG_DQS_DDL to toggle the feature at the connection layer.
- Update sqlite_handle_set_attribute and sqlite_handle_get_attribute to support runtime toggling
and querying.