Better exception when things get really really bad with prepare()
Peter Rabbitson [Mon, 31 Jan 2011 16:00:46 +0000 (17:00 +0100)]
Changes
lib/DBIx/Class/Storage/DBI.pm

diff --git a/Changes b/Changes
index a1d6ac5..ddeda06 100644 (file)
--- a/Changes
+++ b/Changes
@@ -11,6 +11,7 @@ Revision history for DBIx::Class
         - Fix dropped bind values in select/group_by on Oracle (omission
           from 0542ec57 and 4c2b30d6)
         - Fix problems with M.A.D. under CGI::SpeedyCGI (RT#65131)
+        - Better error handling when prepare() fails silently
 
 0.08127 2011-01-19 16:40 (UTC)
     * New Features / Changes
index 7d7a8bb..dfa2e1e 100644 (file)
@@ -2280,7 +2280,18 @@ sub _dbh_sth {
 
   # XXX You would think RaiseError would make this impossible,
   #  but apparently that's not true :(
-  $self->throw_exception($dbh->errstr) if !$sth;
+  $self->throw_exception(
+    $dbh->errstr
+      ||
+    sprintf( "\$dbh->prepare() of '%s' through %s failed *silently* without "
+            .'an exception and/or setting $dbh->errstr',
+      length ($sql) > 20
+        ? substr($sql, 0, 20) . '...'
+        : $sql
+      ,
+      'DBD::' . $dbh->{Driver}{Name},
+    )
+  ) if !$sth;
 
   $sth;
 }