Skip to content

Add PDO::SQLITE_ATTR_DQS to disable SQLite Double-Quoted String literals configuration #22497

Description

@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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions