On 1 Jul 2011, at 7:54pm, KeithB wrote: > Is there any way to perform the equivalent of an INSERT OR UPDATE statement? > > I have something like this: > > CREATE TABLE t1 (id INTEGER PRIMARY KEY, value INTEGER); > CREATE TABLE t2 (parent INTEGER REFERENCES t1 ON DELETE CASCADE, child > INTEGER REFERENCES t1); > INSERT INTO t1 VALUES(1,100); > INSERT INTO t1 VALUES(2,200); > INSERT INTO t2 VALUES(1,2); > > Later on, I want to change the value of t1(1,100) to (1,101) or insert > a new row, I don't know which. > > I realize I can do INSERT OR REPLACE, but if I have a foreign key > referencing that table with CASCADE DELETE, the delete propagates and > t2(1,2) is removed.
You have correctly defined primary keys which makes it easy. First do an INSERT OR IGNORE … which will IGNORE if the row already exists. Follow that with an UPDATE. Simon. _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users