Okay, I got a sql query here, and I want to put a dynamic value in userID
but when I put this query with another query, It seems like the whole sql query doesn't work. I think It has some problem with template string but no clue why It's not working.
好的,我在这里得到了一个sql查询,我想在userID中放置一个动态值但是当我把这个查询与另一个查询放在一起时,似乎整个sql查询都不起作用。我认为它有一些模板字符串的问题,但没有线索为什么它不工作。
query that I'm trying to use
查询我正在尝试使用
insert into CREDIT values (uuid(), userID, null, now(), now(), 3.00, 'C', now(), now(), null, null);
插入CREDIT值(uuid(),userID,null,now(),now(),3.00,'C',now(),now(),null,null);
actual js code
实际的js代码
let query = "UPDATE USER SET STATUS = 'C' WHERE CONFIRM_KEY = " + ${mysql.escape(req.params.id)}
query += `INSERT INTO CREDIT VALUES (uuid(), ${req.params.id}, null, now(), now(), 3.00, 'C', now(), now(), null, null)`
let result = await pool.query(query)
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 \'INSERT INTO CREDIT VALUES (uuid(), \'66915b91-f9f7-11e7-8ffe-8785394e9837\', null,\' at line 1' }
1 个解决方案
#1
2
It looks like you are trying to combine an update and an insert in a single query. That's not possible. Execute each as a separate query.
看起来您正在尝试在单个查询中组合更新和插入。那是不可能的。将每个执行作为单独的查询。
#1
2
It looks like you are trying to combine an update and an insert in a single query. That's not possible. Execute each as a separate query.
看起来您正在尝试在单个查询中组合更新和插入。那是不可能的。将每个执行作为单独的查询。