- Patch #701888 by jhodgdon: subqueries are not altered and test clean-up.

merge-requests/26/head
Dries Buytaert 2010-04-27 10:42:58 +00:00
parent 3d84cef194
commit ca0323d2de
2 changed files with 29 additions and 18 deletions

View File

@ -1319,7 +1319,10 @@ class SelectQuery extends Query implements SelectQueryInterface {
// If the table is a subquery, compile it and integrate it into this query.
if ($table['table'] instanceof SelectQueryInterface) {
$table_string = '(' . (string)$table['table'] . ')';
// Run preparation steps on this sub-query before converting to string.
$subquery = $table['table'];
$subquery->preExecute();
$table_string = '(' . (string) $subquery . ')';
}
else {
$table_string = '{' . $this->connection->escapeTable($table['table']) . '}';

View File

@ -2326,22 +2326,6 @@ class DatabaseAlterTestCase extends DatabaseTestCase {
$this->assertEqual($records[0]->$pid_field, 1, t('Correct data retrieved.'));
$this->assertEqual($records[0]->$task_field, 'sleep', t('Correct data retrieved.'));
}
}
/**
* Select alter tests, part 2.
*
* @see database_test_query_alter()
*/
class DatabaseAlter2TestCase extends DatabaseTestCase {
public static function getInfo() {
return array(
'name' => 'Query altering tests, part 2',
'description' => 'Test the hook_query_alter capabilities of the Select builder.',
'group' => 'Database',
);
}
/**
* Test that we can alter the fields of a query.
@ -2390,6 +2374,31 @@ class DatabaseAlter2TestCase extends DatabaseTestCase {
$this->assertEqual($num_records, 4, t('Returned the correct number of rows.'));
}
/**
* Test that we can do basic alters on subqueries.
*/
function testSimpleAlterSubquery() {
// Create a sub-query with an alter tag.
$subquery = db_select('test', 'p');
$subquery->addField('p', 'name');
$subquery->addField('p', 'id');
// Pick out George.
$subquery->condition('age', 27);
$subquery->addExpression("age*2", 'double_age');
// This query alter should change it to age * 3.
$subquery->addTag('database_test_alter_change_expressions');
// Create a main query and join to sub-query.
$query = db_select('test_task', 'tt');
$query->join($subquery, 'pq', 'pq.id = tt.pid');
$age_field = $query->addField('pq', 'double_age');
$name_field = $query->addField('pq', 'name');
$record = $query->execute()->fetch();
$this->assertEqual($record->$name_field, 'George', t('Fetched name is correct.'));
$this->assertEqual($record->$age_field, 27*3, t('Fetched age expression is correct.'));
}
}
/**
@ -3227,5 +3236,4 @@ class DatabaseEmptyStatementTestCase extends DrupalWebTestCase {
$this->assertEqual($result->fetchAll(), array(), t('Empty array returned from empty result set.'));
}
}