From 74de0778f7c283a2ba12d935e5432845a5511c86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E5=A5=94=E7=A7=91?= <972341480@qq.com> Date: Wed, 19 Mar 2025 13:01:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81sqlsrv=E4=B8=8B=E4=BF=AE?= =?UTF-8?q?=E6=94=B9json=E4=B8=AD=E6=9F=90=E4=B8=80=E5=AD=97=E6=AE=B5,?= =?UTF-8?q?=E4=BB=85=E9=99=90sqlsrv=E7=89=88=E6=9C=AC=E9=AB=98=E4=BA=8E201?= =?UTF-8?q?6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/db/Builder.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/db/Builder.php b/src/db/Builder.php index 0a1dc733..037a2030 100644 --- a/src/db/Builder.php +++ b/src/db/Builder.php @@ -60,7 +60,11 @@ protected function parseData(Query $query, array $data = [], array $fields = [], $result = []; foreach ($data as $key => $val) { - $item = $this->parseKey($query, $key, true); + $strict = false; + if (false === stripos($key,'->')){ + $strict = true; + } + $item = $this->parseKey($query, $key, $strict); if ($val instanceof BackedEnum) { $val = $val->value; } elseif ($val instanceof UnitEnum) { @@ -79,7 +83,11 @@ protected function parseData(Query $query, array $data = [], array $fields = [], [$key, $name] = explode('->', $key, 2); $item = $this->parseKey($query, $key); - $result[$item . '->' . $name] = 'json_set(' . $item . ', \'$.' . $name . '\', ' . $this->parseDataBind($query, $key . '->' . $name, $val, $bind) . ')'; + if ($this->getConnection()->getConfig('type') == 'sqlsrv'){ + $result[$item . '->' . $name] = 'JSON_MODIFY(' . $item . ', \'$.' . $name . '\', ' . $this->parseDataBind($query, $key . '->' . $name, $val, $bind) . ')'; + }else{ + $result[$item . '->' . $name] = 'json_set(' . $item . ', \'$.' . $name . '\', ' . $this->parseDataBind($query, $key . '->' . $name, $val, $bind) . ')'; + } } elseif (!str_contains($key, '.') && !in_array($key, $fields, true)) { if ($options['strict']) { throw new Exception('fields not exists:[' . $key . ']');