]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-18244 sql_length() - new cross-db function to calculate the length in chars of...
authorstronk7 <stronk7>
Sun, 15 Feb 2009 23:17:56 +0000 (23:17 +0000)
committerstronk7 <stronk7>
Sun, 15 Feb 2009 23:17:56 +0000 (23:17 +0000)
lib/dml/moodle_database.php
lib/dml/mssql_adodb_moodle_database.php
lib/dml/mysqli_adodb_moodle_database.php
lib/dml/mysqli_native_moodle_database.php

index ce8b15b2c755bb97edb0a2265cbca2ccac2c5103..72ef93c27b068b5dcd1ba2ef71e64bf00ecb3d72 100644 (file)
@@ -1589,6 +1589,15 @@ abstract class moodle_database {
         return $fieldname;
     }
 
+    /**
+     * Returns the SQL text to be used to calculate the length in characters of one expression.
+     * @param string fieldname or expression to calculate its length in characters.
+     * @return string the piece of SQL code to be used in the statement.
+     */
+    public function sql_length($fieldname) {
+        return ' LENGTH(' . $fieldname . ')';
+    }
+
     /**
      * Returns the proper substr() function for each DB.
      * NOTE: this was originally returning only function name
index 53fcac745ab6bb7c4cdeeff7d59898b6ecaf9aa2..093e2de581a1d8a99ec013e1baa9f253b78dfd0c 100644 (file)
@@ -133,6 +133,15 @@ class mssql_adodb_moodle_database extends adodb_moodle_database {
         return ' CONVERT(varchar, ' . $fieldname . ', ' . $numchars . ')';
     }
 
+    /**
+     * Returns the SQL text to be used to calculate the length in characters of one expression.
+     * @param string fieldname or expression to calculate its length in characters.
+     * @return string the piece of SQL code to be used in the statement.
+     */
+    public function sql_length($fieldname) {
+        return ' LEN(' . $fieldname . ')';
+    }
+
     /**
      * Returns the SQL for returning searching one string for the location of another.
      */
index 23d4c48719b8f43bc1c07382f902a838468cb971..4c010c84df77f73cb9bd887ca737a4a30dc1fb2b 100644 (file)
@@ -266,6 +266,15 @@ class mysqli_adodb_moodle_database extends adodb_moodle_database {
         return ' CAST(' . $fieldname . ' AS SIGNED) ';
     }
 
+    /**
+     * Returns the SQL text to be used to calculate the length in characters of one expression.
+     * @param string fieldname or expression to calculate its length in characters.
+     * @return string the piece of SQL code to be used in the statement.
+     */
+    public function sql_length($fieldname) {
+        return ' CHAR_LENGTH(' . $fieldname . ')';
+    }
+
     /**
      * Does this driver suppoer regex syntax when searching
      */
@@ -305,4 +314,4 @@ class mysqli_adodb_moodle_database extends adodb_moodle_database {
 
         return $this->insert_record_raw($table, $cleaned, false, true, true);
     }
-}
\ No newline at end of file
+}
index 09189025f91b6f23ad2b4465e8ffb87197771fb1..48b2494fcb41e2505f54d425f83c17c2de442cde 100644 (file)
@@ -880,6 +880,15 @@ class mysqli_native_moodle_database extends moodle_database {
         return "CONCAT_WS($separator, $s)";
     }
 
+    /**
+     * Returns the SQL text to be used to calculate the length in characters of one expression.
+     * @param string fieldname or expression to calculate its length in characters.
+     * @return string the piece of SQL code to be used in the statement.
+     */
+    public function sql_length($fieldname) {
+        return ' CHAR_LENGTH(' . $fieldname . ')';
+    }
+
     /**
      * Does this driver suppoer regex syntax when searching
      */