Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Apr 20, 2020
1 parent 79e420f commit d3bb329
Showing 1 changed file with 37 additions and 31 deletions.
68 changes: 37 additions & 31 deletions src/Illuminate/Database/Query/Grammars/MySqlGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);
}
}

0 comments on commit d3bb329

Please sign in to comment.