Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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! ;-)
  • Loading branch information...
commit 38e02f4c321cbf8f62dfb6cd6448bf550b822b46 1 parent 92a2d92
martinlanghoff authored
Showing with 25 additions and 0 deletions.
  1. +25 −0 lib/dmllib.php
25 lib/dmllib.php
View
@@ -1250,6 +1250,31 @@ function sql_concat() {
}
/**
+ * 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
* @param string $fieldname The field to add IS NULL to
Please sign in to comment.
Something went wrong with that request. Please try again.