I'm working with node and the sqlite3 and sqlite npm packages.
I'm trying to run a prepared update statement which is failing. I have:
async function update_json_obj_into_table_by_PropertyId(db,tablename, obj, PropertyId) {
const x = await db.run("UPDATE 'myData' SET StateCode = ? WHERE PropertyId = ? " ,obj.StateCode,PropertyId);
console.log(x)
}
I'm calling it with:
const sqlite3 = require('sqlite3').verbose();
const sqlite = require('sqlite')
async function openDb() {
const db = await sqlite.open({filename: './test.db',driver: sqlite3.Database})
db.on("trace", (data) => { console.log(data); });
console.log('connected!')
return db;
}
followed by:
if (StateCodeTable && StateCodeTable[0].type) {
let json = { StateCode:StateCodeTable[0].type}
const x =await update_json_obj_into_table_by_PropertyId(db,'myData', json, myR);
console.log('inserted');
} else {
console.log('No insert');
}
and I'm seeing in the console:
{ stmt: Statement { stmt: undefined }, lastID: 0, changes: 1 }
inserted
When I go back and chexk the table manually , I find that the updates have not been made. How can I fix this?
Edit,
I added:
db.on("trace", (data) => { console.log(data); });
Now in console:
UPDATE 'myData' SET StateCode = 'C1' WHERE PropertyId = 'R50155' { stmt: Statement { stmt: undefined }, lastID: 0, changes: 1 } inserted
This looks right to me but and
SELECT * FROM 'myData' WHERE StateCode != 'NULL';
Is actually yielding the expected response when I test it manually - still not sure why it says undefined ..