Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not cast the order by expression for MySQL drivers as casting a TE… #1977

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/Storage/Directive/OrderDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,17 @@ private function setOrderBy(QueryInterface $query, string $order, string $direct
} else {
// Note the `lower()` in the `addOrderBy()`. It is essential to sorting the
// results correctly. See also https://github.com/bolt/core/issues/1190
// again: lower breaks postgresql jsonb compatibility, first cast as txt
// again: lower breaks postgresql jsonb compatibility, first cast as txt (but not for MySQL/MariaDB)
$backend_driver = $query->getQueryBuilder()->getEntityManager()->getConnection()->getDatabasePlatform()->getName();
$lowerExpression = $translationsAlias . '.value';

if (mb_strpos($backend_driver, 'mysql') === false) {
$lowerExpression = 'CAST(' . $lowerExpression . ' as TEXT)';
}

$query
->getQueryBuilder()
->addOrderBy('lower(CAST(' . $translationsAlias . '.value as TEXT))', $direction);
->addOrderBy('lower(' . $lowerExpression . ')', $direction);
}
$query->incrementIndex();
} else {
Expand Down