Commit | Line | Data |
5a77aa8b |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | use Test::Exception; |
6 | use lib qw(t/lib); |
7 | use DBICTest; |
8 | |
9 | my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MSSQL_ODBC_${_}" } qw/DSN USER PASS/}; |
10 | |
11 | if (not ($dsn && $user)) { |
12 | plan skip_all => |
13 | 'Set $ENV{DBICTEST_MSSQL_ODBC_DSN}, _USER and _PASS to run this test' . |
14 | "\nWarning: This test drops and creates a table called 'track'"; |
15 | } else { |
16 | eval "use DateTime; use DateTime::Format::Strptime;"; |
17 | if ($@) { |
18 | plan skip_all => 'needs DateTime and DateTime::Format::Strptime for testing'; |
19 | } |
20 | else { |
21 | plan tests => 4 * 2; # (tests * dt_types) |
22 | } |
23 | } |
24 | |
25 | my $schema = DBICTest::Schema->clone; |
26 | |
27 | $schema->connection($dsn, $user, $pass); |
28 | $schema->storage->ensure_connected; |
29 | |
30 | my @dt_types = ( |
31 | ['DATETIME', { |
32 | year => 2004, |
33 | month => 8, |
34 | day => 21, |
35 | hour => 14, |
36 | minute => 36, |
37 | second => 48, |
38 | nanosecond => 500000000, |
39 | }], |
40 | ['SMALLDATETIME', { # minute precision |
41 | year => 2004, |
42 | month => 8, |
43 | day => 21, |
44 | hour => 14, |
45 | minute => 36, |
46 | }], |
47 | ); |
48 | |
49 | for my $dt_type (@dt_types) { |
50 | my ($type, $sample_dt) = @$dt_type; |
51 | |
52 | eval { $schema->storage->dbh->do("DROP TABLE track") }; |
53 | $schema->storage->dbh->do(<<"SQL"); |
54 | CREATE TABLE track ( |
55 | trackid INT IDENTITY PRIMARY KEY, |
56 | cd INT, |
57 | position INT, |
58 | last_updated_on $type, |
59 | ) |
60 | SQL |
61 | ok(my $dt = DateTime->new($sample_dt)); |
62 | |
63 | my $row; |
64 | ok( $row = $schema->resultset('Track')->create({ |
65 | last_updated_on => $dt, |
66 | cd => 1, |
67 | })); |
68 | ok( $row = $schema->resultset('Track') |
69 | ->search({ trackid => $row->trackid }, { select => ['last_updated_on'] }) |
70 | ->first |
71 | ); |
72 | is( $row->updated_date, $dt, 'DateTime roundtrip' ); |
73 | } |
74 | |
75 | # clean up our mess |
76 | END { |
77 | if (my $dbh = eval { $schema->storage->_dbh }) { |
78 | $dbh->do('DROP TABLE track'); |
79 | } |
80 | } |