I use the property db.lastInsertRowId with great success.  Maybe you
should give that a try.

On Aug 11, 4:29 am, Eduard Martini <[email protected]> wrote:
> I haven't checked this, so I may be totally out of picture with this,
> but I suspect that if you enclose your js queries into a transaction,
> last_inserted_rowid() will work for inserts inside that transaction
> and will be lost when db is close().
>
> Just quick thought, may be wrong.
>
> On Aug 10, 12:43 am, Roman <[email protected]> wrote:
>
> > Hi
>
> > What is the difference of using last_insert_row() in a Javascript
> > function vs. using it in DB Query Tool?
>
> > I have created a table in Google Gears (Sqlite):
>
> > db.execute('create table if not exists SPALINKS (link_id int PRIMARY
> > KEY, sid1 int, sid2 int, label text, user text, Timestamp int');
>
> > When using the Google Gears Database Query Tool (in FF 3.5), INSERT
> > with 'last_insert_rowid()' works fine. Inserts from Javascript work
> > fine, as long a I don't use 'last_insert_rowid()'. But when using
> > 'last_insert_rowid()' it doesn't work anymore:
>
> > var sql_stmt = 'INSERT INTO SPALINKS (link_id, sid1, sid2, label,
> > user, Timestamp) VALUES (last_insert_rowid(),?,?,?,?,?)';
> > var arg_array = [sid1, sid2, label, user, creation_time];
> > db.execute(sql_stmt, arg_array);
>
> > this results in:
> > Error: Database operation failed. ERROR: constraint failed DETAILS:
> > constraint failed
>
> > Why does SQLite's 'last-insert-rowid' work fine with the DB Tool, but
> > not in a SQL statement that is created and executed from inside a
> > Javascript function?
>
> > Note: this post is the same as the one 
> > here:http://stackoverflow.com/questions/1249365/difference-when-using-last...
>
> > -Roman

Reply via email to