"martin linklater"
<[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hi. I'm real new to SQLite via the command line, but I have used
> CoreData quite a bit on OSX. My problem is that I have two tables
> that I want to link via a unique ID, but I don' t know how to
> automatically link the ID parameter properly. My tables look like
> this:
>
> create table snapshot( id INTEGER PRIMARY KEY, bumf TEXT );
> create table sample( snapshotid INTEGER, type TEXT, used INTEGER );
>
> Now when I insert an entry into the snapshot with:
>
> insert into snapshot (bumf) values ('one');
>
> I want to insert a number of entries into the 'sample' table and make
> sure their 'snapshotid' value is set to the one just created in the
> previous 'insert into snapshot...' command.
>
> I know that this stuff is possible because CoreData does this sort of
> thing but hides it behind a nice API. How do I create such a
> relationship with sqlite via the command line ?

You can't make this happen automatically with SQLite. After you insert a 
record into snapshot table, retrieve the generated ID with

select last_insert_rowid();

(in your own program, use sqlite3_last_insert_rowid API) then specify 
this ID when inserting into sample.

Igor Tandetnik 



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

Reply via email to