Hi All,

I would appreciate help with the following scenario.

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. If it's a single threaded system then the
above surely works. But if I am in a multi(threaded/process) system,
then there is a problem. 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. If it's
possible then I have a problem and I will have to start looking at
wrapping the above in explicit SQLITE transactions.

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

Reply via email to