Permalink
Browse files

MDL-27325 mysql: Avoid some implicit casting from float to varchar/text

  • Loading branch information...
1 parent 6531aff commit 7aa9e45f56d74d9424baa3dde444870610cd1f90 @stronk7 stronk7 committed May 5, 2011
Showing with 4 additions and 0 deletions.
  1. +4 −0 lib/dml/mysqli_native_moodle_database.php
@@ -579,6 +579,10 @@ protected function normalise_value($column, $value) {
if ($column->meta_type == 'I' or $column->meta_type == 'F' or $column->meta_type == 'N') {
$value = 0; // prevent '' problems in numeric fields
}
+ // Any float value being stored in varchar or text field is converted to string to avoid
+ // any implicit conversion by MySQL
+ } else if (is_float($value) and ($column->meta_type == 'C' or $column->meta_type == 'X')) {
+ $value = "$value";
}
// workaround for problem with wrong enums in mysql - TODO: Out in Moodle 2.1
if (!empty($column->enums)) {

0 comments on commit 7aa9e45

Please sign in to comment.