Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…es/2427311#comment-9628841 to add CONCAT_WS() to the SQLite driver.
  • Loading branch information
jlfranklin committed May 19, 2018
1 parent 70a1633 commit 3a5e48b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions database.inc
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class DatabaseConnection_sqlite extends DatabaseConnection {
$this->sqliteCreateFunction('length', 'strlen', 1);
$this->sqliteCreateFunction('md5', 'md5', 1);
$this->sqliteCreateFunction('concat', array($this, 'sqlFunctionConcat'));
$this->sqliteCreateFunction('concat_ws', array($this, 'sqlFunctionConcatWs'));
$this->sqliteCreateFunction('substring', array($this, 'sqlFunctionSubstring'), 3);
$this->sqliteCreateFunction('substring_index', array($this, 'sqlFunctionSubstringIndex'), 3);
$this->sqliteCreateFunction('rand', array($this, 'sqlFunctionRand'));
Expand Down Expand Up @@ -200,6 +201,25 @@ class DatabaseConnection_sqlite extends DatabaseConnection {
return implode('', $args);
}

/**
* SQLite compatibility implementation for the CONCAT_WS() SQL function.
*
* @see http://dev.mysql.com/doc/refman/5.6/en/string-functions.html#function_concat-ws
*/
public static function sqlFunctionConcatWs() {
$args = func_get_args();
$separator = array_shift($args);
// If the separator is NULL, the result is NULL.
if ($separator === FALSE || is_null($separator)) {
return NULL;
}
// Skip any NULL values after the separator argument.
$args = array_filter($args, function ($value) {
return !is_null($value);
});
return implode($separator, $args);
}

/**
* SQLite compatibility implementation for the SUBSTRING() SQL function.
*/
Expand Down

0 comments on commit 3a5e48b

Please sign in to comment.