Take a copy instead of weakening in 5.8 leak workaround
[dbsrgits/DBIx-Class.git] / t / inflate / datetime_msaccess.t
CommitLineData
726c8f65 1use strict;
2use warnings;
3
4use Test::More;
726c8f65 5use Scope::Guard ();
6use Try::Tiny;
199fbc45 7use DBIx::Class::Optional::Dependencies ();
726c8f65 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
199fbc45 14plan 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 27plan skip_all => <<'EOF' unless $dsn || $dsn2;
076bd599 28Set $ENV{DBICTEST_MSACCESS_ODBC_DSN} and/or $ENV{DBICTEST_MSACCESS_ADO_DSN} (and optionally _USER and _PASS) to run these tests.
29Warning: this test drops and creates the table 'track'.
726c8f65 30EOF
31
726c8f65 32my @connect_info = (
33 [ $dsn, $user || '', $pass || '' ],
34 [ $dsn2, $user2 || '', $pass2 || '' ],
35);
36
726c8f65 37for 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");
51CREATE TABLE track (
52 trackid AUTOINCREMENT PRIMARY KEY,
53 cd INT,
54 [position] INT,
55 last_updated_at DATETIME
56)
57SQL
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
79done_testing;
80
81# clean up our mess
82sub 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}