]> git.mjollnir.org Git - moodle.git/commitdiff
Check for ints being inserted into text (clob) fieds to cast them to string.
authorstronk7 <stronk7>
Sat, 28 Jun 2008 21:09:10 +0000 (21:09 +0000)
committerstronk7 <stronk7>
Sat, 28 Jun 2008 21:09:10 +0000 (21:09 +0000)
Affects insert_record(), update_record() and set_field_xx(). MDL-15460

lib/dml/mssql_adodb_moodle_database.php

index 539f1e2c37fba0fe606fbac606cb4dc1ca0ac612..1ebb3944ed5e051f5bcf206317e78dbf49bbfc07 100644 (file)
@@ -171,6 +171,11 @@ class mssql_adodb_moodle_database extends adodb_moodle_database {
                     $value = null;           /// Set the default value to be inserted in first instance
                 }
 
+            } else if ($column->meta_type == 'X') { /// MSSQL doesn't cast from int to text, so if text column
+                if (is_numeric($value)) {           /// and is numeric value
+                    $value = (string)$value;        /// cast to string
+                }
+
             } else if (is_bool($value)) {
                 $value = (int)$value; // prevent "false" problems
 
@@ -236,8 +241,14 @@ class mssql_adodb_moodle_database extends adodb_moodle_database {
         if (is_null($newvalue)) {
             $newfield = "$newfield = NULL";
         } else {
-            if (is_bool($newvalue)) {
+            if ($column->meta_type == 'X') {        /// MSSQL doesn't cast from int to text, so if text column
+                if (is_numeric($newvalue)) {        /// and is numeric value
+                    $newvalue = (string)$newvalue;  /// cast to string in PHP
+                }
+
+            } else if (is_bool($newvalue)) {
                 $newvalue = (int)$newvalue; // prevent "false" problems
+
             } else if ($newvalue === '') {
                 if ($column->meta_type == 'I' or $column->meta_type == 'F' or $column->meta_type == 'N') {
                     $newvalue = 0; // prevent '' problems in numeric fields
@@ -291,6 +302,11 @@ class mssql_adodb_moodle_database extends adodb_moodle_database {
                     $value = null;           /// Set the default value to be inserted in first instance
                 }
 
+            } else if ($column->meta_type == 'X') { /// MSSQL doesn't cast from int to text, so if text column
+                if (is_numeric($value)) {           /// and is numeric value
+                    $value = (string)$value;        /// cast to string
+                }
+
             } else if (is_bool($value)) {
                 $value = (int)$value; // prevent "false" problems