From: "E. Saynatkari" Date: 2006-02-27T01:14:10+09:00 Subject: Re: In doubt with sqlite3-ruby aurelianito wrote: > Hi! > I have a table with an AUTOINCREMENT primary key and I would like to > know how to retrieve this primary key when a new row is inserted. Is it > possible? > > Below, I written some sample ruby code for you to see my problem. > > require 'sqlite3' > db = SQLite3::Database.new( "test.db" ) > db.execute "create table if not exists t1(id integer PRIMARY KEY > AUTOINCREMENT, v1, v2);" Just INTEGER PRIMARY KEY should be enough. > # some code, skipped, may include inserts to t1 > > db.execute "insert into t1 (v1,v2) values (1,2)" # don't know the > primary key assigned. > db.execute "insert into t1 (v1,v2) values (3,4)" # don't know the > primary key assigned. The method is called last_insert_rowid, I think, check the API docs to verify. > Thank's in advance, > Aureliano. E -- Posted via http://www.ruby-forum.com/.