From 5f3035aaf189710edec3b0abe686cf4bdc7147cc Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 29 Aug 2024 16:56:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3json=E5=AD=97=E6=AE=B5null?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/db/builder/Mysql.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/db/builder/Mysql.php b/src/db/builder/Mysql.php index 4d750696..bbdd5996 100644 --- a/src/db/builder/Mysql.php +++ b/src/db/builder/Mysql.php @@ -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)) { @@ -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) {