Commit 800f2d9a authored by Dries's avatar Dries

- Patch #467984 by Berdir: fixed some database glitches and extended the tests.

parent 092726df
......@@ -461,7 +461,7 @@ public function havingArguments() {
}
public function having($snippet, $args = array()) {
$this->query->where($snippet, $args);
$this->query->having($snippet, $args);
return $this;
}
......@@ -570,7 +570,8 @@ public function countQuery() {
// 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 @@ public function getArguments() {
$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 @@ public function rightJoin($table, $alias = NULL, $condition = NULL, $arguments =
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 @@ public function __toString() {
}
// 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 {
......
......@@ -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.');
}
}
......
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