0

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.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

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Richard. Never thought of doing it that way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.