Skip to content

Commit

Permalink
Use more specific dongle checks
Browse files Browse the repository at this point in the history
  • Loading branch information
daftspunk committed Feb 27, 2024
1 parent bc83a1e commit 1e23041
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/Database/Dongle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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);
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 1e23041

Please sign in to comment.