+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 DBIx::Class::Optional::Dependencies ();
-use lib qw(t/lib);
+use DBIx::Class::_Util 'scope_guard';
+
use DBICTest;
-use DBIC::DebugObj ();
-use DBIC::SqlMakerTest;
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/};
[ $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';
LongReadLen => $maxloblen,
});
- my $guard = Scope::Guard->new(\&cleanup);
+ my $guard = scope_guard { cleanup($schema) };
my $dbh = $schema->storage->dbh;
title => 'my track',
});
- my ($sql, @bind);
-
- my $joined_track = try {
- local $schema->storage->{debug} = 1;
- local $schema->storage->{debugobj} = DBIC::DebugObj->new(\$sql, \@bind);
-
- $schema->resultset('Artist')->search({
+ my $joined_track;
+ lives_ok {
+ $joined_track = $schema->resultset('Artist')->search({
artistid => $first_artistid,
}, {
join => [{ cds => 'tracks' }],
'+select' => [ 'tracks.title' ],
'+as' => [ 'track_title' ],
})->next;
- }
- catch {
- diag "Could not execute two-step left join: $_";
- };
-
- s/^'//, s/'\z// for @bind;
-
- is_same_sql_bind(
- $sql,
- \@bind,
- 'SELECT [me].[artistid], [me].[name], [me].[rank], [me].[charfield], [tracks].[title] FROM ( ( [artist] [me] LEFT JOIN cd [cds] ON [cds].[artist] = [me].[artistid] ) LEFT JOIN [track] [tracks] ON [tracks].[cd] = [cds].[cdid] ) WHERE ( [artistid] = ? )',
- [1],
- 'correct SQL for two-step left join',
- );
+ } 'Two-step left join executed';
- is try { $joined_track->get_column('track_title') }, 'my track',
- 'two-step left join works';
-
- ($sql, @bind) = ();
-
- $joined_artist = try {
- local $schema->storage->{debug} = 1;
- local $schema->storage->{debugobj} = DBIC::DebugObj->new(\$sql, \@bind);
+ is(
+ eval { $joined_track->get_column('track_title') },
+ 'my track',
+ 'two-step left join works'
+ );
- $schema->resultset('Track')->search({
+ lives_ok {
+ $joined_artist = $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: $_";
- };
-
- s/^'//, s/'\z// for @bind;
-
- is_same_sql_bind(
- $sql,
- \@bind,
- 'SELECT [me].[trackid], [me].[cd], [me].[position], [me].[title], [me].[last_updated_on], [me].[last_updated_at], [artist].[name] FROM ( ( [track] [me] INNER JOIN cd [cd] ON [cd].[cdid] = [me].[cd] ) INNER JOIN [artist] [artist] ON [artist].[artistid] = [cd].[artist] ) WHERE ( [trackid] = ? )',
- [$track->trackid],
- 'correct SQL for two-step inner join',
- );
+ } 'Two-step inner join executed';
- is try { $joined_artist->get_column('artist_name') }, 'foo',
- 'two-step inner join works';
+ is(
+ eval { $joined_artist->get_column('artist_name') },
+ 'foo',
+ 'two-step inner join works'
+ );
# test basic transactions
$schema->txn_do(sub {
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;