Skip to content

Commit

Permalink
修正json字段null查询
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Aug 29, 2024
1 parent a991b29 commit 5f3035a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/db/builder/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ public function parseKey(Query $query, string | int | Raw $key, bool $strict = f
// JSON字段支持
[$field, $name] = explode('->', $key, 2);

return 'JSON_UNQUOTE(json_extract(' . $this->parseKey($query, $field, true) . ', \'$' . (str_starts_with($name, '[') ? '' : '.') . str_replace('->', '.', $name) . '\'))';
return 'json_unquote(json_extract(' . $this->parseKey($query, $field, true) . ', \'$' . (str_starts_with($name, '[') ? '' : '.') . str_replace('->', '.', $name) . '\'))';
}

if (str_contains($key, '.') && !preg_match('/[,\'\"\(\)`\s]/', $key)) {
Expand Down Expand Up @@ -441,7 +441,9 @@ public function parseKey(Query $query, string | int | Raw $key, bool $strict = f
*/
protected function parseNull(Query $query, string $key, string $exp, $value, $field, int $bindType): string
{
if (str_starts_with($key, "json_extract")) {
if (str_starts_with($key, "json_unquote(json_extract")) {
$key = str_replace('json_unquote(json_extract', '(json_extract', $key);

if ('NULL' === $exp) {
return '(' . $key . ' is null OR json_type(' . $key . ') = \'NULL\')';
} elseif ('NOT NULL' === $exp) {
Expand Down

0 comments on commit 5f3035a

Please sign in to comment.