From 9882b2c824b5a2c606091c99ebb4cbd28e780c8e Mon Sep 17 00:00:00 2001 From: Eloy Lafuente Date: Thu, 18 Nov 2010 01:27:49 +0000 Subject: [PATCH] MDL-25276 dml - fix/implement sql_cast2int/real() across the 5 drivers. Tests passing. --- lib/dml/mssql_native_moodle_database.php | 14 +++++++++++++- lib/dml/mysqli_native_moodle_database.php | 4 ++++ lib/dml/oci_native_moodle_database.php | 8 ++++++++ lib/dml/sqlsrv_native_moodle_database.php | 14 +++++++++++++- 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/lib/dml/mssql_native_moodle_database.php b/lib/dml/mssql_native_moodle_database.php index 884b3682317..edd66f10903 100644 --- a/lib/dml/mssql_native_moodle_database.php +++ b/lib/dml/mssql_native_moodle_database.php @@ -1052,7 +1052,19 @@ class mssql_native_moodle_database extends moodle_database { /// SQL helper functions public function sql_cast_char2int($fieldname, $text=false) { - return ' CAST(' . $fieldname . ' AS INT) '; + if (!$text) { + return ' CAST(' . $fieldname . ' AS INT) '; + } else { + return ' CAST(' . $this->sql_compare_text($fieldname) . ' AS INT) '; + } + } + + public function sql_cast_char2real($fieldname, $text=false) { + if (!$text) { + return ' CAST(' . $fieldname . ' AS REAL) '; + } else { + return ' CAST(' . $this->sql_compare_text($fieldname) . ' AS REAL) '; + } } public function sql_ceil($fieldname) { diff --git a/lib/dml/mysqli_native_moodle_database.php b/lib/dml/mysqli_native_moodle_database.php index 33090022922..51f2d3d7b6d 100644 --- a/lib/dml/mysqli_native_moodle_database.php +++ b/lib/dml/mysqli_native_moodle_database.php @@ -1052,6 +1052,10 @@ class mysqli_native_moodle_database extends moodle_database { return ' CAST(' . $fieldname . ' AS SIGNED) '; } + public function sql_cast_char2real($fieldname, $text=false) { + return ' CAST(' . $fieldname . ' AS DECIMAL) '; + } + /** * Returns 'LIKE' part of a query. * diff --git a/lib/dml/oci_native_moodle_database.php b/lib/dml/oci_native_moodle_database.php index a3cd061ccbc..7da58101235 100644 --- a/lib/dml/oci_native_moodle_database.php +++ b/lib/dml/oci_native_moodle_database.php @@ -1447,6 +1447,14 @@ class oci_native_moodle_database extends moodle_database { } } + public function sql_cast_char2real($fieldname, $text=false) { + if (!$text) { + return ' CAST(' . $fieldname . ' AS FLOAT) '; + } else { + return ' CAST(' . $this->sql_compare_text($fieldname) . ' AS FLOAT) '; + } + } + /** * Returns 'LIKE' part of a query. * diff --git a/lib/dml/sqlsrv_native_moodle_database.php b/lib/dml/sqlsrv_native_moodle_database.php index 673bc0dcea6..15b3a838dc9 100644 --- a/lib/dml/sqlsrv_native_moodle_database.php +++ b/lib/dml/sqlsrv_native_moodle_database.php @@ -1152,7 +1152,19 @@ class sqlsrv_native_moodle_database extends moodle_database { /// SQL helper functions public function sql_cast_char2int($fieldname, $text = false) { - return ' CAST('.$fieldname.' AS INT) '; + if (!$text) { + return ' CAST(' . $fieldname . ' AS INT) '; + } else { + return ' CAST(' . $this->sql_compare_text($fieldname) . ' AS INT) '; + } + } + + public function sql_cast_char2real($fieldname, $text=false) { + if (!$text) { + return ' CAST(' . $fieldname . ' AS REAL) '; + } else { + return ' CAST(' . $this->sql_compare_text($fieldname) . ' AS REAL) '; + } } public function sql_ceil($fieldname) {