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

[7.x] Update runPaginationCountQuery to support groupBy and sub-selects #32688

Merged
merged 4 commits into from
May 5, 2020
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Re-commit without style changes
  • Loading branch information
hotmeteor committed May 5, 2020
commit 9873d8ca66112031b1054b5c8e2d35785375d965
116 changes: 29 additions & 87 deletions src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,9 @@ class Builder
* @param \Illuminate\Database\Query\Processors\Processor|null $processor
* @return void
*/
public function __construct(
ConnectionInterface $connection,
Grammar $grammar = null,
Processor $processor = null
)
public function __construct(ConnectionInterface $connection,
Grammar $grammar = null,
Processor $processor = null)
{
$this->connection = $connection;
$this->grammar = $grammar ?: $connection->getQueryGrammar();
Expand Down Expand Up @@ -255,8 +253,7 @@ public function selectSub($query, $as)
[$query, $bindings] = $this->createSub($query);

return $this->selectRaw(
'('.$query.') as '.$this->grammar->wrap($as),
$bindings
'('.$query.') as '.$this->grammar->wrap($as), $bindings
);
}

Expand Down Expand Up @@ -649,9 +646,7 @@ public function where($column, $operator = null, $value = null, $boolean = 'and'
// passed to the method, we will assume that the operator is an equals sign
// and keep going. Otherwise, we'll require the operator to be passed in.
[$value, $operator] = $this->prepareValueAndOperator(
$value,
$operator,
func_num_args() === 2
$value, $operator, func_num_args() === 2
);

// If the columns is actually a Closure instance, we will assume the developer
Expand Down Expand Up @@ -709,11 +704,7 @@ public function where($column, $operator = null, $value = null, $boolean = 'and'
// in our array and add the query binding to our array of bindings that
// will be bound to each SQL statements when it is finally executed.
$this->wheres[] = compact(
'type',
'column',
'operator',
'value',
'boolean'
'type', 'column', 'operator', 'value', 'boolean'
);

if (! $value instanceof Expression) {
Expand Down Expand Up @@ -803,9 +794,7 @@ protected function invalidOperator($operator)
public function orWhere($column, $operator = null, $value = null)
{
[$value, $operator] = $this->prepareValueAndOperator(
$value,
$operator,
func_num_args() === 2
$value, $operator, func_num_args() === 2
);

return $this->where($column, $operator, $value, 'or');
Expand Down Expand Up @@ -842,11 +831,7 @@ public function whereColumn($first, $operator = null, $second = null, $boolean =
$type = 'Column';

$this->wheres[] = compact(
'type',
'first',
'operator',
'second',
'boolean'
'type', 'first', 'operator', 'second', 'boolean'
);

return $this;
Expand Down Expand Up @@ -1133,9 +1118,7 @@ public function orWhereNotNull($column)
public function whereDate($column, $operator, $value = null, $boolean = 'and')
{
[$value, $operator] = $this->prepareValueAndOperator(
$value,
$operator,
func_num_args() === 2
$value, $operator, func_num_args() === 2
);

if ($value instanceof DateTimeInterface) {
Expand All @@ -1156,9 +1139,7 @@ public function whereDate($column, $operator, $value = null, $boolean = 'and')
public function orWhereDate($column, $operator, $value = null)
{
[$value, $operator] = $this->prepareValueAndOperator(
$value,
$operator,
func_num_args() === 2
$value, $operator, func_num_args() === 2
);

return $this->whereDate($column, $operator, $value, 'or');
Expand All @@ -1176,9 +1157,7 @@ public function orWhereDate($column, $operator, $value = null)
public function whereTime($column, $operator, $value = null, $boolean = 'and')
{
[$value, $operator] = $this->prepareValueAndOperator(
$value,
$operator,
func_num_args() === 2
$value, $operator, func_num_args() === 2
);

if ($value instanceof DateTimeInterface) {
Expand All @@ -1199,9 +1178,7 @@ public function whereTime($column, $operator, $value = null, $boolean = 'and')
public function orWhereTime($column, $operator, $value = null)
{
[$value, $operator] = $this->prepareValueAndOperator(
$value,
$operator,
func_num_args() === 2
$value, $operator, func_num_args() === 2
);

return $this->whereTime($column, $operator, $value, 'or');
Expand All @@ -1219,9 +1196,7 @@ public function orWhereTime($column, $operator, $value = null)
public function whereDay($column, $operator, $value = null, $boolean = 'and')
{
[$value, $operator] = $this->prepareValueAndOperator(
$value,
$operator,
func_num_args() === 2
$value, $operator, func_num_args() === 2
);

if ($value instanceof DateTimeInterface) {
Expand All @@ -1246,9 +1221,7 @@ public function whereDay($column, $operator, $value = null, $boolean = 'and')
public function orWhereDay($column, $operator, $value = null)
{
[$value, $operator] = $this->prepareValueAndOperator(
$value,
$operator,
func_num_args() === 2
$value, $operator, func_num_args() === 2
);

return $this->whereDay($column, $operator, $value, 'or');
Expand All @@ -1266,9 +1239,7 @@ public function orWhereDay($column, $operator, $value = null)
public function whereMonth($column, $operator, $value = null, $boolean = 'and')
{
[$value, $operator] = $this->prepareValueAndOperator(
$value,
$operator,
func_num_args() === 2
$value, $operator, func_num_args() === 2
);

if ($value instanceof DateTimeInterface) {
Expand All @@ -1293,9 +1264,7 @@ public function whereMonth($column, $operator, $value = null, $boolean = 'and')
public function orWhereMonth($column, $operator, $value = null)
{
[$value, $operator] = $this->prepareValueAndOperator(
$value,
$operator,
func_num_args() === 2
$value, $operator, func_num_args() === 2
);

return $this->whereMonth($column, $operator, $value, 'or');
Expand All @@ -1313,9 +1282,7 @@ public function orWhereMonth($column, $operator, $value = null)
public function whereYear($column, $operator, $value = null, $boolean = 'and')
{
[$value, $operator] = $this->prepareValueAndOperator(
$value,
$operator,
func_num_args() === 2
$value, $operator, func_num_args() === 2
);

if ($value instanceof DateTimeInterface) {
Expand All @@ -1336,9 +1303,7 @@ public function whereYear($column, $operator, $value = null, $boolean = 'and')
public function orWhereYear($column, $operator, $value = null)
{
[$value, $operator] = $this->prepareValueAndOperator(
$value,
$operator,
func_num_args() === 2
$value, $operator, func_num_args() === 2
);

return $this->whereYear($column, $operator, $value, 'or');
Expand Down Expand Up @@ -1428,11 +1393,7 @@ protected function whereSub($column, $operator, Closure $callback, $boolean)
call_user_func($callback, $query = $this->forSubQuery());

$this->wheres[] = compact(
'type',
'column',
'operator',
'query',
'boolean'
'type', 'column', 'operator', 'query', 'boolean'
);

$this->addBinding($query->getBindings(), 'where');
Expand Down Expand Up @@ -1626,9 +1587,7 @@ public function whereJsonLength($column, $operator, $value = null, $boolean = 'a
$type = 'JsonLength';

[$value, $operator] = $this->prepareValueAndOperator(
$value,
$operator,
func_num_args() === 2
$value, $operator, func_num_args() === 2
);

$this->wheres[] = compact('type', 'column', 'operator', 'value', 'boolean');
Expand All @@ -1651,9 +1610,7 @@ public function whereJsonLength($column, $operator, $value = null, $boolean = 'a
public function orWhereJsonLength($column, $operator, $value = null)
{
[$value, $operator] = $this->prepareValueAndOperator(
$value,
$operator,
func_num_args() === 2
$value, $operator, func_num_args() === 2
);

return $this->whereJsonLength($column, $operator, $value, 'or');
Expand All @@ -1671,10 +1628,7 @@ public function dynamicWhere($method, $parameters)
$finder = substr($method, 5);

$segments = preg_split(
'/(And|Or)(?=[A-Z])/',
$finder,
-1,
PREG_SPLIT_DELIM_CAPTURE
'/(And|Or)(?=[A-Z])/', $finder, -1, PREG_SPLIT_DELIM_CAPTURE
);

// The connector variable will determine which connector will be used for the
Expand Down Expand Up @@ -1775,9 +1729,7 @@ public function having($column, $operator = null, $value = null, $boolean = 'and
// passed to the method, we will assume that the operator is an equals sign
// and keep going. Otherwise, we'll require the operator to be passed in.
[$value, $operator] = $this->prepareValueAndOperator(
$value,
$operator,
func_num_args() === 2
$value, $operator, func_num_args() === 2
);

// If the given operator is not found in the list of valid operators we will
Expand Down Expand Up @@ -1807,9 +1759,7 @@ public function having($column, $operator = null, $value = null, $boolean = 'and
public function orHaving($column, $operator = null, $value = null)
{
[$value, $operator] = $this->prepareValueAndOperator(
$value,
$operator,
func_num_args() === 2
$value, $operator, func_num_args() === 2
);

return $this->having($column, $operator, $value, 'or');
Expand Down Expand Up @@ -2225,9 +2175,7 @@ public function get($columns = ['*'])
protected function runSelect()
{
return $this->connection->select(
$this->toSql(),
$this->getBindings(),
! $this->useWritePdo
$this->toSql(), $this->getBindings(), ! $this->useWritePdo
);
}

Expand Down Expand Up @@ -2363,9 +2311,7 @@ public function cursor()

return new LazyCollection(function () {
yield from $this->connection->cursor(
$this->toSql(),
$this->getBindings(),
! $this->useWritePdo
$this->toSql(), $this->getBindings(), ! $this->useWritePdo
);
});
}
Expand Down Expand Up @@ -2400,8 +2346,7 @@ public function pluck($column, $key = null)
is_null($key) ? [$column] : [$column, $key],
function () {
return $this->processor->processSelect(
$this,
$this->runSelect()
$this, $this->runSelect()
);
}
);
Expand Down Expand Up @@ -2509,9 +2454,7 @@ public function implode($column, $glue = '')
public function exists()
{
$results = $this->connection->select(
$this->grammar->compileExists($this),
$this->getBindings(),
! $this->useWritePdo
$this->grammar->compileExists($this), $this->getBindings(), ! $this->useWritePdo
);

// If the results has rows, we will get the row and see if the exists column is a
Expand Down Expand Up @@ -2914,8 +2857,7 @@ public function delete($id = null)
}

return $this->connection->delete(
$this->grammar->compileDelete($this),
$this->cleanBindings(
$this->grammar->compileDelete($this), $this->cleanBindings(
$this->grammar->prepareBindingsForDelete($this->bindings)
)
);
Expand Down