[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

In doubt with sqlite3-ruby

aurelianito

2/26/2006 3:48:00 PM

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);"

# 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.


Thank's in advance,
Aureliano.

5 Answers

Yuu

2/26/2006 4:14:00 PM

0

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-....


aurelianito

2/26/2006 6:03:00 PM

0

> > 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.

The method is last_insert_row_id (note the "_" between row and id).
Thank you very much for the tip (I didn't knew where look for it).

Aureliano.

Frauds Exposed

9/1/2009 12:41:00 PM

0


"Wayne" <mygarbagecan@verizon.net> wrote in message
news:h7kdip$mie$1@news.eternal-september.org...
>
> <Science@Science.com> wrote in message
> news:iddr951sk96gkpn09jmjlh9ghrh622u5c1@4ax.com...
>> On Tue, 1 Sep 2009 16:18:13 -0700, "Wayne"
>> <mygarbagecan@verizon.net> wrote:
>>
>>>Parents....get ready for your kids to come home selling the BHO party
>>>line
>>>on Sept. 8.
>>
>> David Dukes is more your orator, eh?
> -
> How about a cite on when DD gave a national day of televised lecturing to
> young kids about his views.

David Dukes has as much chance of a televised lecture as a turd.


Science

9/2/2009 3:03:00 PM

0

On Tue, 1 Sep 2009 17:17:25 -0700, "Wayne"
<mygarbagecan@verizon.net> wrote:

>
><Science@Science.com> wrote in message
>news:iddr951sk96gkpn09jmjlh9ghrh622u5c1@4ax.com...
>> On Tue, 1 Sep 2009 16:18:13 -0700, "Wayne"
>> <mygarbagecan@verizon.net> wrote:
>>
>>>Parents....get ready for your kids to come home selling the BHO party line
>>>on Sept. 8.
>>
>> David Dukes is more your orator, eh?
>-
>How about a cite on when DD gave a national day of televised lecturing to
>young kids about his views.
>

In which Red-necked white supremacist compound?

No Bammer

9/3/2009 3:01:00 PM

0

Wayne wrote:

> <Science@Science.com> wrote in message
> news:iddr951sk96gkpn09jmjlh9ghrh622u5c1@4ax.com...
>
>>On Tue, 1 Sep 2009 16:18:13 -0700, "Wayne"
>><mygarbagecan@verizon.net> wrote:
>>
>>
>>>Parents....get ready for your kids to come home selling the BHO party line
>>>on Sept. 8.
>>
>>David Dukes is more your orator, eh?
>
> -
> How about a cite on when DD gave a national day of televised lecturing to
> young kids about his views.
>
>

Yes, Obama is more nazi than David Dukes ever thought of.