Commit | Line | Data |
726c8f65 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | use Test::Exception; |
6 | use Scope::Guard (); |
7 | use Try::Tiny; |
8 | use lib qw(t/lib); |
9 | use DBICTest; |
10 | |
11 | my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MSACCESS_ODBC_${_}" } qw/DSN USER PASS/}; |
12 | my ($dsn2, $user2, $pass2) = @ENV{map { "DBICTEST_MSACCESS_ADO_${_}" } qw/DSN USER PASS/}; |
13 | |
14 | plan skip_all => <<'EOF' unless $dsn || $dsn2; |
15 | Set $ENV{DBICTEST_MSACCESS_ODBC_DSN} and/or $ENV{DBICTEST_MSACCESS_ADO_DSN} (and optionally _USER and _PASS) to run these tests.\nWarning: this test drops and creates the table 'track'. |
16 | EOF |
17 | |
18 | plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_dt') |
19 | unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_dt'); |
20 | |
21 | my @connect_info = ( |
22 | [ $dsn, $user || '', $pass || '' ], |
23 | [ $dsn2, $user2 || '', $pass2 || '' ], |
24 | ); |
25 | |
26 | my $schema; |
27 | |
28 | for my $connect_info (@connect_info) { |
29 | my ($dsn, $user, $pass) = @$connect_info; |
30 | |
31 | next unless $dsn; |
32 | |
33 | $schema = DBICTest::Schema->connect($dsn, $user, $pass, { |
34 | on_connect_call => 'datetime_setup', |
35 | quote_names => 1, |
36 | }); |
37 | |
38 | my $guard = Scope::Guard->new(\&cleanup); |
39 | |
40 | try { local $^W = 0; $schema->storage->dbh->do('DROP TABLE track') }; |
41 | $schema->storage->dbh->do(<<"SQL"); |
42 | CREATE TABLE track ( |
43 | trackid AUTOINCREMENT PRIMARY KEY, |
44 | cd INT, |
45 | [position] INT, |
46 | last_updated_at DATETIME |
47 | ) |
48 | SQL |
49 | |
50 | ok(my $dt = DateTime->new({ |
51 | year => 2004, |
52 | month => 8, |
53 | day => 21, |
54 | hour => 14, |
55 | minute => 36, |
56 | second => 48, |
57 | })); |
58 | |
59 | ok(my $row = $schema->resultset('Track')->create({ |
60 | last_updated_at => $dt, |
61 | cd => 1 |
62 | })); |
63 | ok($row = $schema->resultset('Track') |
64 | ->search({ trackid => $row->trackid }, { select => ['last_updated_at'] }) |
65 | ->first |
66 | ); |
67 | is($row->last_updated_at, $dt, "DATETIME roundtrip" ); |
68 | } |
69 | |
70 | done_testing; |
71 | |
72 | # clean up our mess |
73 | sub cleanup { |
74 | # have to reconnect to drop a table that's in use |
75 | if (my $storage = eval { $schema->storage }) { |
76 | local $^W = 0; |
77 | $storage->disconnect; |
78 | $storage->dbh->do('DROP TABLE track'); |
79 | } |
80 | } |