From 3a5e48b079f58c9e12b3b625e948320e63a8d451 Mon Sep 17 00:00:00 2001 From: John Franklin Date: Sat, 19 May 2018 02:47:13 -0400 Subject: [PATCH] Issue #6: Apply patch from https://www.drupal.org/project/drupal/issues/2427311#comment-9628841 to add CONCAT_WS() to the SQLite driver. --- database.inc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/database.inc b/database.inc index 800c480..3618677 100644 --- a/database.inc +++ b/database.inc @@ -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')); @@ -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. */