$dbh->last_insert_id() not working

------------=_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 ( [at] bind_values) || die $dbh->errstr;
};

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

# 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 [at] bind_values\n" . $ [at] .
"\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
[at] [at] 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 [at] 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 [at] m .gmane.org
------------=_1087341213-29926-200--
Daniel Kasak [ Mi, 16 Juni 2004 01:10 ] [ ID #180683 ]
Datenbanken » gmane.comp.db.mysql.perl » $dbh->last_insert_id() not working

Vorheriges Thema: DBD::mysql tests failing: symb unresolved: net_buffer_length
Nächstes Thema: Query - Value