Fix exception message
[dbsrgits/DBIx-Class.git] / t / inflate / datetime_mssql.t
CommitLineData
5a77aa8b 1use strict;
2use warnings;
3
4use Test::More;
5use Test::Exception;
6use lib qw(t/lib);
7use DBICTest;
8
9my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MSSQL_ODBC_${_}" } qw/DSN USER PASS/};
10
11if (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
25my $schema = DBICTest::Schema->clone;
26
27$schema->connection($dsn, $user, $pass);
28$schema->storage->ensure_connected;
29
b7ad9162 30# coltype, column, datehash
5a77aa8b 31my @dt_types = (
b7ad9162 32 ['DATETIME',
33 'last_updated_at',
34 {
5a77aa8b 35 year => 2004,
36 month => 8,
37 day => 21,
38 hour => 14,
39 minute => 36,
40 second => 48,
41 nanosecond => 500000000,
42 }],
b7ad9162 43 ['SMALLDATETIME', # minute precision
44 'small_dt',
45 {
5a77aa8b 46 year => 2004,
47 month => 8,
48 day => 21,
49 hour => 14,
50 minute => 36,
51 }],
52);
53
54for my $dt_type (@dt_types) {
b7ad9162 55 my ($type, $col, $sample_dt) = @$dt_type;
5a77aa8b 56
57 eval { $schema->storage->dbh->do("DROP TABLE track") };
58 $schema->storage->dbh->do(<<"SQL");
59CREATE TABLE track (
60 trackid INT IDENTITY PRIMARY KEY,
61 cd INT,
62 position INT,
b7ad9162 63 $col $type,
5a77aa8b 64)
65SQL
66 ok(my $dt = DateTime->new($sample_dt));
67
68 my $row;
69 ok( $row = $schema->resultset('Track')->create({
b7ad9162 70 $col => $dt,
5a77aa8b 71 cd => 1,
72 }));
73 ok( $row = $schema->resultset('Track')
b7ad9162 74 ->search({ trackid => $row->trackid }, { select => [$col] })
5a77aa8b 75 ->first
76 );
b7ad9162 77 is( $row->$col, $dt, 'DateTime roundtrip' );
5a77aa8b 78}
79
80# clean up our mess
81END {
82 if (my $dbh = eval { $schema->storage->_dbh }) {
83 $dbh->do('DROP TABLE track');
84 }
85}