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 if (not ($dsn || $dsn2 || $dsn3)) {
34 'Set $ENV{DBICTEST_MSSQL_ODBC_DSN} and/or $ENV{DBICTEST_MSSQL_DSN} and/or '
35 .'$ENV{DBICTEST_MSSQL_ADO_DSN} _USER and _PASS to run this test' .
36 "\nWarning: This test drops and creates tables called 'event_small_dt' and"
40 require DBICTest::Schema;
41 DBICTest::Schema->load_classes('EventSmallDT');
44 [ $dsn, $user, $pass ],
45 [ $dsn2, $user2, $pass2 ],
46 [ $dsn3, $user3, $pass3 ],
52 for my $connect_info (@connect_info) {
53 my ($dsn, $user, $pass) = @$connect_info;
57 $schema = DBICTest->connect_schema($dsn, $user, $pass, {
58 on_connect_call => 'datetime_setup'
63 local $SIG{__WARN__} = sub { $w = shift };
64 $schema->storage->ensure_connected;
65 if ($w =~ /Your DBD::Sybase is too old to support DBIx::Class::InflateColumn::DateTime/) {
66 skip "Skipping tests on old DBD::Sybase " . DBD::Sybase->VERSION, 1;
70 my $guard = Scope::Guard->new(sub{ cleanup($schema) });
72 # $^W because DBD::ADO is a piece of crap
73 try { local $^W = 0; $schema->storage->dbh->do("DROP TABLE track") };
74 $schema->storage->dbh->do(<<"SQL");
76 trackid INT IDENTITY PRIMARY KEY,
79 last_updated_at DATETIME,
82 try { local $^W = 0; $schema->storage->dbh->do("DROP TABLE event_small_dt") };
83 $schema->storage->dbh->do(<<"SQL");
84 CREATE TABLE event_small_dt (
85 id INT IDENTITY PRIMARY KEY,
86 small_dt SMALLDATETIME,
89 try { local $^W = 0; $schema->storage->dbh->do("DROP TABLE event") };
90 $schema->storage->dbh->do(<<"SQL");
92 id int IDENTITY(1,1) NOT NULL,
93 starts_at smalldatetime NULL,
94 created_on datetime NULL,
95 varchar_date varchar(20) NULL,
96 varchar_datetime varchar(20) NULL,
97 skip_inflation datetime NULL,
98 ts_without_tz datetime NULL
102 # coltype, column, source, pk, create_extra, datehash
116 nanosecond => 500000000,
118 ['SMALLDATETIME', # minute precision
132 for my $dt_type (@dt_types) {
133 my ($type, $col, $source, $pk, $create_extra, $sample_dt) = @$dt_type;
135 delete $sample_dt->{nanosecond} if $dsn =~ /:ADO:/;
137 ok(my $dt = DateTime->new($sample_dt));
140 ok( $row = $schema->resultset($source)->create({
144 ok( $row = $schema->resultset($source)
145 ->search({ $pk => $row->$pk }, { select => [$col] })
148 is( $row->$col, $dt, "$type roundtrip" );
150 cmp_ok( $row->$col->nanosecond, '==', $sample_dt->{nanosecond},
151 'DateTime fractional portion roundtrip' )
152 if exists $sample_dt->{nanosecond};
155 # Check for bulk insert SQL_DATE funtimes when using DBD::ODBC and sqlncli
156 # dbi:ODBC:driver=SQL Server Native Client 10.0;server=10.6.0.9;database=odbctest;
158 $schema->resultset('Event')->populate([{
163 starts_at => '2011-03-22',
165 } 'populate with datetime does not throw';
166 ok ( my $row = $schema->resultset('Event')->find(2), 'SQL_DATE bulk insert check' );
175 if (my $dbh = eval { $schema->storage->dbh }) {
176 $dbh->do('DROP TABLE track');
177 $dbh->do('DROP TABLE event_small_dt');
178 $dbh->do('DROP TABLE event');