Skip to content

Commit

Permalink
Check for ints being inserted into text (clob) fieds to cast them to …
Browse files Browse the repository at this point in the history
…string.

Affects insert_record(), update_record() and set_field_xx(). MDL-15460
  • Loading branch information
stronk7 committed Jun 28, 2008
1 parent dfc05ef commit a3bf516
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion lib/dml/mssql_adodb_moodle_database.php
Expand Up @@ -171,6 +171,11 @@ public function update_record($table, $dataobject, $bulk=false) {
$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

Expand Down Expand Up @@ -236,8 +241,14 @@ public function set_field_select($table, $newfield, $newvalue, $select, array $p
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
Expand Down Expand Up @@ -291,6 +302,11 @@ public function insert_record($table, $dataobject, $returnid=true, $bulk=false)
$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

Expand Down

0 comments on commit a3bf516

Please sign in to comment.