SQL Statement working perfectly fine when ran in DB Browser for SQLite but not in node.js code. Are there any changes that I need to make?
I created a query that would INSERT values into a table if the specified values did not exist, or UPDATE values if they do exist. When ran in the DB Browser for SQLite, the query worked perfectly but when I tried to implement it in my code, the UPDATE statement works but not the INSERT statement, with no errors being returned. Why is that?
let sql2 = `UPDATE inventory
SET item_name = '${itemChosen}', item_amount = ${amountChosen) where discordId = '${user}';
INSERT INTO inventory (discordId,item_name,item_amount)
select '${user}','${itemChosen}',${amountChosen}
WHERE (Select changes() = 0);`;
db.all(sql2, [], (err, rows) => {
if (err) {
throw (err)
}
message.reply("Item purchased!");
})
The UPDATE statement works fine, but the INSERT statement will never get executed. No error messages are returned.