Skip to content

Commit

Permalink
Merge pull request #1776 from bolt/fix/better-check-for-instr-and-cast
Browse files Browse the repository at this point in the history
Better check for `INSTR` and `CAST`
  • Loading branch information
bobdenotter authored Aug 26, 2020
2 parents 8842feb + c997574 commit d99b0b2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
9 changes: 5 additions & 4 deletions public/theme/skeleton/custom/setcontent_1.twig
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
<section id="seven">
<h1>Seven</h1>
{% setcontent blocks = "blocks" order "title" printquery %}
Results: <span id="results-six">{{ blocks|length > 0 ? 'yes' }}</span>
Results: <span id="results-seven">{{ blocks|length > 0 ? 'yes' }}</span>
<ul>
{% for block in blocks %}
<li>
Expand All @@ -119,7 +119,7 @@
<section id="eight">
<h1>Eight</h1>
{% setcontent entries = "entries,blocks,showcases" where {'title': '%voluptat% || %porro%' } printquery %}
Results: <span id="results-six">{{ entries|length > 0 ? 'yes' }}</span>
Results: <span id="results-eight">{{ entries|length > 0 ? 'yes' }}</span>
<ul>
{% for entry in entries %}
<li>
Expand All @@ -134,7 +134,8 @@
<section id="nine">
<h1>Nine</h1>
{% setcontent showcases = 'showcases' orderby '-floatfield' printquery %}
Results: <span id="results-six">{{ showcases|length > 0 ? 'yes' }}</span>

Results: <span id="results-nine">{{ showcases|length > 0 ? 'yes' }}</span>
<ul>
{% for showcase in showcases %}
<li>showcase {{ showcase.id }}: {{ showcase.floatfield }}
Expand Down Expand Up @@ -167,7 +168,7 @@
<section id="eleven">
<h1>Eleven</h1>
{% setcontent entries = 'entries' order 'categories' printquery %}
Results: <span id="results-six">{{ entries|length > 0 ? 'yes' }}</span>
Results: <span id="results-eleven">{{ entries|length > 0 ? 'yes' }}</span>
<ul>
{% for entry in entries %}
<li>
Expand Down
14 changes: 14 additions & 0 deletions src/Doctrine/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ public function hasJson(): bool
return false;
}

public function hasInstrAndCast(): bool
{
try {
$query = $this->connection->createQueryBuilder();
$query
->select('CAST (1.1 AS int), INSTR("Bolt", "o")');
$query->execute();
} catch (\Throwable $e) {
return false;
}

return true;
}

private function checkSqliteVersion(): bool
{
/** @var PDOConnection $wrapped */
Expand Down
6 changes: 3 additions & 3 deletions src/Storage/Directive/OrderDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,11 @@ private function orderByNumericField(QueryInterface $query, string $translations
{
$qb = $query->getQueryBuilder();

// For older bundled SQLite in PHP 7.2 that do not have `INSTR` and `CAST` built in, we fall back to the
// "dumb" sorting instead. For this we use the same criteria as to check whether we have JSON. C'est la vie.
// For older bundled SQLite in PHP 7.2 that do not have `INSTR` and `CAST` built in, we fall
// back to the "dumb" sorting instead. C'est la vie.
$doctrineVersion = new Version($query->getQueryBuilder()->getEntityManager()->getConnection());

if (! $doctrineVersion->hasJson()) {
if (! $doctrineVersion->hasInstrAndCast()) {
$qb->addOrderBy($translationsAlias . '.value', $direction);

return;
Expand Down

0 comments on commit d99b0b2

Please sign in to comment.