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:
martinlanghoff 2006-09-26 05:05:54 +00:00
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