On Tue, May 22, 2007 at 07:04:27PM -0700, Bill Moseley wrote:
> Does connect_cached() reset attributes each time it's called?  Even if
> just returning an active $dbh?

Yes. You're asking for a handle with specific attributes set, so that's
what it gives you.

> On a CDBI application I need to access multiple databases with the
> same schema.  So my initial attempt was:
> 
>     sub db_Main {
>         my $self = shift;
>         my $connection = $database_registry{$current_database};
>         my %attr = (
>             $self->_default_attributes,
>             %{ $connection->{attr} },
>             AutoCommit     => 1,
>             pg_enable_utf8 => 1,
>             private_pid    => $$,
>         );
>         return DBI->connect_cached( @{$connection}{qw/ dsn user pass /}, 
> \%attr );
>     }
> 
> If I localize AutoCommit (for a transaction) I see this:
>  T  <- STORE('AutoCommit' undef)= 1 at test_model.pl line 27
> but next time db_Main is called I see:
>  T  <- STORE('AutoCommit' 1)= 1 at DBI.pm line 672
> 
> Which looks like attributes are reset when connect_cached is called.

Yeap. They're set to the values you're asking for.

> I guess that's why Ima::DBI doesn't call connect_cached() unless ping fails.

Possibly. May also just have been an optimization.

Tim.

Reply via email to