]> git.mjollnir.org Git - moodle.git/commitdiff
lib/dml - 'complicated sql' unit test MDL-19645
authorDan Poltawski <dan.poltawski@lancaster.ac.uk>
Tue, 27 Oct 2009 23:25:07 +0000 (23:25 +0000)
committerDan Poltawski <dan.poltawski@lancaster.ac.uk>
Tue, 27 Oct 2009 23:25:07 +0000 (23:25 +0000)
I have just added one specific example SQL syntax which was breaking on
earlier versions of sqlite. We need to add more variations used throughout
moodle so different engines can be properly tested for compatibility.

lib/dml/simpletest/testdml.php

index 0ab3aae6baee822f8345eadb6ac36164842ce4b6..cf931ed96a395e8052fd62c12a5a8b68a5bfca1a 100755 (executable)
@@ -2332,6 +2332,41 @@ class dml_test extends UnitTestCase {
             $this->assertTrue(true, 'DB Transactions not supported. Test skipped');
         }
     }
+
+    /**
+     * Test some more complex SQL syntax which moodle uses and depends on to work
+     * useful to determine if new database libraries can be supported.
+     */
+    public function test_get_records_sql_complicated() {
+        global $CFG;
+        $DB = $this->tdb;
+        $dbman = $DB->get_manager();
+
+        $table = $this->get_test_table();
+        $tablename = $table->getName();
+
+        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
+        $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
+        $dbman->create_table($table);
+        $this->tables[$tablename] = $table;
+
+        $DB->insert_record($tablename, array('course' => 3));
+        $DB->insert_record($tablename, array('course' => 3));
+        $DB->insert_record($tablename, array('course' => 5));
+        $DB->insert_record($tablename, array('course' => 2));
+
+        // we have sql like this in moodle, this syntax breaks on older versions of sqlite for example..
+        $sql = 'SELECT a.id AS id, a.course AS course
+                FROM {'.$tablename.'} a
+                JOIN (SELECT * FROM {'.$tablename.'}) b
+                ON a.id = b.id
+                WHERE a.course = ?';
+
+        $this->assertTrue($records = $DB->get_records_sql($sql, array(3)));
+        $this->assertEqual(2, count($records));
+        $this->assertEqual(1, reset($records)->id);
+        $this->assertEqual(2, next($records)->id);
+    }
 }
 
 /**