X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F751msaccess.t;h=479124aa837764585e1815a056bcd5123eed67b1;hb=67f5d3f20045f28bf551e1fd9fd315dd2041d596;hp=62012ac967c1a6a9047a8024d4dddd1600e7bf57;hpb=076bd5998f46f64ea0abc2d5246695f40bacda8b;p=dbsrgits%2FDBIx-Class.git diff --git a/t/751msaccess.t b/t/751msaccess.t index 62012ac..479124a 100644 --- a/t/751msaccess.t +++ b/t/751msaccess.t @@ -1,13 +1,30 @@ +BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) } + use strict; use warnings; use Test::More; use Test::Exception; -use Scope::Guard (); use Try::Tiny; -use lib qw(t/lib); +use DBIx::Class::Optional::Dependencies (); +use DBIx::Class::_Util 'scope_guard'; + use DBICTest; +my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MSACCESS_ODBC_${_}" } qw/DSN USER PASS/}; +my ($dsn2, $user2, $pass2) = @ENV{map { "DBICTEST_MSACCESS_ADO_${_}" } qw/DSN USER PASS/}; + +plan skip_all => 'Test needs ' . + (join ' or ', map { $_ ? $_ : () } + DBIx::Class::Optional::Dependencies->req_missing_for('test_rdbms_msaccess_odbc'), + DBIx::Class::Optional::Dependencies->req_missing_for('test_rdbms_msaccess_ado')) + unless + $dsn && DBIx::Class::Optional::Dependencies->req_ok_for('test_rdbms_msaccess_odbc') + or + $dsn2 && DBIx::Class::Optional::Dependencies->req_ok_for('test_rdbms_msaccess_ado') + or + (not $dsn || $dsn2); + DBICTest::Schema->load_classes('ArtistGUID'); # Example DSNs (32bit only): @@ -15,37 +32,23 @@ DBICTest::Schema->load_classes('ArtistGUID'); # dbi:ADO:Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\rkitover\Documents\access_sample.accdb # dbi:ADO:Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\rkitover\Documents\access_sample.accdb;Persist Security Info=False' -my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MSACCESS_ODBC_${_}" } qw/DSN USER PASS/}; -my ($dsn2, $user2, $pass2) = @ENV{map { "DBICTEST_MSACCESS_ADO_${_}" } qw/DSN USER PASS/}; - plan skip_all => <<'EOF' unless $dsn || $dsn2; Set $ENV{DBICTEST_MSACCESS_ODBC_DSN} and/or $ENV{DBICTEST_MSACCESS_ADO_DSN} (and optionally _USER and _PASS) to run these tests. Warning: this test drops and creates the tables 'artist', 'cd', 'bindtype_test' and 'artist_guid'. EOF -plan skip_all => 'Test needs ' . -DBIx::Class::Optional::Dependencies->req_missing_for('test_rdbms_msaccess_odbc') -. ' or ' . -DBIx::Class::Optional::Dependencies->req_missing_for('test_rdbms_msaccess_ado') - unless - DBIx::Class::Optional::Dependencies->req_ok_for('test_rdbms_msaccess_odbc') - or - DBIx::Class::Optional::Dependencies->req_ok_for('test_rdbms_msaccess_ado'); - my @info = ( [ $dsn, $user || '', $pass || '' ], [ $dsn2, $user2 || '', $pass2 || '' ], ); -my $schema; - foreach my $info (@info) { my ($dsn, $user, $pass) = @$info; next unless $dsn; # Check that we can connect without any options. - $schema = DBICTest::Schema->connect($dsn, $user, $pass); + my $schema = DBICTest::Schema->connect($dsn, $user, $pass); lives_ok { $schema->storage->ensure_connected; } 'connection without any options'; @@ -61,7 +64,7 @@ foreach my $info (@info) { LongReadLen => $maxloblen, }); - my $guard = Scope::Guard->new(\&cleanup); + my $guard = scope_guard { cleanup($schema) }; my $dbh = $schema->storage->dbh; @@ -151,11 +154,27 @@ EOF })->next; } catch { - diag "Could not execute two-step join: $_"; + diag "Could not execute two-step left join: $_"; }; is try { $joined_track->get_column('track_title') }, 'my track', - 'two-step join works'; + 'two-step left join works'; + + $joined_artist = try { + $schema->resultset('Track')->search({ + trackid => $track->trackid, + }, { + join => [{ cd => 'artist' }], + '+select' => [ 'artist.name' ], + '+as' => [ 'artist_name' ], + })->next; + } + catch { + diag "Could not execute two-step inner join: $_"; + }; + + is try { $joined_artist->get_column('artist_name') }, 'foo', + 'two-step inner join works'; # test basic transactions $schema->txn_do(sub { @@ -391,6 +410,8 @@ SQL done_testing; sub cleanup { + my $schema = shift; + if (my $storage = eval { $schema->storage }) { # cannot drop a table if it has been used, have to reconnect first $schema->storage->disconnect;