ali-sdk / ali-rds

Aliyun RDS client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

当 where 和 row 中有相同值时, update 会报错

hoythan opened this issue · comments

commented
// 这种情况的意思是 查询 userid 等于 12  并且 key 等于 'world' 的然后改成 hello
mysql.update('table',{ key: 'hello' }, { where: { userid:12, key:'world'  } })
     Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE `userid` = 1 AND `key` = 'wo' at line 1
      at Query.Sequence._packetToError (test/fixtures/apps/api-utils-test/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)
      at Query.ErrorPacket (test/fixtures/apps/api-utils-test/node_modules/mysql/lib/protocol/sequences/Query.js:77:18)
      at Protocol._parsePacket (test/fixtures/apps/api-utils-test/node_modules/mysql/lib/protocol/Protocol.js:278:3)
      at Parser.write (test/fixtures/apps/api-utils-test/node_modules/mysql/lib/protocol/Parser.js:76:12)
      at Protocol.write (test/fixtures/apps/api-utils-test/node_modules/mysql/lib/protocol/Protocol.js:38:16)
      at Socket.<anonymous> (test/fixtures/apps/api-utils-test/node_modules/mysql/lib/Connection.js:91:28)
      at Socket.<anonymous> (test/fixtures/apps/api-utils-test/node_modules/mysql/lib/Connection.js:502:10)
      at addChunk (_stream_readable.js:263:12)
      at readableAddChunk (_stream_readable.js:250:11)
      at Socket.Readable.push (_stream_readable.js:208:10)
      at TCP.onread (net.js:597:20)

但这种情况在 mysql 是支持的

原因

发现是因为ali-rds 中判断了如果条件和 set 值相同,将会被过滤,导致 set 为空

我也遇到这个问题,代码:

await conn.update('wp_term_relationships', { term_taxonomy_id: 1 }, { 
  where: { term_taxonomy_id: 12 },
  columns: [ 'term_taxonomy_id' ]
})

错误信息

code: "ER_PARSE_ERROR"
errno: 1064
sqlMessage: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE `term_taxonomy_id` = '12'' at line 1"
sqlState: "42000"
index: 0
sql: "UPDATE `wp_term_relationships` SET  WHERE `term_taxonomy_id` = '12'"
headers: {"Access-Control-Allow-Origin":"http://localhost:9527","vary":"Origin"}
name: "ER_PARSE_ERRORError"
pid: 2044
hostname: AGOCG-804111845

column被吞掉了