Permalink
Browse files

MDL-29815 dbtest - added one test_get_records_sql_complicated related…

… test
  • Loading branch information...
1 parent c963b7e commit c96deddbe77739c3fcce1a1743c31bf77c877efe @stronk7 stronk7 committed Oct 25, 2011
Showing with 22 additions and 0 deletions.
  1. +22 −0 lib/dml/simpletest/testdml.php
@@ -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}}

0 comments on commit c96dedd

Please sign in to comment.