Skip to content

Honor PDO::ATTR_CASE and PDO::ATTR_ORACLE_NULLS without affecting internal queries #475

Description

@JanJakes

Problem

WP_MySQL_On_SQLite forwards numeric PDO constructor options and most setAttribute() calls to the underlying SQLite PDO connection. Setting PDO::ATTR_CASE or PDO::ATTR_ORACLE_NULLS therefore changes internal query results as well as caller-visible results.

For PDO::ATTR_CASE, constructing the driver with PDO::CASE_LOWER lowercases keys returned by internal INFORMATION_SCHEMA queries. Driver code expects canonical keys such as COLUMN_NAME, so a subsequent CREATE TABLE emits an undefined-key warning and fails.

PDO::ATTR_ORACLE_NULLS can silently corrupt schema metadata. With PDO::NULL_TO_STRING, even CREATE TABLE t (id INT PRIMARY KEY) creates the SQLite column with DEFAULT ''. With PDO::NULL_EMPTY_STRING, internal metadata fields become null and operations such as SHOW CREATE TABLE fail.

Proposed solution

Treat both attributes as caller-visible wrapper state, similarly to PDO::ATTR_ERRMODE:

  • Track the requested case and Oracle null modes in WP_MySQL_On_SQLite and expose them through setAttribute() and getAttribute().
  • Keep the underlying SQLite connection at PDO::CASE_NATURAL and PDO::NULL_NATURAL for internal queries.
  • Apply the requested modes only to caller-visible result statements, including SELECT, SHOW, DESCRIBE, and synthesized result sets.
  • For PDO::ATTR_CASE, scope the requested mode around preparing and executing result statements, then restore PDO::CASE_NATURAL in a finally block. PDO captures folded result-column names when a statement is executed.
  • For PDO::ATTR_ORACLE_NULLS, apply the requested null conversion in the result-statement layer. PDO SQLite consults the connection-level setting when rows are fetched, so temporarily changing it only during execution is insufficient and leaving it enabled would affect later internal queries.

Add coverage for constructor options and runtime attribute changes using PDO::CASE_LOWER, PDO::CASE_UPPER, PDO::NULL_TO_STRING, and PDO::NULL_EMPTY_STRING. Verify fetch modes, associative and object results, getColumnMeta(), DDL and schema reconstruction, SHOW CREATE TABLE, and behavior across the supported PHP versions.

This is a follow-up to #471.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions