Remove use of Try::Tiny entirely (the missing part of ddcc02d1)
[dbsrgits/DBIx-Class.git] / t / icdt / engine_specific / msaccess.t
1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2 use DBIx::Class::Optional::Dependencies -skip_all_without => qw( ic_dt _rdbms_msaccess_common );
3
4 use strict;
5 use warnings;
6
7 use Test::More;
8 use DBIx::Class::_Util 'scope_guard';
9
10 use DBICTest;
11
12 my @tdeps = qw( test_rdbms_msaccess_odbc test_rdbms_msaccess_ado );
13 plan skip_all => 'Test needs  ' . (join '  OR  ', map
14   { "[ @{[ DBIx::Class::Optional::Dependencies->req_missing_for( $_ ) ]} ]" }
15   @tdeps
16 ) unless scalar grep
17   { DBIx::Class::Optional::Dependencies->req_ok_for( $_ ) }
18   @tdeps
19 ;
20
21 my ($dsn,  $user,  $pass)  = @ENV{map { "DBICTEST_MSACCESS_ODBC_${_}" } qw/DSN USER PASS/};
22 my ($dsn2, $user2, $pass2) = @ENV{map { "DBICTEST_MSACCESS_ADO_${_}" }  qw/DSN USER PASS/};
23
24 my @connect_info = (
25   [ $dsn,  $user  || '', $pass  || '' ],
26   [ $dsn2, $user2 || '', $pass2 || '' ],
27 );
28
29 for my $connect_info (@connect_info) {
30   my ($dsn, $user, $pass) = @$connect_info;
31
32   next unless $dsn;
33
34   my $schema = DBICTest::Schema->connect($dsn, $user, $pass, {
35     on_connect_call => 'datetime_setup',
36     quote_names => 1,
37   });
38
39   my $guard = scope_guard { cleanup($schema) };
40
41   eval { local $^W = 0; $schema->storage->dbh->do('DROP TABLE track') };
42   $schema->storage->dbh->do(<<"SQL");
43 CREATE TABLE track (
44   trackid AUTOINCREMENT PRIMARY KEY,
45   cd INT,
46   [position] INT,
47   last_updated_at DATETIME
48 )
49 SQL
50
51   ok(my $dt = DateTime->new({
52     year => 2004,
53     month => 8,
54     day => 21,
55     hour => 14,
56     minute => 36,
57     second => 48,
58   }));
59
60   ok(my $row = $schema->resultset('Track')->create({
61     last_updated_at => $dt,
62     cd => 1
63   }));
64   ok($row = $schema->resultset('Track')
65     ->search({ trackid => $row->trackid }, { select => ['last_updated_at'] })
66     ->first
67   );
68   is($row->last_updated_at, $dt, "DATETIME roundtrip" );
69 }
70
71 done_testing;
72
73 # clean up our mess
74 sub cleanup {
75   my $schema = shift;
76   # have to reconnect to drop a table that's in use
77   if (my $storage = eval { $schema->storage }) {
78     local $^W = 0;
79     $storage->disconnect;
80     $storage->dbh->do('DROP TABLE track');
81   }
82 }