From: stronk7 Date: Sun, 15 Feb 2009 23:17:56 +0000 (+0000) Subject: MDL-18244 sql_length() - new cross-db function to calculate the length in chars of... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=7e0db2e20556cd90967597f528613ec182e66229;p=moodle.git MDL-18244 sql_length() - new cross-db function to calculate the length in chars of any expression ; from 19_STABLE --- diff --git a/lib/dml/moodle_database.php b/lib/dml/moodle_database.php index ce8b15b2c7..72ef93c27b 100644 --- a/lib/dml/moodle_database.php +++ b/lib/dml/moodle_database.php @@ -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 diff --git a/lib/dml/mssql_adodb_moodle_database.php b/lib/dml/mssql_adodb_moodle_database.php index 53fcac745a..093e2de581 100644 --- a/lib/dml/mssql_adodb_moodle_database.php +++ b/lib/dml/mssql_adodb_moodle_database.php @@ -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. */ diff --git a/lib/dml/mysqli_adodb_moodle_database.php b/lib/dml/mysqli_adodb_moodle_database.php index 23d4c48719..4c010c84df 100644 --- a/lib/dml/mysqli_adodb_moodle_database.php +++ b/lib/dml/mysqli_adodb_moodle_database.php @@ -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 +} diff --git a/lib/dml/mysqli_native_moodle_database.php b/lib/dml/mysqli_native_moodle_database.php index 09189025f9..48b2494fcb 100644 --- a/lib/dml/mysqli_native_moodle_database.php +++ b/lib/dml/mysqli_native_moodle_database.php @@ -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 */