function DatabaseSelectComplexTestCase::testLeftOuterJoin in Drupal 7
Test LEFT OUTER joins.
File
- modules/
simpletest/ tests/ database_test.test, line 2045
Class
- DatabaseSelectComplexTestCase
- Test more complex select statements.
Code
function testLeftOuterJoin() {
$query = db_select('test', 'p');
$people_alias = $query
->leftJoin('test_task', 't', 't.pid = p.id');
$name_field = $query
->addField('p', 'name', 'name');
$task_field = $query
->addField($people_alias, 'task', 'task');
$priority_field = $query
->addField($people_alias, 'priority', 'priority');
$query
->orderBy($name_field);
$result = $query
->execute();
$num_records = 0;
$last_name = 0;
foreach ($result as $record) {
$num_records++;
$this
->assertTrue(strcmp($record->{$name_field}, $last_name) >= 0, 'Results returned in correct order.');
$last_priority = $record->{$name_field};
}
$this
->assertEqual($num_records, 8, 'Returned the correct number of rows.');
}