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