summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--includes/database/database.inc24
-rw-r--r--includes/database/pgsql/database.inc2
-rw-r--r--includes/database/query.inc9
3 files changed, 27 insertions, 8 deletions
diff --git a/includes/database/database.inc b/includes/database/database.inc
index 22bd8fe2ef54..24ac3c42cae4 100644
--- a/includes/database/database.inc
+++ b/includes/database/database.inc
@@ -316,6 +316,13 @@ abstract class DatabaseConnection extends PDO {
*/
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()) {
// Because the other methods don't seem to work right.
$driver_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
@@ -330,6 +337,20 @@ abstract class DatabaseConnection extends PDO {
}
/**
+ * 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.
*
* A given query can be customized with a number of option flags in an
@@ -567,6 +588,9 @@ abstract class DatabaseConnection extends PDO {
$stmt->execute($args, $options);
}
+ // Reset the placeholder numbering.
+ $this->resetPlaceholder();
+
// Depending on the type of query we may need to return a different value.
// See DatabaseConnection::defaultOptions() for a description of each value.
switch ($options['return']) {
diff --git a/includes/database/pgsql/database.inc b/includes/database/pgsql/database.inc
index ec68c3a396a2..d3246274d1f5 100644
--- a/includes/database/pgsql/database.inc
+++ b/includes/database/pgsql/database.inc
@@ -68,6 +68,8 @@ class DatabaseConnection_pgsql extends DatabaseConnection {
$stmt = $this->prepareQuery($query, !$modified);
$stmt->execute($args, $options);
}
+ // Reset the placeholder numbering.
+ $this->resetPlaceholder();
switch ($options['return']) {
case Database::RETURN_STATEMENT:
diff --git a/includes/database/query.inc b/includes/database/query.inc
index b6b47f48d901..6ca869e52a0a 100644
--- a/includes/database/query.inc
+++ b/includes/database/query.inc
@@ -1161,13 +1161,6 @@ class DatabaseCondition implements QueryConditionInterface, Countable {
}
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) {
@@ -1220,7 +1213,7 @@ class DatabaseCondition implements QueryConditionInterface, Countable {
}
if ($operator['use_value']) {
foreach ($condition['value'] as $value) {
- $placeholder = ':db_condition_placeholder_' . $next_placeholder++;
+ $placeholder = ':db_condition_placeholder_' . $connection->getNextPlaceholder();
$arguments[$placeholder] = $value;
$placeholders[] = $placeholder;
}