# 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/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)
@@ -1274,4 +1274,67 @@
 
         $this->free_result($result);
     }
+
+
+    public function get_recordset($table, array $conditions=null, $sort='', $fields='*', $limitfrom=0, $limitnum=0) {
+        $goodconditions = $this->normalise_text_conditions($table, $conditions);
+        return parent::get_recordset($table, $goodconditions, $sort, $fields, $limitfrom, $limitnum);
 }
+
+    public function get_records($table, array $conditions=null, $sort='', $fields='*', $limitfrom=0, $limitnum=0) {
+        $goodconditions = $this->normalise_text_conditions($table, $conditions);
+        return parent::get_records($table, $goodconditions, $sort, $fields, $limitfrom, $limitnum);
+    }
+
+//    public function get_field($table, $return, array $conditions, $strictness=IGNORE_MISSING) {
+//        $goodconditions = $this->normalise_text_conditions($table, $conditions);
+//        return parent::set_field($table, $return, $goodconditions,$strictness);
+//    }
+
+    public function set_field($table, $newfield, $newvalue, array $conditions=null) {
+        $goodconditions = $this->normalise_text_conditions($table, $conditions);
+        return parent::set_field($table, $newfield, $newvalue,$goodconditions);
+    }
+
+    public function count_records($table, array $conditions=null) {
+        $goodconditions = $this->normalise_text_conditions($table, $conditions);
+        return parent::count_records($table, $goodconditions);
+    }
+
+    public function record_exists($table, array $conditions) {
+        $goodconditions = $this->normalise_text_conditions($table, $conditions);
+        return parent::record_exists($table, $goodconditions);
+    }
+
+    public function delete_records($table, array $conditions=null) {
+        $goodconditions = $this->normalise_text_conditions($table, $conditions);
+        return parent::delete_records($table, $conditions);
+    }
+
+    /**
+     * normalise text conditions ie: fieldnames as well as values.
+     * @param <string> $table   table name to get columns from
+     * @param <array> $conditions   fieldname=>value to check against table column types for conversion
+     * @return <array> normalised array of conditions.
+     */
+    protected function normalise_text_conditions($table, $conditions) {
+        $columns = $this->get_columns($table);
+        foreach ($conditions as $field => $value) {
+            if (!isset($columns[$field])) {
+                continue;
+            }
+            $column = $columns[$field];
+
+            $normalisedparams[$field] = $this->normalise_value($column, $value);
+            //check and change the field (if needed) to varchar too
+            if (is_array($normalisedparams[$field]) and isset($normalisedparams[$field]['numstr'])) {
+                $normalisedfieldnames[$field] = $this->sql_compare_text($field);
+            } else {
+                $normalisedfieldnames[$field] = $field;
+            }
+            $goodconditions[$normalisedfieldnames[$field]] = $normalisedparams[$field];
+        }
+        return $goodconditions;
+    }
+}
+
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)
@@ -2018,6 +2018,8 @@
 
         $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');
+        $table->add_field('onechar', XMLDB_TYPE_CHAR, '100', null, null, null);
+        $table->add_field('onetext', XMLDB_TYPE_TEXT, 'big', null, null, null);
         $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
         $dbman->create_table($table);
 
@@ -2060,6 +2062,12 @@
         $this->assertEqual(5, $DB->get_field($tablename, 'course', array('id' => $id2)));
         $this->assertEqual(5, $DB->get_field($tablename, 'course', array('id' => $id3)));
 
+
+        // test for fix for MDL-24863 (unwanted auto conversion of param to int)
+        $conditions = array( 'onetext' => '1' );
+        $DB->set_field($tablename, 'onechar', 'frog', $conditions);
+        $this->assertEqual('frog', $DB->get_field($tablename, 'onechar', array('onetext' => '1')));
+
         // Note: All the nulls, booleans, empties, quoted and backslashes tests
         // go to set_field_select() because set_field() is just one wrapper over it
     }
