$dbh->last_insert_id() not working

$dbh->last_insert_id() not working

am 16.06.2004 01:10:43 von Daniel Kasak

------------=_1087341213-29926-200
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hi all.

I'm writing a helper object to synchronise data in DB server with fields
on a glade-generated form.
Part of that involves handling inserts:

eval {
$sth->execute (@bind_values) || die $dbh->errstr;
};

# If the above failed, there will be something in the special
variable $@
if ($@) {

# Dialog explaining error...
my $dialog = &msgbox(
$prospects->get_widget("Prospects"),
"Error updating recordset!",
"Database Server says:\n" . $dbh->errstr,
1
);
$dialog->run;
$dialog->destroy;
warn "Error updating recordset:\n$sql\n@bind_values\n" . $@ .
"\n\n";
return 0;

}

$pk = $dbh->last_insert_id();

When the above code runs, a record is inserted correctly - perfectly in
fact. The 'insert into' statement appears immediately in the MySQL query
log.
The problem is that the last line doesn't get a value - $pk is undef.

I haven't yet tried doing a 'select last_insert_id()' or 'select
@@identity' because I'm trying to keep the code as portable as possible
- so it can be used with other DB servers, and the obvious way of doing
this is by letting DBI take care of the details ( if it worked ).

Anyone know what's up?

Dan

--
Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
email: dkasak@nusconsulting.com.au
website: http://www.nusconsulting.com.au


------------=_1087341213-29926-200
Content-Type: text/plain; charset=us-ascii

--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org
------------=_1087341213-29926-200--