>From: "Rob Duncan" <[EMAIL PROTECTED]>
>The last_insert_rowid() function seems to be close to what I want.  The
>trouble with it is that as soon as I add a row to the first child table
>its value will change and I will not be able to use it for any other
>child inserts.

Hi Ron,

SQLite doesn't suport user variables to store temporary data, but you can
store data in small tables. This can be used to solve your problem with a
small SQL script.

Given the following tables to hold the data:

CREATE TABLE t1 (pk INTEGER PRIMARY KEY, a);
CREATE TABLE t2 (fk INTEGER REFERENCES t1, b);
CREATE TABLE t3 (fk INTEGER REFERENCES t1, c);

And another table to hold the temporary value;

CREATE TABLE last_insert (row_id INTEGER);
INSERT INTO last_insert values (-1);

You can do the following to insert linked records into the three tables.

INSERT INTO t1 VALUES (NULL, 100);
UPDATE last_insert SET row_id = last_insert_rowid();
INSERT INTO t2 VALUES ((SELECT row_id FROM last_insert), 200);
INSERT INTO t3 VALUES ((SELECT row_id FROM last_insert), 300);

I hope this helps.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to