function DatabaseSelectComplexTestCase::testNestedConditions
Confirm that we can properly nest conditional clauses.
File
-
modules/
simpletest/ tests/ database_test.test, line 2416
Class
- DatabaseSelectComplexTestCase
- Test more complex select statements.
Code
function testNestedConditions() {
// This query should translate to:
// "SELECT job FROM {test} WHERE name = 'Paul' AND (age = 26 OR age = 27)"
// That should find only one record. Yes it's a non-optimal way of writing
// that query but that's not the point!
$query = db_select('test');
$query->addField('test', 'job');
$query->condition('name', 'Paul');
$query->condition(db_or()->condition('age', 26)
->condition('age', 27));
$job = $query->execute()
->fetchField();
$this->assertEqual($job, 'Songwriter', 'Correct data retrieved.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.