From: Sean Chittenden Date: 2002-02-06T02:49:15+09:00 Subject: Re: some dbi questions (probably postres specific) > I'm playing around with dbi and postgres. After a while two problems > remained that I couldn't solve so far. > > 1. after doing a DBI::DatabaseHandle.select_all I get an array > containing the result. In php I could also get the field names for > the result. ( using pg_fieldname($result, $index)) Is there > something similar in ruby's dbi? Eh... I'd avoid these, but that's just may reaction as a long time DBI user. The extra select to the system catalogs is a "bad thing" in my opinion. > 2. another problem arose when I tried wrapping objects around tables. I > created a table with the following structure: > Column| Type | Modifiers > -------+---------+------------------------------------------------------ > id | integer | not null default nextval('"test_table_id_seq"'::text) > name | text | > phone | text | > > now I insert some data into the table with the following code: > aConnection.execute "insert into test_table (name, phone) values > ('foo', '42');" id = dbh.select_one("SELECT currval('test_table_id_seq')")[0] This is what all DBI's do under the hood. After an insert into a table with an incrementing sequence, the connection will honnor curval(seq_name) which will return the value of the increment after the insert into the row. Just make sure that your user has read access to the sequence. -sc -- Sean Chittenden