summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDries Buytaert2009-11-23 22:31:42 (GMT)
committerDries Buytaert2009-11-23 22:31:42 (GMT)
commita902f664d9209f81903619913d754065461523a7 (patch)
tree669be95d475b90ca598e301b41db9026847d834a
parent226341242bf4e7ea16ec7d6f2f81091464207318 (diff)
- Patch #564852 by justinrandell, mcarbone, Crell: fixed subselect in WHERE condition with multiple placeholders cause invalid/duplicate placeholders.
-rw-r--r--includes/database/query.inc7
-rw-r--r--modules/simpletest/tests/database_test.test21
2 files changed, 26 insertions, 2 deletions
diff --git a/includes/database/query.inc b/includes/database/query.inc
index 9932757..9205fe4 100644
--- a/includes/database/query.inc
+++ b/includes/database/query.inc
@@ -925,6 +925,7 @@ class DeleteQuery extends Query implements QueryConditionInterface {
$query = 'DELETE FROM {' . $this->connection->escapeTable($this->table) . '} ';
if (count($this->condition)) {
+
$this->condition->compile($this->connection, $this);
$query .= "\nWHERE " . $this->condition;
}
@@ -1234,6 +1235,8 @@ class DatabaseCondition implements QueryConditionInterface, Countable {
}
else {
// It's a structured condition, so parse it out accordingly.
+ // Note that $condition['field'] will only be an object for a dependent
+ // DatabaseCondition object, not for a dependent subquery.
if ($condition['field'] instanceof QueryConditionInterface) {
// Compile the sub-condition recursively and add it to the list.
$condition['field']->compile($connection, $queryPlaceholder);
@@ -1257,7 +1260,8 @@ class DatabaseCondition implements QueryConditionInterface, Countable {
$operator += $operator_defaults;
$placeholders = array();
- if ($condition['value'] instanceof SelectQuery) {
+ if ($condition['value'] instanceof SelectQueryInterface) {
+ $condition['value']->compile($connection, $queryPlaceholder);
$placeholders[] = (string)$condition['value'];
$arguments += $condition['value']->arguments();
}
@@ -1275,7 +1279,6 @@ class DatabaseCondition implements QueryConditionInterface, Countable {
}
}
$condition_fragments[] = ' (' . $condition['field'] . ' ' . $operator['operator'] . ' ' . $operator['prefix'] . implode($operator['delimiter'], $placeholders) . $operator['postfix'] . ') ';
-
}
}
}
diff --git a/modules/simpletest/tests/database_test.test b/modules/simpletest/tests/database_test.test
index 8970224..43f97d2 100644
--- a/modules/simpletest/tests/database_test.test
+++ b/modules/simpletest/tests/database_test.test
@@ -945,6 +945,27 @@ class DatabaseDeleteTruncateTestCase extends DatabaseTestCase {
}
/**
+ * Confirm that we can use a subselect in a delete successfully.
+ */
+ function testSubselectDelete() {
+ $num_records_before = db_query('SELECT COUNT(*) FROM {test_task}')->fetchField();
+ $pid_to_delete = db_query("SELECT * FROM {test_task} WHERE task = 'sleep'")->fetchField();
+
+ $subquery = db_select('test', 't')
+ ->fields('t', array('id'))
+ ->condition('t.id', array($pid_to_delete), 'IN');
+ $delete = db_delete('test_task')
+ ->condition('task', 'sleep')
+ ->condition('pid', $subquery, 'IN');
+
+ $num_deleted = $delete->execute();
+ $this->assertEqual($num_deleted, 1, t("Deleted 1 record."));
+
+ $num_records_after = db_query('SELECT COUNT(*) FROM {test_task}')->fetchField();
+ $this->assertEqual($num_records_before, $num_records_after + $num_deleted, t('Deletion adds up.'));
+ }
+
+ /**
* Confirm that we can delete a single record successfully.
*/
function testSimpleDelete() {