Skip to content

Commit

Permalink
unify MySQL/MariaDB
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Apr 18, 2024
1 parent 0403982 commit 1fc3ac3
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/Persistence/Sql/Mysql/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ class Query extends BaseQuery
protected function _renderConditionRegexpOperator(bool $negated, string $sqlLeft, string $sqlRight): string
{
$serverVersion = $this->connection->getConnection()->getWrappedConnection()->getServerVersion(); // @phpstan-ignore-line
if (str_contains($serverVersion, 'MariaDB')) {
return $sqlLeft . ($negated ? ' not' : '') . ' regexp concat('
. $this->escapeStringLiteral('(?s)') . ', ' . $sqlRight . ')';
} elseif (str_starts_with($serverVersion, '5.')) {
return $sqlLeft . ($negated ? ' not' : '') . ' regexp ' . $sqlRight;
}

return ($negated ? 'not ' : '') . 'regexp_like(' . $sqlLeft . ', ' . $sqlRight
. ', ' . $this->escapeStringLiteral('in') . ')';
$isMysql5x = str_starts_with($serverVersion, '5.') && !str_contains($serverVersion, 'MariaDB');

return $sqlLeft . ($negated ? ' not' : '') . ' regexp ' . (
$isMysql5x
? $sqlRight
: 'concat(' . $this->escapeStringLiteral('(?s)') . ', ' . $sqlRight . ')'
);
}

#[\Override]
Expand Down

0 comments on commit 1fc3ac3

Please sign in to comment.