public function SqlServerSelectTest::testCrossJoin in Drupal driver for SQL Server and SQL Azure 7.2
Same name and namespace in other branches
- 7.3 tests/sqlsrv.select.test \SqlServerSelectTest::testCrossJoin()
Test cross join.
File
- tests/
sqlsrv.select.test, line 87 - Support tests for SQL Server.
Class
- SqlServerSelectTest
- @file Support tests for SQL Server.
Code
public function testCrossJoin() {
// SelectQuery in SQL Server driver
// is expanding expressions into a cross
// join statement. This allows the use
// of these expressions in the Aggregate
// or Where part of the query.
$query = db_select('test_task', 't');
// Cast the task to an accent insensitive collation in an expression.
$query
->addExpression('(t.task collate Latin1_General_CS_AI)', 'ci_task');
// Add condition over that expression.
$query
->where('ci_task = :param', array(
':param' => 'slëep',
));
$result = $query
->execute();
$num_records = 0;
foreach ($result as $record) {
$num_records++;
}
$this
->assertEqual($num_records, 2, t('Returned the correct number of total rows.'));
// There is a special case, if the query is an aggregate
// and an expression is used, this expression must be part of the aggregate.
$query = db_select('test_task', 't');
// Cast the task to an accent insensitive collation in an expression.
$query
->addExpression('(t.task collate Latin1_General_CS_AI)', 'ci_task');
// Add condition over that expression.
$query
->where('ci_task = :param', array(
':param' => 'slëep',
));
// Add condition over that expression.
$query
->groupBy('t.task');
$result = $query
->execute();
$num_records = 0;
foreach ($result as $record) {
$num_records++;
}
$this
->assertEqual($num_records, 1, t('Returned the correct number of total rows.'));
}