marcucio / Cordova-WP-SqlitePlugin

14 stars 20 forks source link

insertId is null #18

Open gvr2003 opened 10 years ago

gvr2003 commented 10 years ago

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)

gvr2003 commented 10 years ago

Hi, anyone got in to this issue and knows how to resolve it?

gvr2003 commented 10 years ago

Is there similar library that supports non batch mode? My need is to do CRUD operations in non batch mode. Any help appreciated.

biodiv commented 10 years ago

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