MDL-16669 dml: improved sql_substring(), added unit tests

This commit is contained in:
skodak
2008-10-28 15:11:10 +00:00
parent d669160891
commit 655bbf511d
13 changed files with 87 additions and 40 deletions
+15 -2
View File
@@ -1398,10 +1398,23 @@ abstract class moodle_database {
/**
* Returns the proper substr() function for each DB.
* NOTE: this was originally returning only function name
*
* Relies on ADOdb $adodb->substr property
* @param string $expr some string field, no aggregates
* @param mixed $start integer or expresion evaluating to int (1 based value; first char has index 1)
* @param mixed $length optional integer or expresion evaluating to int
* @return string sql fragment
*/
public abstract function sql_substr();
public function sql_substr($expr, $start, $length=false) {
if (count(func_get_args()) < 2) {
throw new coding_exception('moodle_database::sql_substr() requires at least two parameters', 'Originaly this function was only returning name of SQL substring function, it now requires all parameters.');
}
if ($length === false) {
return "SUBSTR($expr, $start";
} else {
return "SUBSTR($expr, $start, $length)";
}
}
/**
* Returns the SQL for returning searching one string for the location of another.