Commit eac93fa4 authored by Dries's avatar Dries

- Patch #496500 by Moshe Weitzman, Crell, Berdir: remove global placeholder...

- Patch #496500 by Moshe Weitzman, Crell, Berdir: remove global placeholder counter so we can support Views caching.
parent a9762cd3
...@@ -316,6 +316,13 @@ abstract class DatabaseConnection extends PDO { ...@@ -316,6 +316,13 @@ abstract class DatabaseConnection extends PDO {
*/ */
protected $schema = NULL; protected $schema = NULL;
/**
* A unique number used for dynamic placeholders.
*
* It gets reset after every executed query.
*/
protected $nextPlaceholder = 1;
function __construct($dsn, $username, $password, $driver_options = array()) { function __construct($dsn, $username, $password, $driver_options = array()) {
// Because the other methods don't seem to work right. // Because the other methods don't seem to work right.
$driver_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION; $driver_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
...@@ -329,6 +336,20 @@ function __construct($dsn, $username, $password, $driver_options = array()) { ...@@ -329,6 +336,20 @@ function __construct($dsn, $username, $password, $driver_options = array()) {
} }
} }
/**
* Reset the next placeholder number back to 1.
*/
public function resetPlaceholder() {
$this->nextPlaceholder = 1;
}
/**
* Get the current unique placeholder number and increment it.
*/
public function getNextPlaceholder() {
return $this->nextPlaceholder++;
}
/** /**
* Return the default query options for any given query. * Return the default query options for any given query.
* *
...@@ -567,6 +588,9 @@ public function query($query, array $args = array(), $options = array()) { ...@@ -567,6 +588,9 @@ public function query($query, array $args = array(), $options = array()) {
$stmt->execute($args, $options); $stmt->execute($args, $options);
} }
// Reset the placeholder numbering.
$this->resetPlaceholder();
// Depending on the type of query we may need to return a different value. // Depending on the type of query we may need to return a different value.
// See DatabaseConnection::defaultOptions() for a description of each value. // See DatabaseConnection::defaultOptions() for a description of each value.
switch ($options['return']) { switch ($options['return']) {
......
...@@ -68,6 +68,8 @@ public function query($query, array $args = array(), $options = array()) { ...@@ -68,6 +68,8 @@ public function query($query, array $args = array(), $options = array()) {
$stmt = $this->prepareQuery($query, !$modified); $stmt = $this->prepareQuery($query, !$modified);
$stmt->execute($args, $options); $stmt->execute($args, $options);
} }
// Reset the placeholder numbering.
$this->resetPlaceholder();
switch ($options['return']) { switch ($options['return']) {
case Database::RETURN_STATEMENT: case Database::RETURN_STATEMENT:
......
...@@ -1161,13 +1161,6 @@ public function arguments() { ...@@ -1161,13 +1161,6 @@ public function arguments() {
} }
public function compile(DatabaseConnection $connection) { public function compile(DatabaseConnection $connection) {
// This value is static, so it will increment across the entire request
// rather than just this query. That is OK, because we only need definitive
// placeholder names if we're going to use them for _alter hooks, which we
// are not. The alter hook would intervene before compilation.
// $next_placeholder does not use drupal_static as it increments and should
// never be reset during a request.
static $next_placeholder = 1;
if ($this->changed) { if ($this->changed) {
...@@ -1220,7 +1213,7 @@ public function compile(DatabaseConnection $connection) { ...@@ -1220,7 +1213,7 @@ public function compile(DatabaseConnection $connection) {
} }
if ($operator['use_value']) { if ($operator['use_value']) {
foreach ($condition['value'] as $value) { foreach ($condition['value'] as $value) {
$placeholder = ':db_condition_placeholder_' . $next_placeholder++; $placeholder = ':db_condition_placeholder_' . $connection->getNextPlaceholder();
$arguments[$placeholder] = $value; $arguments[$placeholder] = $value;
$placeholders[] = $placeholder; $placeholders[] = $placeholder;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment