I use Class::DBI + DBD::mysql in mod_perl Apache::DBI enabled
environment. I've found

  SELECT LAST_INSERT_ID

would *sometimes* cause vizarre result in persistent connection. It
happens very rarely, but the phenomenon is gone away we stop-start the
httpd.

Here's a patch for Class::DBI that fix this problem (*1) (for
0.36). In evey installation of Class::DBI I've applied this patch, and
the problem above never happens with it.

It should be clever that Class/DBI.pm can be free from this
mysql-dependent hardcode into each subclasses (Strategy Pattern, or
DBIx::AnyDBD?).

*1) error message is as follows:

  Can't call method "call_hook" on an undefined value at /usr/local/lib/
  perl5/site_perl/5.005/Class/DBI.pm line 101.


--
Tatsuhiko Miyagawa <[EMAIL PROTECTED]>


--- DBI.pm~     Fri Nov  2 00:43:27 2001
+++ DBI.pm      Fri Mar  8 00:57:17 2002
@@ -125,10 +125,7 @@
     $sth->execute(values %$data);
     # If we still don't have a primary key, try AUTO_INCREMENT.
     unless( _safe_exists($data, $self->primary) ) {
-      $sth = $self->sql_LastInsertID;
-      $sth->execute;
-      $data->{$self->primary} = ($sth->fetch)[0];
-      $sth->finish;
+      $data->{$self->primary} = $class->db_Main->{mysql_insertid};
     }
   };
   if($@) {

Reply via email to