DBAL-78: Native support for parameter lists #2009

Closed
doctrinebot opened this Issue Dec 24, 2010 · 4 comments

2 participants

@doctrinebot

Jira issue originally created by user @beberlei:

Prerequisites:

  1. Detection of this mode has to be super-fast. It should not have an auto-detection but should be triggered explicitly.
  2. This mode cannot be supported after $conn->prepare(). It is only viable for $conn->executeQuery() or $conn->executeUpdate().

Case 1: Positional

$stmt = $conn->executeQuery("SELECT a.id FROM articles a WHERE a.id IN (?) AND a.foo = ?",
    array($paramList, $foo), array( Connection::PARAM*ARRAY => PDO::PARAM_INT) , PDO:PARAM*STR ),
    Connection::FLAG*EXPAND*ARRAYS
);

Would internally, right before execution, be rewritten to:

$c = count($paramList); // 3!
"SELECT a.id FROM articles a WHERE a.id IN (?, ?, ?) AND a.foo = ?"

Case 2: Named

$stmt = $conn->executeQuery("SELECT a.id FROM articles a WHERE a.id IN (:id) AND a.foo = :bar",
    array('id' => $paramList, 'bar' => $foo),
    array( array(Connection::PARAM*ARRAY => PDO::PARAM_INT), PDO::PARAM*STR ),
    Connection::FLAG*EXPAND*ARRAYS
);

Would internally, right before execution, be rewritten to:

$c = count($paramList); // 3!
"SELECT a.id FROM articles a WHERE a.id IN (:id1, :id2, :id3) AND a.foo = :bar"
@doctrinebot

Comment created by @beberlei:

Implementing this for Named parameters is not really possible without re-parsing the query after every replacement just because the named parameters can occur more then once and this messes with the positions.

@doctrinebot

Comment created by @beberlei:

Using arrays as param list is a very bad idea performance wise (and also code handling).

Algorithm now:

  1. New Constants Connection::PARAMINT_ARRAY and PARAM_STR_ARRAY, being apart by Connection::ARRAY_TYPE_OFFSET from their PDO::PARAM_STR and PDO:PARAMINT plain values.
  2. Detect if there is one _ARRAY param. If not abort expansion (complexity O(T)) where T is the number of types.
  3. Parse SQL statement for positional needle => character position
  4. Iterate param list and inline arrays values
@doctrinebot

Comment created by @beberlei:

Implemented in df50f44

@doctrinebot

Issue was closed with resolution "Fixed"

@beberlei beberlei was assigned by doctrinebot Dec 7, 2015
@doctrinebot doctrinebot added this to the 2.1 milestone Dec 7, 2015
@doctrinebot doctrinebot closed this Dec 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment