top-think / top-think/think-orm

最新版本 连接 sqlsrv save 无法更新

Open
#112 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Sqlsrv
Dominant language
PHP
Stars
437
Forks
188
PR merge metrics
No merged PRs in 30d

Description

表现为 更新的字段 会被强制清空,

if (false !== strpos($key, '->')) { [$key, $name] = explode('->', $key, 2); $item = $this->parseKey($query, $key); $result[$item] = 'json_set(' . $item . ', \'$.' . $name . '\', ' . $this->parseDataBind($query, $key . '->' . $name, $val, $bind) . ')'; } elseif (false === strpos($key, '.') && !in_array($key, $fields, true)) { if ($options['strict']) { throw new Exception('fields not exists:[' . $key . ']'); } } elseif (is_null($val)) { $result[$item] = 'NULL'; } elseif (is_array($val) && !empty($val)) { switch (strtoupper($val[0])) { case 'INC': $result[$item] = $item . ' + ' . floatval($val[1]); break; case 'DEC': $result[$item] = $item . ' - ' . floatval($val[1]); break; } } elseif (is_scalar($val)) { // 过滤非标量数据 $result[$item] = $this->parseDataBind($query, $key, $val, $bind); }

在这个位置 MYSQL 没有问题 MSSQL 会将更新的字段清除 导致更新量总是为 0 返回成功但实际数据未修改, 具体位置在版本库 db\builder.php line 162

在 162 行 加上 $result[$item] = $this->parseDataBind($query, $key, $val, $bind); 则可以更新成功

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at db\builder.php line 162 and trace the SQL Server save path, comparing it with the MySQL behavior described in the issue. Reproduce the update with sqlsrv, then verify that the affected field is preserved and the reported update count is correct without relying on an unconfirmed workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend, databases
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.