Skip to content

Commit

Permalink
Resolve compileAggregate compatibility with the framework's paginator
Browse files Browse the repository at this point in the history
  • Loading branch information
harrygulliford committed Mar 9, 2022
1 parent 8ce0aab commit e0e3d13
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
21 changes: 0 additions & 21 deletions src/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,4 @@ public function fromProcedure(string $procedure, array $values = [])

return $this;
}

/**
* Run a pagination count query.
*
* @param array $columns
* @return array
*/
protected function runPaginationCountQuery($columns = ['*'])
{
$results = parent::runPaginationCountQuery($columns);

// Convert the resultset keys to lower, so they can be handled correctly
// by the paginator.
if ($this->getConnection()->getPdo()->getAttribute(\PDO::ATTR_CASE) !== \PDO::CASE_LOWER) {
foreach ($results as $key => $value) {
$results[$key] = (object) array_change_key_case((array) $value, CASE_LOWER);
}
}

return $results;
}
}
18 changes: 18 additions & 0 deletions src/Query/Grammars/FirebirdGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Database\Query\Builder;
use Illuminate\Database\Query\Grammars\Grammar;
use Illuminate\Support\Str;

class FirebirdGrammar extends Grammar
{
Expand Down Expand Up @@ -151,4 +152,21 @@ public function compileProcedure(Builder $query, $procedure, array $values = nul

return $procedure.' ('.$this->parameterize($values).')';
}

/**
* Compile an aggregated select clause.
*
* @param Builder $query
* @param array $aggregate
* @return string
*/
protected function compileAggregate(Builder $query, $aggregate)
{
// Wrap `aggregate` in double quotes to ensure the resultset returns the
// column name as a lowercase string. This resolves compatibility with
// the framework's paginator.
return Str::replaceLast(
'as aggregate', 'as "aggregate"', parent::compileAggregate($query, $aggregate)
);
}
}

0 comments on commit e0e3d13

Please sign in to comment.