From: Peter Rabbitson Date: Tue, 29 Jan 2013 10:57:49 +0000 (+0100) Subject: Extra sanity check of a fresh DBI handle X-Git-Tag: v0.08206~10 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8c21eef750db35dbc8f363ffa7218ef71073d656;p=dbsrgits%2FDBIx-Class.git Extra sanity check of a fresh DBI handle --- diff --git a/Changes b/Changes index 94974b1..80fc232 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ Revision history for DBIx::Class + * Fixes + - Extra sanity check of a fresh DBI handle ($dbh). Fixes + connection coderefs returning garbage (seen in the wild) + * Misc - Only allow known globals in SQL::Translator leak allowance diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 4141a15..d46522b 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -1399,10 +1399,17 @@ sub _connect { $dbh = DBI->connect(@info); } - if (!$dbh) { - die $DBI::errstr; - } + die $DBI::errstr unless $dbh; + + die sprintf ("%s fresh DBI handle with a *false* 'Active' attribute. " + . 'This handle is disconnected as far as DBIC is concerned, and we can ' + . 'not continue', + ref $info[0] eq 'CODE' + ? "Connection coderef $info[0] returned a" + : 'DBI->connect($schema->storage->connect_info) resulted in a' + ) unless $dbh->FETCH('Active'); + # sanity checks unless asked otherwise unless ($self->unsafe) { $self->throw_exception(