Search code examples
javascriptsqlitesafarimobile-safari

SQLite web-app, get row from insert?


I have this code:

database.transaction(function(transaction) {
    transaction.executeSql('INSERT INTO incomplete (todo, description, date) VALUES (?, ?, ?);', [todoInput, descriptionInput, myDate]);
});

But what I want to do is to get the row[]; (or more specifically row[id]) from what I just inserted.

Does the transaction method return any more values?

UPDATE:

I inserted it with variables, standard sqlite-webapp way.

    var todoInput = $('#todo').val();
    var descriptionInput = $('#description').val();
    var myDate = new Date();
    myDate.getMonth() + 1 + '/' + myDate.getDate() + '/' + myDate.getFullYear();

    database.transaction(function(transaction) {
        transaction.executeSql('INSERT INTO incomplete (todo, description, date) VALUES (?, ?, ?);', [todoInput, descriptionInput, myDate]);
    });

Solution

  • you need to return the id straight after your insert.

    add this ;select scope_identity() to your query.

    then you should be able to pull out the id of the inserted row and do what you want from there.