# This patch file was generated by NetBeans IDE
# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.
# It uses platform neutral UTF-8 encoding.
# Above lines and this line are ignored by the patching process.
Index: moodle/lib/dml/moodle_database.php
--- moodle/lib/dml/moodle_database.php Base (1.132)
+++ moodle/lib/dml/moodle_database.php Locally Modified (Based On 1.132)
@@ -1734,8 +1734,8 @@
      * @param int $numchars of chars to use for the ordering (defaults to 32)
      * @return string the piece of SQL code to be used in your statement.
      */
-    public function sql_compare_text($fieldname, $numchars=32) {
-        return $this->sql_order_by_text($fieldname, $numchars);
+    public function sql_compare_text($fieldname, $numchars=32, &$numstrvar=null ) {
+        return $this->sql_order_by_text($fieldname, $numchars, $numstrvar);
     }
 
     /**
Index: moodle/lib/dml/mssql_native_moodle_database.php
--- moodle/lib/dml/mssql_native_moodle_database.php Base (1.38)
+++ moodle/lib/dml/mssql_native_moodle_database.php Locally Modified (Based On 1.38)
@@ -1010,7 +1010,7 @@
 
         list($sql, $params, $type) = $this->fix_sql_params($sql, $params);
         $rawsql = $this->emulate_bound_params($sql, $params);
-
+        error_log($rawsql);
         $this->query_start($sql, $params, SQL_QUERY_UPDATE);
         $result = mssql_query($rawsql, $this->mssql);
         $this->query_end($result);
@@ -1162,7 +1162,11 @@
         return ' LEN(' . $fieldname . ')';
     }
 
-    public function sql_order_by_text($fieldname, $numchars=32) {
+    public function sql_order_by_text($fieldname, $numchars=32, &$numstrvar=null) {
+        if ($numstrvar != null) {
+            // numstr hack to force a var to string.
+            $numstrvar = array( 'numstr' => $numstrvar);
+        }
         return ' CONVERT(varchar, ' . $fieldname . ', ' . $numchars . ')';
     }
 
Index: moodle/lib/dml/simpletest/testdml.php
--- moodle/lib/dml/simpletest/testdml.php Base (1.129)
+++ moodle/lib/dml/simpletest/testdml.php Locally Modified (Based On 1.129)
@@ -2190,6 +2190,14 @@
         $DB->set_field_select($tablename, 'onebinary', $newblob, 'id = ?', array(1));
         $this->assertEqual($newclob, $DB->get_field($tablename, 'onetext', array('id' => 1)), 'Test "small" CLOB set_field (full contents output disabled)');
         $this->assertEqual($newblob, $DB->get_field($tablename, 'onebinary', array('id' => 1)), 'Test "small" BLOB set_field (full contents output disabled)');
+
+        // This is the failure from MDL-24863. This was giving an error on MSSQL,
+        // which converts the '1' to an integer, which cannot then be compared with
+        // onetext cast to a varchar.
+        $params = array('1');
+        $DB->set_field_select($tablename, 'onechar', 'frog',
+                $DB->sql_compare_text('onetext', 32, $params[0]) . ' = ?', $params);
+        
     }
 
     public function test_count_records() {
