On 04.04.2011, at 15:59, Simon Slavin wrote:

> 
> On 4 Apr 2011, at 2:48pm, Enrico Thierbach wrote:
> 
>> isn't last_insert_rowid defined as the ID of the last row inserted
> 
> Yes it is.  But the FTS system does what it does by maintaining extra tables, 
> and doing extra operations to them besides the ones that the programmer has 
> asked for.  Naturally this means that several things get done after each 
> INSERT operation the programmer asked for, so last_insert_rowid() may as well 
> be a random number.
> 

I might have an exceptionally dumb day, but this sequence (from this post 
http://www.mail-archive.com/sqlite-users@sqlite.org/msg34082.html ) looks 
totally fine:
> insert into one (value) values ("hello1");
> select last_insert_rowid();   -- returns 1
> insert into one (value) values ("hello2");
> select last_insert_rowid(); -- returns 2
> update one set value="hello3" where id=1;
> select last_insert_rowid(); -- returns 3, but should return 2
until the update (assuming that the IDs reported are right, of course). The 
last one would not be a problem in my understanding, as last_insert_rowid() 
gets undefined by the UPDATE anyways. Or do I miss a point?

On the other hand, http://www.sqlite.org/c3ref/last_insert_rowid.html defines 
the last insert rowid as

"This routine returns the rowid of the most recent successful INSERT into the 
database from the database connection in the first argument. If no successful 
INSERTs have ever occurred on that database connection, zero is returned."

As this doesn't mention non-INSERT changes I tend to see my understanding as 
wrong :)

/eno

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to