@@ -14,6 +14,43 @@ class MySqlGrammar extends Grammar
1414 */
1515 protected $ operators = ['sounds like ' ];
1616
17+ /**
18+ * Add a "where null" clause to the query.
19+ *
20+ * @param string|array $columns
21+ * @param string $boolean
22+ * @param bool $not
23+ * @return $this
24+ */
25+ protected function whereNull (Builder $ query , $ where )
26+ {
27+ if ($ this ->isJsonSelector ($ where ['column ' ])) {
28+ [$ field , $ path ] = $ this ->wrapJsonFieldAndPath ($ where ['column ' ]);
29+
30+ return '(json_extract( ' .$ field .$ path .') is null OR json_type(json_extract( ' .$ field .$ path .')) = \'NULL \') ' ;
31+ }
32+
33+ return parent ::whereNull ($ query , $ where );
34+ }
35+
36+ /**
37+ * Add a "where not null" clause to the query.
38+ *
39+ * @param string|array $columns
40+ * @param string $boolean
41+ * @return $this
42+ */
43+ protected function whereNotNull (Builder $ query , $ where )
44+ {
45+ if ($ this ->isJsonSelector ($ where ['column ' ])) {
46+ [$ field , $ path ] = $ this ->wrapJsonFieldAndPath ($ where ['column ' ]);
47+
48+ return '(json_extract( ' .$ field .$ path .') is not null AND json_type(json_extract( ' .$ field .$ path .')) != \'NULL \') ' ;
49+ }
50+
51+ return parent ::whereNotNull ($ query , $ where );
52+ }
53+
1754 /**
1855 * Compile an insert ignore statement into SQL.
1956 *
@@ -244,35 +281,4 @@ protected function wrapJsonBooleanSelector($value)
244281
245282 return 'json_extract( ' .$ field .$ path .') ' ;
246283 }
247-
248- protected function whereNull (Builder $ query , $ where )
249- {
250- if ($ this ->isJsonSelector ($ where ['column ' ])) {
251- // In MySQL json_extract() returns different values
252- // * key not exist => SQL NULL
253- // * value is null => JSON NULL
254- //
255- // These values are not equal so we should use both checks
256- // "is null" and "json_type".
257- //
258- // https://bugs.mysql.com/bug.php?id=85755
259-
260- [$ field , $ path ] = $ this ->wrapJsonFieldAndPath ($ where ['column ' ]);
261-
262- return '(json_extract( ' .$ field .$ path .') is null OR json_type(json_extract( ' .$ field .$ path .')) = \'NULL \') ' ;
263- }
264-
265- return parent ::whereNull ($ query , $ where );
266- }
267-
268- protected function whereNotNull (Builder $ query , $ where )
269- {
270- if ($ this ->isJsonSelector ($ where ['column ' ])) {
271- [$ field , $ path ] = $ this ->wrapJsonFieldAndPath ($ where ['column ' ]);
272-
273- return '(json_extract( ' .$ field .$ path .') is not null AND json_type(json_extract( ' .$ field .$ path .')) != \'NULL \') ' ;
274- }
275-
276- return parent ::whereNotNull ($ query , $ where );
277- }
278284}
0 commit comments