11 DBICTest::Schema->load_classes('EventSmallDT');
13 # use this if you keep a copy of DBD::Sybase linked to FreeTDS somewhere else
15 if (my $lib_dirs = $ENV{DBICTEST_MSSQL_PERL5LIB}) {
16 unshift @INC, $_ for split /:/, $lib_dirs;
20 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MSSQL_ODBC_${_}" } qw/DSN USER PASS/};
21 my ($dsn2, $user2, $pass2) = @ENV{map { "DBICTEST_MSSQL_${_}" } qw/DSN USER PASS/};
22 my ($dsn3, $user3, $pass3) = @ENV{map { "DBICTEST_MSSQL_ADO_${_}" } qw/DSN USER PASS/};
24 if (not ($dsn || $dsn2 || $dsn3)) {
26 'Set $ENV{DBICTEST_MSSQL_ODBC_DSN} and/or $ENV{DBICTEST_MSSQL_DSN} and/or '
27 .'$ENV{DBICTEST_MSSQL_ADO_DSN} _USER and _PASS to run this test' .
28 "\nWarning: This test drops and creates tables called 'event_small_dt' and"
32 plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_dt')
33 unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_dt');
36 [ $dsn, $user, $pass ],
37 [ $dsn2, $user2, $pass2 ],
38 [ $dsn3, $user3, $pass3 ],
44 for my $connect_info (@connect_info) {
45 my ($dsn, $user, $pass) = @$connect_info;
49 $schema = DBICTest::Schema->connect($dsn, $user, $pass, {
50 on_connect_call => 'datetime_setup'
55 local $SIG{__WARN__} = sub { $w = shift };
56 $schema->storage->ensure_connected;
57 if ($w =~ /Your DBD::Sybase is too old to support DBIx::Class::InflateColumn::DateTime/) {
58 skip "Skipping tests on old DBD::Sybase " . DBD::Sybase->VERSION, 1;
62 my $guard = Scope::Guard->new(\&cleanup);
64 # $^W because DBD::ADO is a piece of crap
65 try { local $^W = 0; $schema->storage->dbh->do("DROP TABLE track") };
66 $schema->storage->dbh->do(<<"SQL");
68 trackid INT IDENTITY PRIMARY KEY,
71 last_updated_at DATETIME,
74 try { local $^W = 0; $schema->storage->dbh->do("DROP TABLE event_small_dt") };
75 $schema->storage->dbh->do(<<"SQL");
76 CREATE TABLE event_small_dt (
77 id INT IDENTITY PRIMARY KEY,
78 small_dt SMALLDATETIME,
82 # coltype, column, source, pk, create_extra, datehash
96 nanosecond => 500000000,
98 ['SMALLDATETIME', # minute precision
112 for my $dt_type (@dt_types) {
113 my ($type, $col, $source, $pk, $create_extra, $sample_dt) = @$dt_type;
115 delete $sample_dt->{nanosecond} if $dsn =~ /:ADO:/;
117 ok(my $dt = DateTime->new($sample_dt));
120 ok( $row = $schema->resultset($source)->create({
124 ok( $row = $schema->resultset($source)
125 ->search({ $pk => $row->$pk }, { select => [$col] })
128 is( $row->$col, $dt, "$type roundtrip" );
130 cmp_ok( $row->$col->nanosecond, '==', $sample_dt->{nanosecond},
131 'DateTime fractional portion roundtrip' )
132 if exists $sample_dt->{nanosecond};
140 if (my $dbh = eval { $schema->storage->dbh }) {
141 $dbh->do('DROP TABLE track');
142 $dbh->do('DROP TABLE event_small_dt');