Changeset 149
- Timestamp:
- 02/05/09 22:17:07 (10 months ago)
- Location:
- branches/use-existing-dbh
- Files:
-
- 2 modified
-
lib/TheSchwartz.pm (modified) (2 diffs)
-
t/lib/db-common.pl (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/use-existing-dbh/lib/TheSchwartz.pm
r148 r149 61 61 my($list) = @_; 62 62 for my $ref (@$list) { 63 my $full = ($ref->{d bh}) ? rand().time().{}.$$ : join '|', map { $ref->{$_} || '' } qw( dsn user pass );63 my $full = ($ref->{driver}) ? rand().time().{}.$$ : join '|', map { $ref->{$_} || '' } qw( dsn user pass ); 64 64 $client->{databases}{ md5_hex($full) } = $ref; 65 65 } … … 77 77 my $db = $client->{databases}{$hashdsn} 78 78 or croak "Ouch, I don't know about a database whose hash is $hashdsn"; 79 my %p = ($db->{dbh}) ?80 ( dbd => $db->{dbh} ) :81 (82 dsn => $db->{dsn},83 username => $db->{user},84 password => $db->{pass},85 );86 $driver = Data::ObjectDriver::Driver::DBI->new(87 %p,88 ($db->{prefix} ? (prefix => $db->{prefix}) : ()),89 ); 79 if ($db->{driver}) { 80 $driver = $db->{driver}; 81 } else { 82 $driver = Data::ObjectDriver::Driver::DBI->new( 83 dsn => $db->{dsn}, 84 username => $db->{user}, 85 password => $db->{pass}, 86 ); 87 } 88 $driver->prefix(($db->{prefix} ? (prefix => $db->{prefix}) : ())); 89 90 90 if ($cache_duration) { 91 91 $client->{cached_drivers}{$hashdsn}{driver} = $driver; -
branches/use-existing-dbh/t/lib/db-common.pl
r91 r149 53 53 } 54 54 55 return TheSchwartz->new(databases => [ 55 if ($ENV{USE_DBH_FOR_TEST}) { 56 my @tmp; 57 for (@$dbs) { 58 my $dsn = dsn_for($_); 59 my $dbh = DBI->connect( $dsn, "root", "" ) or die $DBI::errstr; 60 my $driver = Data::ObjectDriver::Driver::DBI->new( dbh => $dbh); 61 push @tmp, { driver => $driver, prefix => $pfx }; 62 } 63 return TheSchwartz->new(databases => [@tmp]); 64 } else { 65 return TheSchwartz->new(databases => [ 56 66 map { { 57 67 dsn => dsn_for($_), … … 61 71 } } @$dbs 62 72 ]); 73 } 63 74 } 64 75
