Re: last insert id
- From: dan@xxxxxxxxxxxxxxxxxxxxx (Daniel Kasak)
- Date: Thu, 27 Apr 2006 12:04:08 +1000
Ron Savage wrote:
On Sun, 16 Apr 2006 22:15:22 +1000, Daniel Kasak wrote:
Hi Daniel
DBI: V 1.47
DBD::mysql: V 3.002
There are critical bugs in the $dbh->column_info() method in DBD::mysql-3.x that prevent us from upgrading :(
I've tried a line identical to your:
$id = $self -> dbh() -> last_insert_id(undef, undef, $table_name, undef);and I didn't get anything useful from it. Ah well. 'select @@IDENTITY' works well for me, and appears to be the most compatible way of doing things.
Is last_insert_id() supposed to work in versions prior to 3.x? I know it's only a relatively recent addition. That means that the code below requires more checks on the version of DBD::mysql to see if last_insert_id() is supported ( and working ).
sub last_insert_id.
{
my($self, $table_name) = @_;
my($id);
if ($self -> db_vendor() =~ /(?:mysql|Pg)/)
{
$id = $self -> dbh() -> last_insert_id(undef, undef, $table_name, undef);
}
else # Oracle.
{
my($sth) = $self -> dbh() -> prepare("select ${table_name}_id_seq.currval from dual");
$sth -> execute();
$id = ${$sth -> fetch()}[0];
$sth -> finish();
}
return $id;
} # End of last_insert_id.
- References:
- Re: last insert id
- From: Ron Savage
- Re: last insert id
- Prev by Date: Re: how to set a DEFAULT value !!
- Next by Date: Re: how to set a DEFAULT value !!
- Previous by thread: Re: last insert id
- Next by thread: Re: last insert id
- Index(es):
Relevant Pages
|