Is sqlite last_insert_rowid atomic?

I am using node.js sqlite3 to manage data. I use these codes to insert data into the database and enter the inserted id:

db.run("INSERT INTO myTable (name) VALUES ('test')");
db.get("SELECT last_insert_rowid() as id", function (err, row) {
     console.log('Last inserted id is: ' + row['id']);
});

I think this is not stable. my db connection is always open. when my server serves this code on several and at the same time client connections, does it have the SELECT last_insert_rowid()correct identifier? Is sqlite last_insert_rowid atomic? thank.

+4
source share
4 answers

According to the sqlite3 Database # run documentation (sql, [param, ...], [callback]) you can extract lastIDfrom the callback.

+7
source
try{

    db.run("INSERT INTO TABLE_NAME VALUES (NULL,?,?,?,?)",data1,data2,data3,data4,function(err){
                    if(err){
                        callback({"status":false,"val":err});
                    }else{
                        console.log("val  "+this.lastID);
                        callback({"status":true,"val":""});
                    }
                });
}catch(ex){
    callback({"status":false,"val":ex});
}

this.lastID sqlite3 Database # run (sql, [param,...], [callback])

+5

last_insert_rowid() ROWID .

, .

( API C): https://www.sqlite.org/c3ref/last_insert_rowid.html

() , . , , .. ID, .

+1

This.data.lastID .

-1

All Articles