Skip to content

Commit

Permalink
Revert "Bitwise (#41112)"
Browse files Browse the repository at this point in the history
This reverts commit 95b732f.
  • Loading branch information
taylorotwell committed Feb 22, 2022
1 parent b91b3b5 commit 3010530
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 196 deletions.
29 changes: 0 additions & 29 deletions src/Illuminate/Database/Query/Builder.php
Expand Up @@ -203,15 +203,6 @@ class Builder
'not similar to', 'not ilike', '~~*', '!~~*',
];

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

/**
* 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->isBitwiseOperator($operator)) {
$type = 'Bitwise';
}

// 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 bitwise operator.
*
* @param string $operator
* @return bool
*/
protected function isBitwiseOperator($operator)
{
return in_array(strtolower($operator), $this->bitwiseOperators, true) ||
in_array(strtolower($operator), $this->grammar->getBitwiseOperators(), 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->isBitwiseOperator($operator)) {
$type = 'Bitwise';
}

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

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

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

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

/**
* Compile a bitwise operator where clause.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $where
* @return string
*/
protected function whereBitwise(Builder $query, $where)
{
return $this->whereBasic($query, $where);
}

/**
* Compile a "where in" clause.
*
Expand Down Expand Up @@ -1318,14 +1299,4 @@ public function getOperators()
{
return $this->operators;
}

/**
* Get the grammar specific bitwise operators.
*
* @return array
*/
public function getBitwiseOperators()
{
return $this->bitwiseOperators;
}
}
55 changes: 0 additions & 55 deletions src/Illuminate/Database/Query/Grammars/PostgresGrammar.php
Expand Up @@ -21,15 +21,6 @@ class PostgresGrammar extends Grammar
'is distinct from', 'is not distinct from',
];

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

/**
* {@inheritdoc}
*
Expand All @@ -51,22 +42,6 @@ protected function whereBasic(Builder $query, $where)
return parent::whereBasic($query, $where);
}

/**
* {@inheritdoc}
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $where
* @return string
*/
protected function whereBitwise(Builder $query, $where)
{
$value = $this->parameter($where['value']);

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

return '('.$this->wrap($where['column']).' '.$operator.' '.$value.')::bool';
}

/**
* Compile a "where date" clause.
*
Expand Down Expand Up @@ -231,36 +206,6 @@ protected function compileJsonLength($column, $operator, $value)
return 'json_array_length(('.$column.')::json) '.$operator.' '.$value;
}

/**
* {@inheritdoc}
*
* @param array $having
* @return string
*/
protected function compileHaving(array $having)
{
if ($having['type'] === 'Bitwise') {
return $this->compileHavingBitwise($having);
}

return parent::compileHaving($having);
}

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

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

return $having['boolean'].' ('.$column.' '.$having['operator'].' '.$parameter.')::bool';
}

/**
* Compile the lock into SQL.
*
Expand Down
46 changes: 0 additions & 46 deletions src/Illuminate/Database/Query/Grammars/SqlServerGrammar.php
Expand Up @@ -96,22 +96,6 @@ protected function compileFrom(Builder $query, $table)
return $from;
}

/**
* {@inheritdoc}
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $where
* @return string
*/
protected function whereBitwise(Builder $query, $where)
{
$value = $this->parameter($where['value']);

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

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

/**
* Compile a "where date" clause.
*
Expand Down Expand Up @@ -180,36 +164,6 @@ protected function compileJsonLength($column, $operator, $value)
return '(select count(*) from openjson('.$field.$path.')) '.$operator.' '.$value;
}

/**
* {@inheritdoc}
*
* @param array $having
* @return string
*/
protected function compileHaving(array $having)
{
if ($having['type'] === 'Bitwise') {
return $this->compileHavingBitwise($having);
}

return parent::compileHaving($having);
}

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

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

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

/**
* Create a full ANSI offset clause for the query.
*
Expand Down
2 changes: 0 additions & 2 deletions tests/Database/DatabaseEloquentModelTest.php
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('getBitwiseOperators')->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('getBitwiseOperators')->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
35 changes: 0 additions & 35 deletions tests/Database/DatabaseQueryBuilderTest.php
Expand Up @@ -3209,41 +3209,6 @@ public function testMySqlSoundsLikeOperator()
$this->assertEquals(['John Doe'], $builder->getBindings());
}

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

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

$builder = $this->getPostgresBuilder();
$builder->select('*')->from('users')->where('range', '>>', '[2022-01-08 00:00:00,2022-01-09 00:00:00)');
$this->assertSame('select * from "users" where ("range" >> ?)::bool', $builder->toSql());

$builder = $this->getSqlServerBuilder();
$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" & ?', $builder->toSql());

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

$builder = $this->getPostgresBuilder();
$builder->select('*')->from('users')->having('range', '>>', '[2022-01-08 00:00:00,2022-01-09 00:00:00)');
$this->assertSame('select * from "users" having ("range" >> ?)::bool', $builder->toSql());

$builder = $this->getSqlServerBuilder();
$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

0 comments on commit 3010530

Please sign in to comment.