Open the logfile in append mode
[dbsrgits/DBIx-Class.git] / t / inflate / datetime_msaccess.t
CommitLineData
726c8f65 1use strict;
2use warnings;
3
4use Test::More;
5use Test::Exception;
6use Scope::Guard ();
7use Try::Tiny;
8use lib qw(t/lib);
9use DBICTest;
10
11my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MSACCESS_ODBC_${_}" } qw/DSN USER PASS/};
12my ($dsn2, $user2, $pass2) = @ENV{map { "DBICTEST_MSACCESS_ADO_${_}" } qw/DSN USER PASS/};
13
14plan skip_all => <<'EOF' unless $dsn || $dsn2;
076bd599 15Set $ENV{DBICTEST_MSACCESS_ODBC_DSN} and/or $ENV{DBICTEST_MSACCESS_ADO_DSN} (and optionally _USER and _PASS) to run these tests.
16Warning: this test drops and creates the table 'track'.
726c8f65 17EOF
18
19plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_dt')
20 unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_dt');
21
22my @connect_info = (
23 [ $dsn, $user || '', $pass || '' ],
24 [ $dsn2, $user2 || '', $pass2 || '' ],
25);
26
27my $schema;
28
29for my $connect_info (@connect_info) {
30 my ($dsn, $user, $pass) = @$connect_info;
31
32 next unless $dsn;
33
34 $schema = DBICTest::Schema->connect($dsn, $user, $pass, {
35 on_connect_call => 'datetime_setup',
36 quote_names => 1,
37 });
38
39 my $guard = Scope::Guard->new(\&cleanup);
40
41 try { local $^W = 0; $schema->storage->dbh->do('DROP TABLE track') };
42 $schema->storage->dbh->do(<<"SQL");
43CREATE TABLE track (
44 trackid AUTOINCREMENT PRIMARY KEY,
45 cd INT,
46 [position] INT,
47 last_updated_at DATETIME
48)
49SQL
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
71done_testing;
72
73# clean up our mess
74sub cleanup {
75 # have to reconnect to drop a table that's in use
76 if (my $storage = eval { $schema->storage }) {
77 local $^W = 0;
78 $storage->disconnect;
79 $storage->dbh->do('DROP TABLE track');
80 }
81}