开发者

Error adding row to sqlite database using Appcelerator Titanium

开发者 https://www.devze.com 2023-02-08 07:33 出处:网络
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:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消