insertId is null
Opened this issue · 3 comments
Hi,
When I run the test application included here I am getting the insertId as null. How can I get the id of the last row that has been inserted when the INSERT query is called?
I need the last row inserted id for using in the other places as foreign key. In the below code from the test application I get insertId as undefined. Any help is greatly appreciated.
tx.executeSql(
'INSERT INTO sql_test (test_id, test_name) VALUES (?, ?);',
['1', 'Hi 1'],
function(results){console.log('Callback 2 complete')
console.log('Callback 2 complete result:'+JSON.stringify(results))
recordId = results.insertId;
console.log('Callback 2 complete result: '+recordId)
Hi, anyone got in to this issue and knows how to resolve it?
Is there similar library that supports non batch mode? My need is to do CRUD operations in non batch mode. Any help appreciated.
this is a known bug. You will have to do a second query:
SELECT MAX(id) FROM TABLE
or
SELECT last_insert_rowid() FROM TABLE