From 1e23041a41186b6d60606111676dc59c1e660889 Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Tue, 27 Feb 2024 20:50:50 +1100 Subject: [PATCH] Use more specific dongle checks --- src/Database/Dongle.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Database/Dongle.php b/src/Database/Dongle.php index 4a9c71f5d..1994c5e0b 100644 --- a/src/Database/Dongle.php +++ b/src/Database/Dongle.php @@ -125,6 +125,10 @@ public function parseGroupConcat(string $sql): string return $sql; } + if (!str_contains(strtolower($sql), 'group_concat(')) { + return $sql; + } + $result = preg_replace_callback('/group_concat\((.+)\)/i', function ($matches) { if (!isset($matches[1])) { return $matches[0]; @@ -143,13 +147,12 @@ public function parseGroupConcat(string $sql): string }, $sql); if ($this->driver === 'pgsql' || $this->driver === 'postgis') { + // @todo this leaks to other definitions $result = preg_replace("/\\(([]a-zA-Z\\-\\_\\.]+)\\,/i", "($1::VARCHAR,", $result); $result = str_ireplace('group_concat(', 'string_agg(', $result); } - /* - * Requires https://groupconcat.codeplex.com/ - */ + // Requires https://groupconcat.codeplex.com/ if ($this->driver === 'sqlsrv') { $result = str_ireplace('group_concat(', 'dbo.GROUP_CONCAT_D(', $result); } @@ -166,6 +169,10 @@ public function parseConcat(string $sql): string return $sql; } + if (!str_contains(strtolower($sql), 'concat(')) { + return $sql; + } + // Pre process special characters inside quotes $charComma = 'X___COMMA_CHAR___X'; $result = preg_replace_callback("/'(.*?[^\\\\])'/i", function ($matches) use ($charComma) { @@ -207,6 +214,14 @@ public function parseConcat(string $sql): string */ public function parseIfNull(string $sql): string { + if ($this->driver === 'mysql') { + return $sql; + } + + if (!str_contains(strtolower($sql), 'ifnull(')) { + return $sql; + } + if ($this->driver === 'pgsql' || $this->driver === 'postgis') { return str_ireplace('ifnull(', 'coalesce(', $sql); }