Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hoythan opened this issue Apr 10, 2019 · 1 comment
Open

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

hoythan opened this issue Apr 10, 2019 · 1 comment

Comments

@hoythan
Copy link
Contributor

hoythan commented Apr 10, 2019

// 这种情况的意思是 查询 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 为空

@hoythan hoythan closed this as completed Apr 10, 2019
@hoythan hoythan changed the title where 值 当 where 和 row 中有相同值时, update 会报错 Apr 10, 2019
@hoythan hoythan reopened this Apr 10, 2019
@chwech
Copy link

chwech commented Nov 2, 2020

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

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被吞掉了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants