Index: moodle_database.php =================================================================== RCS file: /cvsroot/moodle/moodle/lib/dml/moodle_database.php,v retrieving revision 1.123 diff -u -r1.123 moodle_database.php --- moodle_database.php 25 Aug 2010 11:18:37 -0000 1.123 +++ moodle_database.php 1 Sep 2010 10:31:29 -0000 @@ -632,6 +632,11 @@ // convert table names $sql = $this->fix_table_names($sql); + // cast booleans to 1/0 int + foreach ($params as $key => $value) { + $params[$key] = is_bool($value) ? (int)$value : $value; + } + // NICOLAS C: Fixed regexp for negative backwards lookahead of double colons. Thanks for Sam Marshall's help $named_count = preg_match_all('/(?assertTrue($e instanceof moodle_exception); } - + // Booleans in NAMED params are casting to 1/0 int + $sql = "SELECT * FROM {".$tablename."} WHERE course = ? OR course = ?"; + $params = array(true, false); + list($sql, $params) = $DB->fix_sql_params($sql, $params); + $this->assertTrue(reset($params) === 1); + $this->assertTrue(next($params) === 0); + + // Booleans in QM params are casting to 1/0 int + $sql = "SELECT * FROM {".$tablename."} WHERE course = :course1 OR course = :course2"; + $params = array('course1' => true, 'course2' => false); + list($sql, $params) = $DB->fix_sql_params($sql, $params); + $this->assertTrue(reset($params) === 1); + $this->assertTrue(next($params) === 0); + + // Booleans in DOLLAR params are casting to 1/0 int + $sql = "SELECT * FROM {".$tablename."} WHERE course = \$1 OR course = \$2"; + $params = array(true, false); + list($sql, $params) = $DB->fix_sql_params($sql, $params); + $this->assertTrue(reset($params) === 1); + $this->assertTrue(next($params) === 0); } public function testGetTables() { @@ -732,6 +751,12 @@ $this->assertFalse(empty($records[1]->id)); $this->assertEqual(4, count($records)); + // Booleans into params + $records = $DB->get_records($tablename, array('course' => true)); + $this->assertEqual(0, count($records)); + $records = $DB->get_records($tablename, array('course' => false)); + $this->assertEqual(0, count($records)); + // note: delegate limits testing to test_get_records_sql() }