Thanks. I'll fix it for the next release. Meanwhile try

        ... $attr ? sort %$attr : ();

Tim.

On Thu, May 31, 2001 at 04:17:09PM -0500, Mitch Helle-Morrissey wrote:
> I think there might be a bug with the connect_cached() method in DBI.  If
> the elements in the attributes hashref are in a different order, then it
> makes a new handle instead of returning the cached handle, even if they are
> the same values.  This presents a problem if you are generating the
> attributes hashref dynamically, not in the same way every time.  (And I
> don't think you can ever count on the order of things in a hash).
> 
> The code that I think is causing the problem is Line 876 in DBI.pm v 1.15:
> 
>       my $key = join "~", $dsn, $user||'', $auth||'', $attr ? %$attr : ();
> 
> I think it could be remedied by stringifying a sorted version of the hashref
> ($attr).  Here is some sample code (using Sybase) that illustrates the
> problem.  I think it should apply to other drivers though.  You might have
> to mess around with the order for a while before it works.
> 
> Mitch
> 
> ----------------------------------------------------
> #!/usr/local/bin/perl5 -w
> 
> use strict;
> use DBI;
> use Data::Dumper qw(Dumper);
> 
> my $c = 'dbi:Sybase:server=YOURSERVER';
> my $u = 'YOURUSERNAME';
> my $p = 'YOURPASSWORD';
> 
> my $a1 = {
>     Warn            => 1,
>     CompatMode      => 1,
>     InactiveDestroy => 1,
>     PrintError      => 1,
>     RaiseError      => 1,
>     ChopBlanks      => 1,
>     LongReadLen     => 1,
>     Taint           => 1,
>     syb_use_bin_0x  => 1,
> };
> 
> my $a2 = {
>     syb_use_bin_0x  => 1,
>     Warn            => 1,
>     CompatMode      => 1,
>     InactiveDestroy => 1,
>     PrintError      => 1,
>     RaiseError      => 1,
>     ChopBlanks      => 1,
>     LongReadLen     => 1,
>     Taint           => 1,
> };
> 
> # notice that $a1 and $a2 have exactly the same attributes (syb_use_bin_0x
> was just moved to the top)!
> 
> my $dbh  = DBI->connect_cached($c, $u, $p, $a1);
> my $dbh2 = DBI->connect_cached($c, $u, $p, $a2);
> 
> print "it was cached\n" if($dbh eq $dbh2);
> 

Reply via email to