Peter Karman wrote on 10/27/07 11:53 AM:
> 
> Peter Karman wrote on 10/27/07 11:48 AM:
>> In particular, I don't
>> see a way to clear the DBI cache (could be there but I didn't notice it in 
>> the
>> docs).
>>
> 
> I obviously stopped reading before I got to the CachedKids feature...
> 
> So the ability to clear the dbh cache is available as well.
> 

attached is a revised patch that documents the CachedKids feature and respects
the DBI API's 'private_' key prefix.

-- 
Peter Karman  .  http://peknet.com/  .  [EMAIL PROTECTED]
Index: t/dbh_cache.t
===================================================================
--- t/dbh_cache.t       (revision 0)
+++ t/dbh_cache.t       (revision 0)
@@ -0,0 +1,40 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+BEGIN {
+    require Test::More;
+    eval { require DBD::SQLite };
+
+    if ( $@ || $DBD::SQLite::VERSION < 1.08 || $ENV{'RDBO_NO_SQLITE'} ) {
+        Test::More->import(
+            skip_all => $ENV{'RDBO_NO_SQLITE'}
+            ? 'SQLite tests disabled'
+            : 'Missing DBD::SQLite 1.08+'
+        );
+    }
+    elsif ( $DBD::SQLite::VERSION == 1.13 )
+    {
+        Test::More->import( skip_all => 'DBD::SQLite 1.13 is broken' );
+    }
+    else {
+        Test::More->import( tests => 5 );
+    }
+}
+
+BEGIN {
+    require 't/test-lib.pl';
+    use_ok('Rose::DB');
+}
+
+Rose::DB->default_domain('test');
+Rose::DB->default_type('sqlite_admin');
+
+ok( my $db = Rose::DB->new_or_cached(), "new_or_cached db" );
+
+ok( ref $db && $db->isa('Rose::DB'), 'new()' );
+
+ok( my $db2 = Rose::DB->new_or_cached(), "new_or_cached db2" );
+
+is( $db->dbh, $db2->dbh, "same DBI handle used" );
+
Index: lib/Rose/DB.pm
===================================================================
--- lib/Rose/DB.pm      (revision 1470)
+++ lib/Rose/DB.pm      (working copy)
@@ -366,6 +366,14 @@
   return $self;
 }
 
+sub new_or_cached 
+{
+  my $self = shift;
+  my $db = $self->new(@_);
+  $db->{'cached_dbh'} = 1;
+  return $db;
+}
+
 sub class 
 {
   my($self) = shift;
@@ -820,13 +828,20 @@
   my $options = $self->connect_options;
 
   my $dsn = $self->dsn;
+  
+  my $method = $self->{'cached_dbh'} ? 'connect_cached' : 'connect';
 
-  $Debug && warn "DBI->connect('$dsn', '", $self->username, "', ...)\n";
+  $Debug && warn "DBI->$method('$dsn', '", $self->username, "', ...)\n";
 
   $self->{'error'} = undef;
   $self->{'database_version'} = undef;
 
-  my $dbh = DBI->connect($dsn, $self->username, $self->password, $options);
+  my $dbh = DBI->$method($dsn, $self->username, $self->password, 
+                         { %$options, 
+                           private_rdb_type => $self->type, 
+                           private_rdb_domain => $self->domain 
+                         }
+                        );
 
   unless($dbh)
   {
@@ -2759,6 +2774,13 @@
 
 You can change this mapping with the L<driver_class|/driver_class> class 
method.
 
+=item <new_or_cached PARAMS>
+
+Acts just like new() except that the DBI connect_cached() method will be used 
instead
+of connect().
+
+See the DBI CachedKids feature for ways to access the cache directly and to 
clear it.
+
 =back
 
 =head1 OBJECT METHODS
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object

Reply via email to