From: stronk7 Date: Sat, 28 Jun 2008 21:09:10 +0000 (+0000) Subject: Check for ints being inserted into text (clob) fieds to cast them to string. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=a3bf516d75137c9cc6abb072ffb3d4a6783c8fe6;p=moodle.git Check for ints being inserted into text (clob) fieds to cast them to string. Affects insert_record(), update_record() and set_field_xx(). MDL-15460 --- diff --git a/lib/dml/mssql_adodb_moodle_database.php b/lib/dml/mssql_adodb_moodle_database.php index 539f1e2c37..1ebb3944ed 100644 --- a/lib/dml/mssql_adodb_moodle_database.php +++ b/lib/dml/mssql_adodb_moodle_database.php @@ -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