summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--includes/database/select.inc11
-rw-r--r--modules/simpletest/tests/database_test.test40
2 files changed, 46 insertions, 5 deletions
diff --git a/includes/database/select.inc b/includes/database/select.inc
index ef0455fca..74a66b954 100644
--- a/includes/database/select.inc
+++ b/includes/database/select.inc
@@ -461,7 +461,7 @@ class SelectQueryExtender implements SelectQueryInterface {
}
public function having($snippet, $args = array()) {
- $this->query->where($snippet, $args);
+ $this->query->having($snippet, $args);
return $this;
}
@@ -570,7 +570,8 @@ class SelectQueryExtender implements SelectQueryInterface {
// Also remove 'all_fields' statements, which are expanded into tablename.*
// when the query is executed.
- foreach ($count->tables as $alias => &$table) {
+ $tables = &$count->getTables();
+ foreach ($tables as $alias => &$table) {
unset($table['all_fields']);
}
@@ -866,7 +867,7 @@ class SelectQuery extends Query implements SelectQueryInterface {
$args += $table['arguments'];
}
// If this table is a subquery, grab its arguments recursively.
- if ($table['table'] instanceof SelectQuery) {
+ if ($table['table'] instanceof SelectQueryInterface) {
$args += $table['table']->getArguments();
}
}
@@ -985,7 +986,7 @@ class SelectQuery extends Query implements SelectQueryInterface {
public function addJoin($type, $table, $alias = NULL, $condition = NULL, $arguments = array()) {
if (empty($alias)) {
- if ($table instanceof SelectQuery) {
+ if ($table instanceof SelectQueryInterface) {
$alias = 'subquery';
}
else {
@@ -1089,7 +1090,7 @@ class SelectQuery extends Query implements SelectQueryInterface {
}
// If the table is a subquery, compile it and integrate it into this query.
- if ($table['table'] instanceof SelectQuery) {
+ if ($table['table'] instanceof SelectQueryInterface) {
$table_string = '(' . (string)$table['table'] .')';
}
else {
diff --git a/modules/simpletest/tests/database_test.test b/modules/simpletest/tests/database_test.test
index da3add21a..590e9c102 100644
--- a/modules/simpletest/tests/database_test.test
+++ b/modules/simpletest/tests/database_test.test
@@ -1689,6 +1689,46 @@ class DatabaseSelectPagerDefaultTestCase extends DatabaseTestCase {
$this->assertEqual(count($data->names), $correct_number, t('Correct number of records returned by pager: @number', array('@number' => $correct_number)));
}
}
+
+ /**
+ * Confirm that a pager query with inner pager query returns valid results.
+ *
+ * This is a regression test for #467984.
+ */
+ function testInnerPagerQuery() {
+ $query = db_select('test', 't')->extend('PagerDefault');
+ $query
+ ->fields('t', array('age'))
+ ->orderBy('age')
+ ->limit(5);
+
+ $outer_query = db_select($query);
+ $outer_query->addField('subquery', 'age');
+
+ $ages = $outer_query
+ ->execute()
+ ->fetchCol();
+ $this->assertEqual($ages, array(25, 26, 27, 28), 'Inner pager query returned the correct ages.');
+ }
+
+ /**
+ * Confirm that a paging query with a having expression returns valid results.
+ *
+ * This is a regression test for #467984.
+ */
+ function testHavingPagerQuery() {
+ $query = db_select('test', 't')->extend('PagerDefault');
+ $query
+ ->fields('t', array('age'))
+ ->orderBy('age')
+ ->having('COUNT(age) > :count', array(':count' => 1))
+ ->limit(5);
+
+ $ages = $query
+ ->execute()
+ ->fetchCol();
+ $this->assertEqual($ages, array(25), ' pager query with having expression returned the correct ages.');
+ }
}