mirror of
https://github.com/moodle/moodle.git
synced 2025-04-25 02:16:06 +02:00
Introducing sql_concat_join($sep, $array) helper
returns the SQL to do the equivalente of a join() or implode() on the DB server. Watch the RDBMS work! ;-)
This commit is contained in:
parent
92a2d92a82
commit
38e02f4c32
@ -1249,6 +1249,31 @@ function sql_concat() {
|
||||
return call_user_func_array(array('Concat', $db), $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the proper SQL to do CONCAT between the elements passed
|
||||
* with a given separator
|
||||
*
|
||||
* @uses $db
|
||||
* @param string $separator
|
||||
* @param array $elements
|
||||
* @return string
|
||||
*/
|
||||
function sql_concat_join($separator="' '", $elements=array()) {
|
||||
global $db;
|
||||
|
||||
// copy to ensure pass by value
|
||||
$elem = $elements;
|
||||
|
||||
// Intersperse $elements in the array.
|
||||
// Add items to the array on the fly, walking it
|
||||
// _backwards_ splicing the elements in. The loop definition
|
||||
// should skip first and last positions.
|
||||
for ($n=count($elem)-1; $n > 0 ; $n--) {
|
||||
array_splice($elem, $n, 0, $separator);
|
||||
}
|
||||
return call_user_func_array(array('Concat', $db), $elem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the proper SQL to do IS NULL
|
||||
* @uses $CFG
|
||||
|
Loading…
x
Reference in New Issue
Block a user