From 30105303f6875c0fcb96a77074e5d0c63aba2d2a Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 22 Feb 2022 09:22:35 -0600 Subject: [PATCH] Revert "Bitwise (#41112)" This reverts commit 95b732f30adba8f02fca47e4af625e221691cc81. --- src/Illuminate/Database/Query/Builder.php | 29 ---------- .../Database/Query/Grammars/Grammar.php | 29 ---------- .../Query/Grammars/PostgresGrammar.php | 55 ------------------- .../Query/Grammars/SqlServerGrammar.php | 46 ---------------- tests/Database/DatabaseEloquentModelTest.php | 2 - tests/Database/DatabaseQueryBuilderTest.php | 35 ------------ 6 files changed, 196 deletions(-) diff --git a/src/Illuminate/Database/Query/Builder.php b/src/Illuminate/Database/Query/Builder.php index 908d97d129aa..2d2d96ff76bc 100755 --- a/src/Illuminate/Database/Query/Builder.php +++ b/src/Illuminate/Database/Query/Builder.php @@ -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. * @@ -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. @@ -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. * @@ -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) { diff --git a/src/Illuminate/Database/Query/Grammars/Grammar.php b/src/Illuminate/Database/Query/Grammars/Grammar.php index 0dbdb1e0535e..77472f088e02 100755 --- a/src/Illuminate/Database/Query/Grammars/Grammar.php +++ b/src/Illuminate/Database/Query/Grammars/Grammar.php @@ -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. * @@ -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. * @@ -1318,14 +1299,4 @@ public function getOperators() { return $this->operators; } - - /** - * Get the grammar specific bitwise operators. - * - * @return array - */ - public function getBitwiseOperators() - { - return $this->bitwiseOperators; - } } diff --git a/src/Illuminate/Database/Query/Grammars/PostgresGrammar.php b/src/Illuminate/Database/Query/Grammars/PostgresGrammar.php index 1b49bf10e9cb..47f498e54708 100755 --- a/src/Illuminate/Database/Query/Grammars/PostgresGrammar.php +++ b/src/Illuminate/Database/Query/Grammars/PostgresGrammar.php @@ -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} * @@ -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. * @@ -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. * diff --git a/src/Illuminate/Database/Query/Grammars/SqlServerGrammar.php b/src/Illuminate/Database/Query/Grammars/SqlServerGrammar.php index 417b63e4a324..3fce201bd28c 100755 --- a/src/Illuminate/Database/Query/Grammars/SqlServerGrammar.php +++ b/src/Illuminate/Database/Query/Grammars/SqlServerGrammar.php @@ -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. * @@ -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. * diff --git a/tests/Database/DatabaseEloquentModelTest.php b/tests/Database/DatabaseEloquentModelTest.php index 5597accae834..76fa651e855c 100755 --- a/tests/Database/DatabaseEloquentModelTest.php +++ b/tests/Database/DatabaseEloquentModelTest.php @@ -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); @@ -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) { diff --git a/tests/Database/DatabaseQueryBuilderTest.php b/tests/Database/DatabaseQueryBuilderTest.php index ef2c67a3b588..d27a38a10276 100755 --- a/tests/Database/DatabaseQueryBuilderTest.php +++ b/tests/Database/DatabaseQueryBuilderTest.php @@ -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();