7 messages in com.mysql.lists.perl$dbh->last_insert_id() not working| From | Sent On | Attachments |
|---|---|---|
| Daniel Kasak | 15 Jun 2004 16:10 | |
| William R. Mussatto | 15 Jun 2004 16:21 | |
| Daniel Kasak | 15 Jun 2004 16:39 | |
| William R. Mussatto | 15 Jun 2004 17:02 | |
| Jochen Wiedmann | 15 Jun 2004 23:40 | |
| Daniel Kasak | 16 Jun 2004 15:20 | |
| lei shen | 17 Jun 2004 07:44 |
| Subject: | $dbh->last_insert_id() not working![]() |
|---|---|
| From: | Daniel Kasak (dka...@nusconsulting.com.au) |
| Date: | 06/15/2004 04:10:21 PM |
| List: | com.mysql.lists.perl |
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: dka...@nusconsulting.com.au website: http://www.nusconsulting.com.au




