7 use DBIx::Class::Optional::Dependencies ();
11 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MSSQL_ODBC_${_}" } qw/DSN USER PASS/};
12 my ($dsn2, $user2, $pass2) = @ENV{map { "DBICTEST_MSSQL_${_}" } qw/DSN USER PASS/};
13 my ($dsn3, $user3, $pass3) = @ENV{map { "DBICTEST_MSSQL_ADO_${_}" } qw/DSN USER PASS/};
15 plan skip_all => 'Test needs ' .
16 (join ' and ', map { $_ ? $_ : () }
17 DBIx::Class::Optional::Dependencies->req_missing_for('test_dt'),
18 (join ' or ', map { $_ ? $_ : () }
19 DBIx::Class::Optional::Dependencies->req_missing_for('test_rdbms_mssql_odbc'),
20 DBIx::Class::Optional::Dependencies->req_missing_for('test_rdbms_mssql_sybase'),
21 DBIx::Class::Optional::Dependencies->req_missing_for('test_rdbms_mssql_ado')))
23 DBIx::Class::Optional::Dependencies->req_ok_for ('test_dt') && (
24 $dsn && DBIx::Class::Optional::Dependencies->req_ok_for('test_rdbms_mssql_odbc')
26 $dsn2 && DBIx::Class::Optional::Dependencies->req_ok_for('test_rdbms_mssql_sybase')
28 $dsn3 && DBIx::Class::Optional::Dependencies->req_ok_for('test_rdbms_mssql_ado'))
29 or (not $dsn || $dsn2 || $dsn3);
31 # use this if you keep a copy of DBD::Sybase linked to FreeTDS somewhere else
33 if (my $lib_dirs = $ENV{DBICTEST_MSSQL_PERL5LIB}) {
34 unshift @INC, $_ for split /:/, $lib_dirs;
38 if (not ($dsn || $dsn2 || $dsn3)) {
40 'Set $ENV{DBICTEST_MSSQL_ODBC_DSN} and/or $ENV{DBICTEST_MSSQL_DSN} and/or '
41 .'$ENV{DBICTEST_MSSQL_ADO_DSN} _USER and _PASS to run this test' .
42 "\nWarning: This test drops and creates tables called 'event_small_dt' and"
46 DBICTest::Schema->load_classes('EventSmallDT');
49 [ $dsn, $user, $pass ],
50 [ $dsn2, $user2, $pass2 ],
51 [ $dsn3, $user3, $pass3 ],
57 for my $connect_info (@connect_info) {
58 my ($dsn, $user, $pass) = @$connect_info;
62 $schema = DBICTest::Schema->connect($dsn, $user, $pass, {
63 on_connect_call => 'datetime_setup'
68 local $SIG{__WARN__} = sub { $w = shift };
69 $schema->storage->ensure_connected;
70 if ($w =~ /Your DBD::Sybase is too old to support DBIx::Class::InflateColumn::DateTime/) {
71 skip "Skipping tests on old DBD::Sybase " . DBD::Sybase->VERSION, 1;
75 my $guard = Scope::Guard->new(sub{ cleanup($schema) });
77 # $^W because DBD::ADO is a piece of crap
78 try { local $^W = 0; $schema->storage->dbh->do("DROP TABLE track") };
79 $schema->storage->dbh->do(<<"SQL");
81 trackid INT IDENTITY PRIMARY KEY,
84 last_updated_at DATETIME,
87 try { local $^W = 0; $schema->storage->dbh->do("DROP TABLE event_small_dt") };
88 $schema->storage->dbh->do(<<"SQL");
89 CREATE TABLE event_small_dt (
90 id INT IDENTITY PRIMARY KEY,
91 small_dt SMALLDATETIME,
95 # coltype, column, source, pk, create_extra, datehash
109 nanosecond => 500000000,
111 ['SMALLDATETIME', # minute precision
125 for my $dt_type (@dt_types) {
126 my ($type, $col, $source, $pk, $create_extra, $sample_dt) = @$dt_type;
128 delete $sample_dt->{nanosecond} if $dsn =~ /:ADO:/;
130 ok(my $dt = DateTime->new($sample_dt));
133 ok( $row = $schema->resultset($source)->create({
137 ok( $row = $schema->resultset($source)
138 ->search({ $pk => $row->$pk }, { select => [$col] })
141 is( $row->$col, $dt, "$type roundtrip" );
143 cmp_ok( $row->$col->nanosecond, '==', $sample_dt->{nanosecond},
144 'DateTime fractional portion roundtrip' )
145 if exists $sample_dt->{nanosecond};
154 if (my $dbh = eval { $schema->storage->dbh }) {
155 $dbh->do('DROP TABLE track');
156 $dbh->do('DROP TABLE event_small_dt');