views:

145

answers:

1

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), INSERT with 'last-insert-rowid' work 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);

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?

A: 

It seems that the problem was that the respective column wasn't defined as AUTOINCREMENT.

Roman