![]() |
|
No such thing as a small change | |
PerlMonks |
Re: DBI and primary keysby lachoy (Parson) |
on Mar 28, 2001 at 00:21 UTC ( #67620=note: print w/replies, xml ) | Need Help?? |
This really, really depends on the database you're using. MySQL uses AUTO_INCREMENT fields and DBD::mysql stores the value for the row just inserted in $dbh->{mysql_insertid}. Sybase and MS SQL Server use IDENTITY fields, which stores the value in your database connection session and you can retrieve the value using SELECT @@IDENTITY. Postgres uses a sequence to accomplish the same thing and you can either select the NEXTVAL from the sequence before you send the statement to the db and send the ID value or, if you use the SERIAL datatype you can SELECT CURRVAL( sequence-name ) and get the current sequence value. IIRC, Oracle uses sequences as well but I don't know the exact semantics. Or (plug plug) you can use SPOPS, which does this and a number of other things for you. Postgres support is in CVS and will be in the next version. Chris
In Section
Seekers of Perl Wisdom
|
|