Error adding row to sqlite database using Appcelerator Titanium
I've created a HTML/JS project in Titanium to develop a desktop app, and have the following code to add data to a sqlite table:
var db = Ti.Database.install('/data/', 'fyw');
db.execute('INSERT INTO newtable (col1, col2, col3, col4) VALUES (?,?,?,?)', 'col1', 'col2', 'col3', 'col4');
Titanium.API开发者_JAVA百科.info('JUST INSERTED, lastInsertRowId = ' + db.lastInsertRowId);
db.close();
The code is wrapped in a try...catch and the error I get is "undefined". How can I add a row, then get the id (it's an autoincrement field) which I need to use further down the code?
Thanks,
Adrian
Haven't tried it myself in titanium, but you could use the maxid sql to get the last row index and use that instead further down the script.
SELECT max(id) FROM table etc
Hope that helps a bit
精彩评论