rfc:pdo_driver_specific_parsers
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:pdo_driver_specific_parsers [2024/04/23 08:32] – mbeccati | rfc:pdo_driver_specific_parsers [2024/05/20 17:46] (current) – Deprecation notice for "escaped question marks inside dollar quoted string" mbeccati | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: PDO Driver specific SQL parsers ====== | ====== PHP RFC: PDO Driver specific SQL parsers ====== | ||
- | * Version: 0.3 | + | * Version: 0.7 |
* Date: 2024-04-11 | * Date: 2024-04-11 | ||
* Author: Matteo Beccati, mbeccati@php.net | * Author: Matteo Beccati, mbeccati@php.net | ||
* Status: Under Discussion | * Status: Under Discussion | ||
- | * Discussion: https:// | + | * Discussion: |
- | * First Published at: http:// | + | * First Published at: [[https:// |
+ | * Implementation: | ||
===== Introduction ===== | ===== Introduction ===== | ||
Line 33: | Line 34: | ||
===== Proposal ===== | ===== Proposal ===== | ||
- | The proposal is to: | + | Following a detailed research (see below) for each of the databases currently supported by PDO in core, the proposal is to allow drivers to optionally provide a custom scanner function to handle their specific SQL dialect and: |
- | - change | + | - Change |
- | - allow drivers | + | - single and double quoted literals, with doubling as escaping mechanism |
- | - re-use the current version of the scanner | + | - two-dashes and C-style comments (non-nested, |
- | - add a pdo_pgsql | + | - Add a MySQL specific |
+ | - single and double quoted literals with both doubling and backslash as escaping mechanisms (MySQL default) | ||
+ | | ||
+ | - two-dashes (if followed by 1 whitespace), | ||
+ | - Tests, as necessary | ||
+ | - Add a PgSQL specific | ||
+ | - single and double quoted literals, with doubling as escaping mechanism | ||
+ | - C-style " | ||
+ | - Dollar-quoted string literals | ||
+ | - two-dashes and C-style comments (non-nested, | ||
+ | | ||
+ | - Tests, as necessary | ||
+ | - Add a SqLite | ||
+ | - single, double quoted, and backtick literals, with doubling as escaping mechanism | ||
+ | - square brackets quoting for identifiers | ||
+ | - two-dashes and C-style comments (non-nested) | ||
+ | - Tests, as necessary | ||
+ | |||
+ | In order to keep the change as simple as possible, the proposal tries to cover the default | ||
One important thing to mention is that the proposed changes are only targeting the part of PDO that scans the SQL query for parameter placeholders. Quoting literals or using parameters in queries is **not going to be affected**. | One important thing to mention is that the proposed changes are only targeting the part of PDO that scans the SQL query for parameter placeholders. Quoting literals or using parameters in queries is **not going to be affected**. | ||
Line 57: | Line 76: | ||
Each PDO driver defines already [[https:// | Each PDO driver defines already [[https:// | ||
+ | |||
+ | The rest of the implementation is the actual re2c scanner code, config.*, Makefile changes, etc. required to incorporate the driver specific scanner into the build. | ||
+ | |||
+ | In order to support dollar-quoted strings on Postgres, the functionality of custom quoting has been added to the common PDO parser function. The change has no side effects for other database drivers. | ||
+ | |||
+ | One minor potential BC-break was reported while researching bug [[https:// | ||
+ | |||
+ | '' | ||
+ | |||
+ | Such BC-compatibility can be removed in the next major version. | ||
+ | |||
===== Research on String Literals, Identifiers, | ===== Research on String Literals, Identifiers, | ||
Line 68: | Line 98: | ||
Several [[https:// | Several [[https:// | ||
+ | |||
+ | The RFC aims to support all the above kinds of string literals with string-affecting configuration variables set to their defaults. All comment types will be supported. | ||
==== PostgreSQL ==== | ==== PostgreSQL ==== | ||
Line 73: | Line 105: | ||
Escaping has evolved during the years. Historically accepted " | Escaping has evolved during the years. Historically accepted " | ||
- | It also accepts [[https:// | + | Postgres also supports [[https:// |
+ | |||
+ | It also accepts [[https:// | ||
<code php> | <code php> | ||
- | I had seen them being used when PostgreSQL started emitting warnings about backslashes in string literals, during the transition phase when '' | + | Lastly, [[https:// |
The behaviour of strings can also be manipulated in multiple ways through configuration variables, such as: [[https:// | The behaviour of strings can also be manipulated in multiple ways through configuration variables, such as: [[https:// | ||
- | |||
- | The RFC will ensure regular SQL standard string literals are supported on a Postgres instance with default configuration, | ||
- | |||
- | Support for escape string literal is out of scope of this RFC and should be documented as incompatible in the UPGRADING file, as weirdly enough it previously was the only fully-compatible format. | ||
About [[https:// | About [[https:// | ||
+ | |||
+ | The RFC aims to support all the above kinds of string literals with string-affecting configuration variables set to their defaults. Dollar-quoting support requires minimal changes to the common PDO parser function. All comment types are already supported, albeit support for nested comments will not be introduced. | ||
==== SQLite ==== | ==== SQLite ==== | ||
Line 97: | Line 129: | ||
Almost SQL standard [[https:// | Almost SQL standard [[https:// | ||
- | ==== Oracle ==== | + | The RFC aims to support single-quoted, double-quoted, |
- | + | ||
- | SQL standard string literals, according | + | |
- | It also supports alternative quoting, e.g. q'< | + | |
- | + | ||
- | [[https:// | + | |
- | + | ||
- | Almost SQL standard [[https:// | + | |
==== SQL Server ==== | ==== SQL Server ==== | ||
Line 113: | Line 138: | ||
Almost SQL standard [[https:// | Almost SQL standard [[https:// | ||
+ | |||
+ | No custom parser is planned in this RFC: the default scanner will be used by default, bringing compatibility for SQL standard string literals, identifiers, | ||
==== Firebird ==== | ==== Firebird ==== | ||
Line 120: | Line 147: | ||
Almost SQL standard [[https:// | Almost SQL standard [[https:// | ||
+ | |||
+ | No custom parser is planned in this RFC: the default scanner will be used by default, bringing compatibility for SQL standard string literals, identifiers, | ||
+ | |||
==== ODBC ==== | ==== ODBC ==== | ||
Since ODBC can connect to various types of databases, the SQL standard parser hopefully will suffice. | Since ODBC can connect to various types of databases, the SQL standard parser hopefully will suffice. | ||
+ | |||
+ | ==== Oracle ==== | ||
+ | |||
+ | SQL standard string literals, according to the [[https:// | ||
+ | It also supports alternative quoting, e.g. q'< | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | Almost SQL standard [[https:// | ||
+ | |||
+ | The OCI driver lives in PECL: the default scanner will be used by default, bringing compatibility for SQL standard string literals, identifiers, | ||
Line 130: | Line 171: | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
- | No expected | + | No BC breaks, but a deprecation notice will be raised when using the " |
Users having applications that can work with multiple database engines should still be very careful and write portable queries, possibly using the '' | Users having applications that can work with multiple database engines should still be very careful and write portable queries, possibly using the '' | ||
Line 160: | Line 201: | ||
===== Unaffected PHP Functionality ===== | ===== Unaffected PHP Functionality ===== | ||
Anything not related to PDO scanning the SQL query for parameter placeholders. | Anything not related to PDO scanning the SQL query for parameter placeholders. | ||
+ | |||
+ | ===== Out Of Scope ===== | ||
+ | |||
+ | ==== Dynamic changes to the scanner ==== | ||
+ | The scanners are generated when PHP is compiled and, currently, cannot be modified at runtime. However, some databases allow configuration directives or '' | ||
+ | |||
+ | Being able to understand all possible combinations would require tracking what directives are different from the expected default and having a number of scanners inside each driver for each possible permutation of such configuration directives. | ||
===== Future Scope ===== | ===== Future Scope ===== | ||
- | If necessary, support | + | Evaluate supporting |
===== Proposed Voting Choices ===== | ===== Proposed Voting Choices ===== | ||
Line 169: | Line 217: | ||
===== Patches and Tests ===== | ===== Patches and Tests ===== | ||
- | [[https:// | + | [[https:// |
===== References ===== | ===== References ===== |
rfc/pdo_driver_specific_parsers.1713861154.txt.gz · Last modified: 2024/04/23 08:32 by mbeccati