From: Rafael Kitover Date: Sat, 3 Oct 2009 18:59:17 +0000 (+0000) Subject: Merge 'trunk' into 'sybase_support' X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7f52685f7d241ee38e33afed8b01d4a0b808f569;hp=763026c15bf2047020c261f430bd782bb5180850;p=dbsrgits%2FDBIx-Class-Historic.git Merge 'trunk' into 'sybase_support' r20835@hlagh (orig r7753): ribasushi | 2009-10-03 09:49:14 -0400 Test reorg (no changes) r20836@hlagh (orig r7754): ribasushi | 2009-10-03 09:55:25 -0400 Add failing tests for RT#50003 r20837@hlagh (orig r7755): caelum | 2009-10-03 10:09:45 -0400 fix on_connect_ with coderef connect_info --- diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 01adf7d..366b2ae 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -878,13 +878,14 @@ sub _determine_driver { my ($self) = @_; if ((not $self->_driver_determined) && (not $self->{_in_determine_driver})) { - my $started_unconnected = 0; + my $started_connected = 0; local $self->{_in_determine_driver} = 1; if (ref($self) eq __PACKAGE__) { my $driver; if ($self->_dbh) { # we are connected $driver = $self->_dbh->{Driver}{Name}; + $started_connected = 1; } else { # if connect_info is a CODEREF, we have no choice but to connect if (ref $self->_dbi_connect_info->[0] && @@ -896,7 +897,6 @@ sub _determine_driver { # try to use dsn to not require being connected, the driver may still # force a connection in _rebless to determine version ($driver) = $self->_dbi_connect_info->[0] =~ /dbi:([^:]+):/i; - $started_unconnected = 1; } } @@ -913,7 +913,7 @@ sub _determine_driver { $self->_init; # run driver-specific initializations $self->_run_connection_actions - if $started_unconnected && defined $self->_dbh; + if !$started_connected && defined $self->_dbh; } } diff --git a/t/storage/on_connect_call.t b/t/storage/on_connect_call.t index be5e746..12894ee 100644 --- a/t/storage/on_connect_call.t +++ b/t/storage/on_connect_call.t @@ -3,67 +3,95 @@ use warnings; no warnings qw/once redefine/; use lib qw(t/lib); +use DBI; use DBICTest; +use DBICTest::Schema; +use DBIx::Class::Storage::DBI; -use Test::More tests => 9; +# !!! do not replace this with done_testing - tests reside in the callbacks +# !!! number of calls is important +use Test::More tests => 15; +# !!! -use DBIx::Class::Storage::DBI; -my $schema = DBICTest->init_schema( - no_connect => 1, - no_deploy => 1, -); - -local *DBIx::Class::Storage::DBI::connect_call_foo = sub { - isa_ok $_[0], 'DBIx::Class::Storage::DBI', - 'got storage in connect_call method'; - is $_[1], 'bar', 'got param in connect_call method'; -}; - -local *DBIx::Class::Storage::DBI::disconnect_call_foo = sub { - isa_ok $_[0], 'DBIx::Class::Storage::DBI', - 'got storage in disconnect_call method'; -}; - -ok $schema->connection( - DBICTest->_database, - { - on_connect_call => [ - [ do_sql => 'create table test1 (id integer)' ], - [ do_sql => [ 'insert into test1 values (?)', {}, 1 ] ], - [ do_sql => sub { ['insert into test1 values (2)'] } ], - [ sub { $_[0]->dbh->do($_[1]) }, 'insert into test1 values (3)' ], - # this invokes $storage->connect_call_foo('bar') (above) - [ foo => 'bar' ], - ], - on_connect_do => 'insert into test1 values (4)', - on_disconnect_call => 'foo', - }, -), 'connection()'; - -is_deeply ( - $schema->storage->dbh->selectall_arrayref('select * from test1'), - [ [ 1 ], [ 2 ], [ 3 ], [ 4 ] ], - 'on_connect_call/do actions worked' -); - -local *DBIx::Class::Storage::DBI::connect_call_foo = sub { - isa_ok $_[0], 'DBIx::Class::Storage::DBI', - 'got storage in connect_call method'; -}; - -local *DBIx::Class::Storage::DBI::connect_call_bar = sub { - isa_ok $_[0], 'DBIx::Class::Storage::DBI', - 'got storage in connect_call method'; -}; - -$schema->storage->disconnect; - -ok $schema->connection( - DBICTest->_database, - { - # method list form - on_connect_call => [ 'foo', sub { ok 1, "coderef in list form" }, 'bar' ], - }, -), 'connection()'; - -$schema->storage->ensure_connected; +my $schema = DBICTest::Schema->clone; + +{ + *DBIx::Class::Storage::DBI::connect_call_foo = sub { + isa_ok $_[0], 'DBIx::Class::Storage::DBI', + 'got storage in connect_call method'; + is $_[1], 'bar', 'got param in connect_call method'; + }; + + *DBIx::Class::Storage::DBI::disconnect_call_foo = sub { + isa_ok $_[0], 'DBIx::Class::Storage::DBI', + 'got storage in disconnect_call method'; + }; + + ok $schema->connection( + DBICTest->_database, + { + on_connect_call => [ + [ do_sql => 'create table test1 (id integer)' ], + [ do_sql => [ 'insert into test1 values (?)', {}, 1 ] ], + [ do_sql => sub { ['insert into test1 values (2)'] } ], + [ sub { $_[0]->dbh->do($_[1]) }, 'insert into test1 values (3)' ], + # this invokes $storage->connect_call_foo('bar') (above) + [ foo => 'bar' ], + ], + on_connect_do => 'insert into test1 values (4)', + on_disconnect_call => 'foo', + }, + ), 'connection()'; + + ok (! $schema->storage->connected, 'start disconnected'); + + is_deeply ( + $schema->storage->dbh->selectall_arrayref('select * from test1'), + [ [ 1 ], [ 2 ], [ 3 ], [ 4 ] ], + 'on_connect_call/do actions worked' + ); + + $schema->storage->disconnect; +} + +{ + *DBIx::Class::Storage::DBI::connect_call_foo = sub { + isa_ok $_[0], 'DBIx::Class::Storage::DBI', + 'got storage in connect_call method'; + }; + + *DBIx::Class::Storage::DBI::connect_call_bar = sub { + isa_ok $_[0], 'DBIx::Class::Storage::DBI', + 'got storage in connect_call method'; + }; + + + ok $schema->connection( + DBICTest->_database, + { + # method list form + on_connect_call => [ 'foo', sub { ok 1, "coderef in list form" }, 'bar' ], + }, + ), 'connection()'; + + ok (! $schema->storage->connected, 'start disconnected'); + $schema->storage->ensure_connected; + $schema->storage->disconnect; # this should not fire any tests +} + +{ + ok $schema->connection( + sub { DBI->connect(DBICTest->_database) }, + { + # method list form + on_connect_call => [ sub { ok 1, "on_connect_call after DT parser" }, ], + on_disconnect_call => [ sub { ok 1, "on_disconnect_call after DT parser" }, ], + }, + ), 'connection()'; + + ok (! $schema->storage->connected, 'start disconnected'); + my $parser = $schema->storage->datetime_parser; + + $schema->storage->ensure_connected; + $schema->storage->disconnect; +}