]> git.mjollnir.org Git - moodle.git/commitdiff
lib/dml: new compatibility method sql_cast_2signed for when MySQL thinks that 1 ...
authortjhunt <tjhunt>
Fri, 10 Apr 2009 09:33:26 +0000 (09:33 +0000)
committertjhunt <tjhunt>
Fri, 10 Apr 2009 09:33:26 +0000 (09:33 +0000)
lib/dml/moodle_database.php
lib/dml/mysqli_adodb_moodle_database.php
lib/dml/mysqli_native_moodle_database.php

index 72ef93c27b068b5dcd1ba2ef71e64bf00ecb3d72..a60884849aa2d00d6e93699bab07100d06db0d66 100644 (file)
@@ -1518,6 +1518,19 @@ abstract class moodle_database {
         return ' ' . $fieldname . ' ';
     }
 
+    /**
+     * Returns the SQL to be used in order to an UNSIGNED INTEGER column to SIGNED.
+     *
+     * (Only MySQL needs this. MySQL things that 1 * -1 = 18446744073709551615
+     * if the 1 comes from an unsigned column).
+     *
+     * @param string fieldname the name of the field to be cast
+     * @return string the piece of SQL code to be used in your statement.
+     */
+    public function sql_cast_2signed($fieldname) {
+        return ' ' . $fieldname . ' ';
+    }
+
     /**
      * Returns the SQL text to be used to compare one TEXT (clob) column with
      * one varchar column, because some RDBMS doesn't support such direct
index 4c010c84df77f73cb9bd887ca737a4a30dc1fb2b..588d4e99bfe8df7614c0334d846350bbf0bd44de 100644 (file)
@@ -291,6 +291,10 @@ class mysqli_adodb_moodle_database extends adodb_moodle_database {
         return $positivematch ? 'REGEXP' : 'NOT REGEXP';
     }
 
+    public function sql_cast_2signed($fieldname) {
+        return ' CAST(' . $fieldname . ' AS SIGNED) ';
+    }
+
     /**
      * Import a record into a table, id field is required.
      * Basic safety checks only. Lobs are supported.
index 48b2494fcb41e2505f54d425f83c17c2de442cde..c65662e9e7424fca4c2fb5aa7300817055f13a61 100644 (file)
@@ -905,6 +905,10 @@ class mysqli_native_moodle_database extends moodle_database {
         return $positivematch ? 'REGEXP' : 'NOT REGEXP';
     }
 
+    public function sql_cast_2signed($fieldname) {
+        return ' CAST(' . $fieldname . ' AS SIGNED) ';
+    }
+
 /// session locking
     public function session_lock_supported() {
         return true;