RE: DBI and last_insert_id()
You wrote $pk = $dbh-last_insert_id(); I believe you can get the created ID with the query, Select @@IDENTITY; This returns the last created ID from the connector object. Peace -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
RE: DBI and last_insert_id()
last_insert_id() should work. You are updating using @bind_values. What is the text of that? Does it indeed create a record? God Bless Paul C. McNeil Developer in Java, MS-SQL, MySQL, and web technologies. GOD BLESS AMERICA! To God Be The Glory! -Original Message- From: Daniel Kasak [mailto:[EMAIL PROTECTED] Sent: Tuesday, June 15, 2004 12:42 AM To: [EMAIL PROTECTED] Subject: DBI and last_insert_id() Hi all. I'm writing an app in Perl / Gtk2, and I'm having trouble with DBI's last_insert_id() function. I have so far: 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:[EMAIL PROTECTED] . $@ . \n\n; return 0; } $pk = $dbh-last_insert_id(); The statement executes successfully, and the data is inserted. However the above line that fetches the last_insert_id value from MySQL always returns undef. The table has an auto_increment column. What's going on? 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: [EMAIL PROTECTED] website: http://www.nusconsulting.com.au -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: DBI and last_insert_id()
Paul McNeil wrote: last_insert_id() should work. You are updating using @bind_values. What is the text of that? Does it indeed create a record? @bind_values is an array of values that gets populated from my form. It has the same number of elements as the number of placeholders in my SQL, and yes, the record is created, and I see the 'insert into' statement appear immediately in the query log. Perl's DBI is supposed to then allow me to use the 'last_insert_id()' function of the database handle: my $inserted_id = $dbh-last_insert_id(); to get the value into $inserted_id. But it doesn't work. I haven't yet tried doing a 'select last_insert_id()' or 'select @@identity' statement, but I suppose I can fall back to that. I was just wondering if I was doing something wrong, but the more I look at it ( and it's a pretty simple script ) the more I think there's something up with DBI. -- 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: [EMAIL PROTECTED] website: http://www.nusconsulting.com.au -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: DBI and last_insert_id()
You might have better luck with this on the [EMAIL PROTECTED] list, re: why this doesn't work. This works for me though: $pk = $dbh-{mysql_insertid}; On Mon, 2004-06-14 at 21:42, Daniel Kasak wrote: Hi all. I'm writing an app in Perl / Gtk2, and I'm having trouble with DBI's last_insert_id() function. I have so far: 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:[EMAIL PROTECTED] . $@ . \n\n; return 0; } $pk = $dbh-last_insert_id(); The statement executes successfully, and the data is inserted. However the above line that fetches the last_insert_id value from MySQL always returns undef. The table has an auto_increment column. What's going on? Dan -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: DBI and last_insert_id()
Garth Webb said: You might have better luck with this on the [EMAIL PROTECTED] list, re: why this doesn't work. This works for me though: $pk = $dbh-{mysql_insertid}; On Mon, 2004-06-14 at 21:42, Daniel Kasak wrote: Hi all. I'm writing an app in Perl / Gtk2, and I'm having trouble with DBI's last_insert_id() function. I have so far: 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:[EMAIL PROTECTED] . $@ . \n\n; return 0; } $pk = $dbh-last_insert_id(); The statement executes successfully, and the data is inserted. However the above line that fetches the last_insert_id value from MySQL always returns undef. The table has an auto_increment column. What's going on? Dan ($pk) = $dbh-selectrow_array('SELECT LAST_INSERT_ID()'); BTW this also works in java. -- William R. Mussatto, Senior Systems Engineer Ph. 909-920-9154 ext. 27 FAX. 909-608-7061 -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
DBI and last_insert_id()
Hi all. I'm writing an app in Perl / Gtk2, and I'm having trouble with DBI's last_insert_id() function. I have so far: 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:[EMAIL PROTECTED] . $@ . \n\n; return 0; } $pk = $dbh-last_insert_id(); The statement executes successfully, and the data is inserted. However the above line that fetches the last_insert_id value from MySQL always returns undef. The table has an auto_increment column. What's going on? 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: [EMAIL PROTECTED] website: http://www.nusconsulting.com.au -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]