Skip to content

Commit

Permalink
MDL-29815 dbtest - added one test_get_records_sql_complicated related…
Browse files Browse the repository at this point in the history
… test
  • Loading branch information
stronk7 committed Oct 25, 2011
1 parent c963b7e commit c96dedd
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/dml/simpletest/testdml.php
Expand Up @@ -3755,6 +3755,28 @@ public function test_get_records_sql_complicated() {
$records = $DB->get_records_sql($sql, null);
$this->assertEqual($result, $records);

// another grouping by CASE expression just to ensure it works ok for multiple WHEN
$sql = "SELECT CASE name
WHEN 'xyz' THEN 'last'
WHEN 'def' THEN 'mid'
WHEN 'abc' THEN 'first'
END AS casecol,
COUNT(1) AS countrecs,
MAX(name) AS maxname
FROM {{$tablename}}
GROUP BY CASE name
WHEN 'xyz' THEN 'last'
WHEN 'def' THEN 'mid'
WHEN 'abc' THEN 'first'
END
ORDER BY casecol DESC";
$result = array(
'mid' => (object)array('casecol' => 'mid', 'countrecs' => 1, 'maxname' => 'def'),
'last' => (object)array('casecol' => 'last', 'countrecs' => 1, 'maxname' => 'xyz'),
'first'=> (object)array('casecol' => 'first', 'countrecs' => 2, 'maxname' => 'abc'));
$records = $DB->get_records_sql($sql, null);
$this->assertEqual($result, $records);

// test limits in queries with DISTINCT/ALL clauses and multiple whitespace. MDL-25268
$sql = "SELECT DISTINCT course
FROM {{$tablename}}
Expand Down

0 comments on commit c96dedd

Please sign in to comment.