]> git.mjollnir.org Git - moodle.git/commitdiff
Introducing sql_concat() - and use it in sql_fullname()
authormartinlanghoff <martinlanghoff>
Tue, 26 Sep 2006 05:02:59 +0000 (05:02 +0000)
committermartinlanghoff <martinlanghoff>
Tue, 26 Sep 2006 05:02:59 +0000 (05:02 +0000)
sql_concat() is just a passthrough to $db->Concat() -- it doesn't
add any value, and I think the dispatching is somewhat expensive.

Just using $db->Concat() should be good enough, were it not for
consistency in our DM API.

lib/dmllib.php

index 4c0cef95f2e82b8a46b2898f4ee8eeb750be9c0b..b149383afa52c480986a890cc44853bcc1a0e2b6 100644 (file)
@@ -1231,18 +1231,22 @@ function sql_ilike() {
  * @return string
  */
 function sql_fullname($firstname='firstname', $lastname='lastname') {
-    global $CFG;
+    return sql_concat($firstname, "' '", $lastname);
+}
 
-    switch ($CFG->dbtype) {
-        case 'mysql':
-             return ' CONCAT('. $firstname .'," ",'. $lastname .') ';
-        case 'postgres7':
-             return " ". $firstname ."||' '||". $lastname ." ";
-        case 'mssql':
-             return " ". $firstname ."+' '+". $lastname ." ";
-        default:
-             return ' '. $firstname .'||" "||'. $lastname .' ';
-    }
+/**
+ * Returns the proper SQL to do CONCAT between the elements passed
+ * Can take many parameters - just a passthrough to $db->Concat()
+ *
+ * @uses $db
+ * @param string $element
+ * @return string
+ */
+function sql_concat() {
+    global $db;
+    $args = func_get_args();
+    return call_user_func_array(array('Concat', $db), $args);
 }
 
 /**