I need to write data to sqlite that contains single and double quotes. I was able to INSERT the data with the following code using a function node and the data is written to the table with all the quotes intact.
let id = 155;
let item = `this contains "double" and 'single' quotes`;
msg.topic = `INSERT INTO test (id, item) VALUES ($id, $item)`;
msg.payload = [id, item];
HOWEVER, I am unable to get UPDATE to work with the same data. I tried the following code in a function node and it works fine as long as the data does not contain quotes or double quotes, if it does, it errors out.
let id = 155;
let item = `this contains "double" and 'single' quotes`;
msg.topic = `UPDATE test SET item = '${item}' WHERE id = ${id}`;
msg.payload = [item];
I also tried using a mustache template.
UPDATE test SET item = '{{payload.item}}' WHERE id = {{payload.id}};
It writes the data without errors but gives me
some text with 'single quotes' and "double quotes" inside
which is not what I'm looking for. That is why I started researching doing it in a function node and was able to get it to work with INSERT.