How to get last inserted row id from sqlite in phonegap android

I am creating an application in which I insert data into a table. After inserting the data into the table, I want to get the identifier of this row so that I can perform further operation depending on it. I tried using the last_insert_rowid () sqlite function, but did not find any luck. can anyone say what is the best way to get the last inserted row id. Any idea is appreciated. Thanks in advance.

+4
source share
2 answers

You can get the id of the last insert in the table, for example:

tx.executeSql("INSERT INTO profile('name','label','list_order','category') values(?,?,?,?)", 
    [currentProfile.name, currentProfile.label, currentProfile.list_order, currentProfile.category], 
    function(tx, results){
        var lastInsertId = results.insertId; // this is the id of the insert just performed
    }, 
    failCB
)

results.insertIdin WebSQL is similar to mysql_insert_id()in MySQL -

mysql_query("INSERT INTO mytable (product) values ('kossu')");
printf("Last inserted record has id %d\n", mysql_insert_id());
+4

rowid, oid _rowid_? , last_insert_rowid(), . . .

: , , SQL .

SELECT * FROM yourTable ORDER BY yourIdColumn DESC LIMIT 1

, .

+1