8 use DBIx::Class::Optional::Dependencies ();
12 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MSSQL_ODBC_${_}" } qw/DSN USER PASS/};
13 my ($dsn2, $user2, $pass2) = @ENV{map { "DBICTEST_MSSQL_${_}" } qw/DSN USER PASS/};
14 my ($dsn3, $user3, $pass3) = @ENV{map { "DBICTEST_MSSQL_ADO_${_}" } qw/DSN USER PASS/};
16 plan skip_all => 'Test needs ' .
17 (join ' and ', map { $_ ? $_ : () }
18 DBIx::Class::Optional::Dependencies->req_missing_for('test_dt'),
19 (join ' or ', map { $_ ? $_ : () }
20 DBIx::Class::Optional::Dependencies->req_missing_for('test_rdbms_mssql_odbc'),
21 DBIx::Class::Optional::Dependencies->req_missing_for('test_rdbms_mssql_sybase'),
22 DBIx::Class::Optional::Dependencies->req_missing_for('test_rdbms_mssql_ado')))
24 DBIx::Class::Optional::Dependencies->req_ok_for ('test_dt') && (
25 $dsn && DBIx::Class::Optional::Dependencies->req_ok_for('test_rdbms_mssql_odbc')
27 $dsn2 && DBIx::Class::Optional::Dependencies->req_ok_for('test_rdbms_mssql_sybase')
29 $dsn3 && DBIx::Class::Optional::Dependencies->req_ok_for('test_rdbms_mssql_ado'))
30 or (not $dsn || $dsn2 || $dsn3);
32 # use this if you keep a copy of DBD::Sybase linked to FreeTDS somewhere else
34 if (my $lib_dirs = $ENV{DBICTEST_MSSQL_PERL5LIB}) {
35 unshift @INC, $_ for split /:/, $lib_dirs;
39 if (not ($dsn || $dsn2 || $dsn3)) {
41 'Set $ENV{DBICTEST_MSSQL_ODBC_DSN} and/or $ENV{DBICTEST_MSSQL_DSN} and/or '
42 .'$ENV{DBICTEST_MSSQL_ADO_DSN} _USER and _PASS to run this test' .
43 "\nWarning: This test drops and creates tables called 'event_small_dt' and"
47 DBICTest::Schema->load_classes('EventSmallDT');
50 [ $dsn, $user, $pass ],
51 [ $dsn2, $user2, $pass2 ],
52 [ $dsn3, $user3, $pass3 ],
58 for my $connect_info (@connect_info) {
59 my ($dsn, $user, $pass) = @$connect_info;
63 $schema = DBICTest::Schema->connect($dsn, $user, $pass, {
64 on_connect_call => 'datetime_setup'
69 local $SIG{__WARN__} = sub { $w = shift };
70 $schema->storage->ensure_connected;
71 if ($w =~ /Your DBD::Sybase is too old to support DBIx::Class::InflateColumn::DateTime/) {
72 skip "Skipping tests on old DBD::Sybase " . DBD::Sybase->VERSION, 1;
76 my $guard = Scope::Guard->new(sub{ cleanup($schema) });
78 # $^W because DBD::ADO is a piece of crap
79 try { local $^W = 0; $schema->storage->dbh->do("DROP TABLE track") };
80 $schema->storage->dbh->do(<<"SQL");
82 trackid INT IDENTITY PRIMARY KEY,
85 last_updated_at DATETIME,
88 try { local $^W = 0; $schema->storage->dbh->do("DROP TABLE event_small_dt") };
89 $schema->storage->dbh->do(<<"SQL");
90 CREATE TABLE event_small_dt (
91 id INT IDENTITY PRIMARY KEY,
92 small_dt SMALLDATETIME,
96 # coltype, column, source, pk, create_extra, datehash
110 nanosecond => 500000000,
112 ['SMALLDATETIME', # minute precision
126 for my $dt_type (@dt_types) {
127 my ($type, $col, $source, $pk, $create_extra, $sample_dt) = @$dt_type;
129 delete $sample_dt->{nanosecond} if $dsn =~ /:ADO:/;
131 ok(my $dt = DateTime->new($sample_dt));
134 ok( $row = $schema->resultset($source)->create({
138 ok( $row = $schema->resultset($source)
139 ->search({ $pk => $row->$pk }, { select => [$col] })
142 is( $row->$col, $dt, "$type roundtrip" );
144 cmp_ok( $row->$col->nanosecond, '==', $sample_dt->{nanosecond},
145 'DateTime fractional portion roundtrip' )
146 if exists $sample_dt->{nanosecond};
155 if (my $dbh = eval { $schema->storage->dbh }) {
156 $dbh->do('DROP TABLE track');
157 $dbh->do('DROP TABLE event_small_dt');