From d3bb329ce40e716e8e92aa7c27a929be60511a97 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 20 Apr 2020 09:03:36 -0500 Subject: [PATCH] formatting --- .../Database/Query/Grammars/MySqlGrammar.php | 68 ++++++++++--------- 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/src/Illuminate/Database/Query/Grammars/MySqlGrammar.php b/src/Illuminate/Database/Query/Grammars/MySqlGrammar.php index 17f9f214180d..494018803723 100755 --- a/src/Illuminate/Database/Query/Grammars/MySqlGrammar.php +++ b/src/Illuminate/Database/Query/Grammars/MySqlGrammar.php @@ -14,6 +14,43 @@ class MySqlGrammar extends Grammar */ protected $operators = ['sounds like']; + /** + * Add a "where null" clause to the query. + * + * @param string|array $columns + * @param string $boolean + * @param bool $not + * @return $this + */ + protected function whereNull(Builder $query, $where) + { + if ($this->isJsonSelector($where['column'])) { + [$field, $path] = $this->wrapJsonFieldAndPath($where['column']); + + return '(json_extract('.$field.$path.') is null OR json_type(json_extract('.$field.$path.')) = \'NULL\')'; + } + + return parent::whereNull($query, $where); + } + + /** + * Add a "where not null" clause to the query. + * + * @param string|array $columns + * @param string $boolean + * @return $this + */ + protected function whereNotNull(Builder $query, $where) + { + if ($this->isJsonSelector($where['column'])) { + [$field, $path] = $this->wrapJsonFieldAndPath($where['column']); + + return '(json_extract('.$field.$path.') is not null AND json_type(json_extract('.$field.$path.')) != \'NULL\')'; + } + + return parent::whereNotNull($query, $where); + } + /** * Compile an insert ignore statement into SQL. * @@ -244,35 +281,4 @@ protected function wrapJsonBooleanSelector($value) return 'json_extract('.$field.$path.')'; } - - protected function whereNull(Builder $query, $where) - { - if ($this->isJsonSelector($where['column'])) { - // In MySQL json_extract() returns different values - // * key not exist => SQL NULL - // * value is null => JSON NULL - // - // These values are not equal so we should use both checks - // "is null" and "json_type". - // - // https://bugs.mysql.com/bug.php?id=85755 - - [$field, $path] = $this->wrapJsonFieldAndPath($where['column']); - - return '(json_extract('.$field.$path.') is null OR json_type(json_extract('.$field.$path.')) = \'NULL\')'; - } - - return parent::whereNull($query, $where); - } - - protected function whereNotNull(Builder $query, $where) - { - if ($this->isJsonSelector($where['column'])) { - [$field, $path] = $this->wrapJsonFieldAndPath($where['column']); - - return '(json_extract('.$field.$path.') is not null AND json_type(json_extract('.$field.$path.')) != \'NULL\')'; - } - - return parent::whereNotNull($query, $where); - } }