Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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 ..


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
312 views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...