From: martinlanghoff Date: Tue, 26 Sep 2006 05:02:59 +0000 (+0000) Subject: Introducing sql_concat() - and use it in sql_fullname() X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=0ce96669c97beef23c6875953bfc15c79f42e1ce;p=moodle.git Introducing sql_concat() - and use it in sql_fullname() 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. --- diff --git a/lib/dmllib.php b/lib/dmllib.php index 4c0cef95f2..b149383afa 100644 --- a/lib/dmllib.php +++ b/lib/dmllib.php @@ -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); } /**