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/};
23 if (not ($dsn || $dsn2)) {
25 'Set $ENV{DBICTEST_MSSQL_ODBC_DSN} and/or $ENV{DBICTEST_MSSQL_DSN} _USER '
26 .'and _PASS to run this test' .
27 "\nWarning: This test drops and creates a table called 'small_dt'";
30 plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_dt')
31 unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_dt');
34 [ $dsn, $user, $pass ],
35 [ $dsn2, $user2, $pass2 ],
41 for my $connect_info (@connect_info) {
42 my ($dsn, $user, $pass) = @$connect_info;
46 $schema = DBICTest::Schema->connect($dsn, $user, $pass, {
47 on_connect_call => 'datetime_setup'
52 local $SIG{__WARN__} = sub { $w = shift };
53 $schema->storage->ensure_connected;
54 if ($w =~ /Your DBD::Sybase is too old to support DBIx::Class::InflateColumn::DateTime/) {
55 skip "Skipping tests on old DBD::Sybase " . DBD::Sybase->VERSION, 1;
59 my $guard = Scope::Guard->new(\&cleanup);
61 try { $schema->storage->dbh->do("DROP TABLE track") };
62 $schema->storage->dbh->do(<<"SQL");
64 trackid INT IDENTITY PRIMARY KEY,
67 last_updated_at DATETIME,
70 try { $schema->storage->dbh->do("DROP TABLE event_small_dt") };
71 $schema->storage->dbh->do(<<"SQL");
72 CREATE TABLE event_small_dt (
73 id INT IDENTITY PRIMARY KEY,
74 small_dt SMALLDATETIME,
78 # coltype, column, source, pk, create_extra, datehash
92 nanosecond => 500000000,
94 ['SMALLDATETIME', # minute precision
108 for my $dt_type (@dt_types) {
109 my ($type, $col, $source, $pk, $create_extra, $sample_dt) = @$dt_type;
111 ok(my $dt = DateTime->new($sample_dt));
114 ok( $row = $schema->resultset($source)->create({
118 ok( $row = $schema->resultset($source)
119 ->search({ $pk => $row->$pk }, { select => [$col] })
122 is( $row->$col, $dt, "$type roundtrip" );
124 cmp_ok( $row->$col->nanosecond, '==', $sample_dt->{nanosecond},
125 'DateTime fractional portion roundtrip' )
126 if exists $sample_dt->{nanosecond};
134 if (my $dbh = eval { $schema->storage->dbh }) {
135 $dbh->do('DROP TABLE track');
136 $dbh->do('DROP TABLE event_small_dt');