"Gaurav Mathur" <[EMAIL PROTECTED]>
wrote in message
news:[EMAIL PROTECTED]
> Suppose I have the following schema:
>
> CREATE TABLE t1
> (
> f1 integer,
> f2 text
> );
>
> CREATE TABLE t2
> (
> val integer
> );
>
> Suppose the following inserts statement are executed by two processes
> over the above schema.
>
> insert into t1 values ((SELECT val FROM t2 WHERE ROWID=1), "aa");
> UPDATE t2 SET  val = val + 1 WHERE ROWID=1;
>
> The idea is to use the value 'val' from the table t2 and set the value
> of f1 to that value on an insert. The question I have is whether I can
> rely on the above sequence of SQL to reliably generate *unique* f2
> values for all INSERTs.

Why not just use ROWID as a unique identifier?

> Basically, I am not sure whether there is a
> possibility that a thread/process can be preempted after executing the
> SELECT but before executing the INSERT in that thread/process.

No. An implicit transaction is created for each statement. What is 
possible is for another thread to squeeze a statement between your 
insert and update. To prevent that, surround the two statements with an 
explicit transaction.

Igor Tandetnik



_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to