From c899cbeae97bb0a91f9d6771e97d2d711f46ebb0 Mon Sep 17 00:00:00 2001 From: Eloy Lafuente Date: Mon, 30 Aug 2010 11:46:34 +0000 Subject: [PATCH] MDL-23997 re-added text comparison tests for bound query now using sql_compare_text() properly. --- lib/dml/simpletest/testdml.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/dml/simpletest/testdml.php b/lib/dml/simpletest/testdml.php index 865ffde301f..61101d3dc1f 100755 --- a/lib/dml/simpletest/testdml.php +++ b/lib/dml/simpletest/testdml.php @@ -2857,16 +2857,22 @@ class dml_test extends UnitTestCase { $this->assertTrue($records = $DB->get_records($tablename, array('name' => '2'))); $this->assertEqual(1, count($records)); - /* TODO: we need param type hints to make this work - $this->assertTrue($records = $DB->get_records($tablename, array('content' => '1'))); + // Conditions in TEXT columns always must be performed with the sql_compare_text + // helper function on both sides of the condition + $sqlqm = "SELECT * + FROM {{$tablename}} + WHERE " . $DB->sql_compare_text('content') . " = " . $DB->sql_compare_text('?'); + $this->assertTrue($records = $DB->get_records_sql($sqlqm, array('1'))); $this->assertEqual(1, count($records)); - $this->assertTrue($records = $DB->get_records($tablename, array('content' => 1))); + $this->assertTrue($records = $DB->get_records_sql($sqlqm, array(1))); $this->assertEqual(1, count($records)); - $this->assertTrue($records = $DB->get_records($tablename, array('content' => 2))); + $sqlnamed = "SELECT * + FROM {{$tablename}} + WHERE " . $DB->sql_compare_text('content') . " = " . $DB->sql_compare_text(':content'); + $this->assertTrue($records = $DB->get_records_sql($sqlnamed, array('content' => 2))); $this->assertEqual(1, count($records)); - $this->assertTrue($records = $DB->get_records($tablename, array('content' => '2'))); + $this->assertTrue($records = $DB->get_records_sql($sqlnamed, array('content' => '2'))); $this->assertEqual(1, count($records)); - */ } } -- 2.43.0