Node-sqlite3: Dont recieve the lastId in callback when inserting a new row

Created on 2 Oct 2013  路  3Comments  路  Source: mapbox/node-sqlite3

Just like in topic, the callback always returns the null value and its the only value returned in case of the success.

Most helpful comment

To query .lastID, see this code example:

db.run("INSERT INTO foo ...", function(err) {
    // err is null if insertion was successful
    console.warn("inserted id:", this.lastID);
});

All 3 comments

can you post a working testcase that replicates the issue?

There are several ways to execute a query: https://github.com/developmentseed/node-sqlite3/wiki/API

By design, .run() returns null as the first parameter if no error occurs, and doesn't return data if the query was a select statement. To get the data, use .get() instead.

To query .lastID, see this code example:

db.run("INSERT INTO foo ...", function(err) {
    // err is null if insertion was successful
    console.warn("inserted id:", this.lastID);
});
Was this page helpful?
0 / 5 - 0 ratings

Related issues

milu2003 picture milu2003  路  16Comments

Hedva picture Hedva  路  29Comments

coolaj86 picture coolaj86  路  28Comments

Thavaprakash picture Thavaprakash  路  31Comments

creationix picture creationix  路  22Comments