Author: timbo
Date: Thu Apr 26 03:42:31 2007
New Revision: 9455

Modified:
   dbi/trunk/DBI.pm
   dbi/trunk/lib/DBD/ExampleP.pm
   dbi/trunk/t/10examp.t

Log:
Improve error message when 'dbi:driver:' is missing of malformed.
Add tests for connect_cached attribute resting


Modified: dbi/trunk/DBI.pm
==============================================================================
--- dbi/trunk/DBI.pm    (original)
+++ dbi/trunk/DBI.pm    Thu Apr 26 03:42:31 2007
@@ -573,8 +573,10 @@
 
     # Set $driver. Old style driver, if specified, overrides new dsn style.
     $driver = $old_driver || $1 || $ENV{DBI_DRIVER}
-       or Carp::croak("Can't connect to data source $dsn, no database driver 
specified "
-               ."and DBI_DSN env var not set");
+       or Carp::croak("Can't connect to data source '$dsn' "
+            ."because I can't work out what driver to use "
+            ."(it doesn't seem to contain a 'dbi:driver:' prefix "
+            ."and the DBI_DRIVER env var is not set)");
 
     my $proxy;
     if ($ENV{DBI_AUTOPROXY} && $driver ne 'Proxy' && $driver ne 'Sponge' && 
$driver ne 'Switch') {

Modified: dbi/trunk/lib/DBD/ExampleP.pm
==============================================================================
--- dbi/trunk/lib/DBD/ExampleP.pm       (original)
+++ dbi/trunk/lib/DBD/ExampleP.pm       Thu Apr 26 03:42:31 2007
@@ -96,7 +96,7 @@
                unless $statement =~ m/^\s*set\s+/;
            # the SET syntax is just a hack so the ExampleP driver can
            # be used to test non-select statements.
-           # No we have DBI::DBM etc ExampleP should be deprecated
+           # Now we have DBI::DBM etc., ExampleP should be deprecated
        }
 
        my ($outer, $sth) = DBI::_new_sth($dbh, {

Modified: dbi/trunk/t/10examp.t
==============================================================================
--- dbi/trunk/t/10examp.t       (original)
+++ dbi/trunk/t/10examp.t       Thu Apr 26 03:42:31 2007
@@ -72,19 +72,25 @@
        # This test checks that connect_cached works
        # and how it then relates to the CachedKids 
        # attribute for the driver.
-#DBI->trace(4);
-       my $dbh_cached_1 = DBI->connect_cached('dbi:ExampleP:', '', '', { 
TraceLevel=>0});
-       isa_ok($dbh_cached_1, "DBI::db");
 
-       my $dbh_cached_2 = DBI->connect_cached('dbi:ExampleP:', '', '', { 
TraceLevel=>0});
-       isa_ok($dbh_cached_2, "DBI::db");
+       ok my $dbh_cached_1 = DBI->connect_cached('dbi:ExampleP:', '', '', { 
TraceLevel=>0, Executed => 0 });
+
+       ok my $dbh_cached_2 = DBI->connect_cached('dbi:ExampleP:', '', '', { 
TraceLevel=>0, Executed => 0 });
 
-       my $dbh_cached_3 = DBI->connect_cached('dbi:ExampleP:', '', '', { 
examplep_foo => 1 });
-       isa_ok($dbh_cached_3, "DBI::db");
-       
        is($dbh_cached_1, $dbh_cached_2, '... these 2 handles are cached, so 
they are the same');
+
+       ok my $dbh_cached_3 = DBI->connect_cached('dbi:ExampleP:', '', '', { 
examplep_foo => 1 });
+       
        isnt($dbh_cached_3, $dbh_cached_2, '... this handle was created with 
different parameters, so it is not the same');
 
+        # check that cached_connect applies attributes to handles returned 
from the cache
+        # (The specific case of Executed is relevant to DBD::Gofer 
retry-on-error logic)
+        ok $dbh_cached_1->do("select * from ."); # set Executed flag
+        ok $dbh_cached_1->{Executed}, 'Executed should be true';
+       ok my $dbh_cached_4 = DBI->connect_cached('dbi:ExampleP:', '', '', { 
TraceLevel=>0, Executed => 0 });
+        is $dbh_cached_4, $dbh_cached_1, 'should return same handle';
+        ok !$dbh_cached_4->{Executed}, 'Executed should be false because reset 
by connect attributes';
+
        my $drh = $dbh->{Driver};
        isa_ok($drh, "DBI::dr");
        

Reply via email to