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

[8.x] Revert Bit operators #40791

Merged
merged 1 commit into from
Feb 3, 2022
Merged
Show file tree
Hide file tree
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
29 changes: 0 additions & 29 deletions src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,6 @@ class Builder
'not similar to', 'not ilike', '~~*', '!~~*',
];

/**
* All of the available bit operators.
*
* @var string[]
*/
public $bitOperators = [
'&', '|', '^', '<<', '>>', '&~',
];

/**
* Whether to use write pdo for the select.
*
Expand Down Expand Up @@ -763,10 +754,6 @@ public function where($column, $operator = null, $value = null, $boolean = 'and'
}
}

if ($this->isBitOperator($operator)) {
$type = 'Bit';
}

// Now that we are working with just a simple query we can put the elements
// 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.
Expand Down Expand Up @@ -850,18 +837,6 @@ protected function invalidOperator($operator)
! in_array(strtolower($operator), $this->grammar->getOperators(), true);
}

/**
* Determine if the operator is a bit operator.
*
* @param string $operator
* @return bool
*/
protected function isBitOperator($operator)
{
return in_array(strtolower($operator), $this->bitOperators, true) ||
in_array(strtolower($operator), $this->grammar->getBitOperators(), true);
}

/**
* Add an "or where" clause to the query.
*
Expand Down Expand Up @@ -1940,10 +1915,6 @@ public function having($column, $operator = null, $value = null, $boolean = 'and
[$value, $operator] = [$operator, '='];
}

if ($this->isBitOperator($operator)) {
$type = 'bit';
}

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

if (! $value instanceof Expression) {
Expand Down
50 changes: 0 additions & 50 deletions src/Illuminate/Database/Query/Grammars/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ class Grammar extends BaseGrammar
*/
protected $operators = [];

/**
* The grammar specific bit operators.
*
* @var array
*/
protected $bitOperators = [];

/**
* The components that make up a select clause.
*
Expand Down Expand Up @@ -262,22 +255,6 @@ protected function whereBasic(Builder $query, $where)
return $this->wrap($where['column']).' '.$operator.' '.$value;
}

/**
* Compile a bit operator where clause.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $where
* @return string
*/
protected function whereBit(Builder $query, $where)
{
$value = $this->parameter($where['value']);

$operator = str_replace('?', '??', $where['operator']);

return '('.$this->wrap($where['column']).' '.$operator.' '.$value.') != 0';
}

/**
* Compile a "where in" clause.
*
Expand Down Expand Up @@ -708,8 +685,6 @@ protected function compileHaving(array $having)
return $having['boolean'].' '.$having['sql'];
} elseif ($having['type'] === 'between') {
return $this->compileHavingBetween($having);
} elseif ($having['type'] === 'bit') {
return $this->compileHavingBit($having);
}

return $this->compileBasicHaving($having);
Expand Down Expand Up @@ -749,21 +724,6 @@ protected function compileHavingBetween($having)
return $having['boolean'].' '.$column.' '.$between.' '.$min.' and '.$max;
}

/**
* Compile a having clause involving a bit operator.
*
* @param array $having
* @return string
*/
protected function compileHavingBit($having)
{
$column = $this->wrap($having['column']);

$parameter = $this->parameter($having['value']);

return $having['boolean'].' ('.$column.' '.$having['operator'].' '.$parameter.') != 0';
}

/**
* Compile the "order by" portions of the query.
*
Expand Down Expand Up @@ -1339,14 +1299,4 @@ public function getOperators()
{
return $this->operators;
}

/**
* Get the grammar specific bit operators.
*
* @return array
*/
public function getBitOperators()
{
return $this->bitOperators;
}
}
9 changes: 0 additions & 9 deletions src/Illuminate/Database/Query/Grammars/PostgresGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,6 @@ class PostgresGrammar extends Grammar
'is distinct from', 'is not distinct from',
];

/**
* The grammar specific bit operators.
*
* @var array
*/
protected $bitOperators = [
'~', '&', '|', '#', '<<', '>>', '<<=', '>>=',
];

/**
* {@inheritdoc}
*
Expand Down
2 changes: 0 additions & 2 deletions tests/Database/DatabaseEloquentModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2153,7 +2153,6 @@ protected function addMockConnection($model)
$model->setConnectionResolver($resolver = m::mock(ConnectionResolverInterface::class));
$resolver->shouldReceive('connection')->andReturn($connection = m::mock(Connection::class));
$connection->shouldReceive('getQueryGrammar')->andReturn($grammar = m::mock(Grammar::class));
$grammar->shouldReceive('getBitOperators')->andReturn([]);
$connection->shouldReceive('getPostProcessor')->andReturn($processor = m::mock(Processor::class));
$connection->shouldReceive('query')->andReturnUsing(function () use ($connection, $grammar, $processor) {
return new BaseBuilder($connection, $grammar, $processor);
Expand Down Expand Up @@ -2441,7 +2440,6 @@ public function getConnection()
{
$mock = m::mock(Connection::class);
$mock->shouldReceive('getQueryGrammar')->andReturn($grammar = m::mock(Grammar::class));
$grammar->shouldReceive('getBitOperators')->andReturn([]);
$mock->shouldReceive('getPostProcessor')->andReturn($processor = m::mock(Processor::class));
$mock->shouldReceive('getName')->andReturn('name');
$mock->shouldReceive('query')->andReturnUsing(function () use ($mock, $grammar, $processor) {
Expand Down
19 changes: 0 additions & 19 deletions tests/Database/DatabaseQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3209,25 +3209,6 @@ public function testMySqlSoundsLikeOperator()
$this->assertEquals(['John Doe'], $builder->getBindings());
}

public function testBitOperators()
{
$builder = $this->getBuilder();
$builder->select('*')->from('users')->where('bar', '&', 1);
$this->assertSame('select * from "users" where ("bar" & ?) != 0', $builder->toSql());

$builder = $this->getPostgresBuilder();
$builder->select('*')->from('users')->where('bar', '#', 1);
$this->assertSame('select * from "users" where ("bar" # ?) != 0', $builder->toSql());

$builder = $this->getBuilder();
$builder->select('*')->from('users')->having('bar', '&', 1);
$this->assertSame('select * from "users" having ("bar" & ?) != 0', $builder->toSql());

$builder = $this->getPostgresBuilder();
$builder->select('*')->from('users')->having('bar', '#', 1);
$this->assertSame('select * from "users" having ("bar" # ?) != 0', $builder->toSql());
}

public function testMergeWheresCanMergeWheresAndBindings()
{
$builder = $this->getBuilder();
Expand Down