1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2 use DBIx::Class::Optional::Dependencies -skip_all_without => qw( ic_dt _rdbms_mssql_common );
10 use DBIx::Class::_Util 'scope_guard';
14 my @tdeps = qw( test_rdbms_mssql_odbc test_rdbms_mssql_sybase test_rdbms_mssql_ado );
15 plan skip_all => 'Test needs ' . (join ' OR ', map
16 { "[ @{[ DBIx::Class::Optional::Dependencies->req_missing_for( $_ ) ]} ]" }
19 { DBIx::Class::Optional::Dependencies->req_ok_for( $_ ) }
23 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MSSQL_ODBC_${_}" } qw/DSN USER PASS/};
24 my ($dsn2, $user2, $pass2) = @ENV{map { "DBICTEST_MSSQL_${_}" } qw/DSN USER PASS/};
25 my ($dsn3, $user3, $pass3) = @ENV{map { "DBICTEST_MSSQL_ADO_${_}" } qw/DSN USER PASS/};
27 DBICTest::Schema->load_classes('EventSmallDT');
30 [ $dsn, $user, $pass ],
31 [ $dsn2, $user2, $pass2 ],
32 [ $dsn3, $user3, $pass3 ],
38 for my $connect_info (@connect_info) {
39 my ($dsn, $user, $pass) = @$connect_info;
43 $schema = DBICTest::Schema->connect($dsn, $user, $pass, {
44 on_connect_call => 'datetime_setup'
49 local $SIG{__WARN__} = sub { $w = shift };
50 $schema->storage->ensure_connected;
51 if ($w =~ /Your DBD::Sybase is too old to support DBIx::Class::InflateColumn::DateTime/) {
52 skip "Skipping tests on old DBD::Sybase " . DBD::Sybase->VERSION, 1;
56 my $guard = scope_guard { cleanup($schema) };
58 # $^W because DBD::ADO is a piece of crap
59 try { local $^W = 0; $schema->storage->dbh->do("DROP TABLE track") };
60 $schema->storage->dbh->do(<<"SQL");
62 trackid INT IDENTITY PRIMARY KEY,
65 last_updated_at DATETIME,
68 try { local $^W = 0; $schema->storage->dbh->do("DROP TABLE event_small_dt") };
69 $schema->storage->dbh->do(<<"SQL");
70 CREATE TABLE event_small_dt (
71 id INT IDENTITY PRIMARY KEY,
72 small_dt SMALLDATETIME,
75 try { local $^W = 0; $schema->storage->dbh->do("DROP TABLE event") };
76 $schema->storage->dbh->do(<<"SQL");
78 id int IDENTITY(1,1) NOT NULL,
79 starts_at smalldatetime NULL,
80 created_on datetime NULL,
81 varchar_date varchar(20) NULL,
82 varchar_datetime varchar(20) NULL,
83 skip_inflation datetime NULL,
84 ts_without_tz datetime NULL
88 # coltype, column, source, pk, create_extra, datehash
102 nanosecond => 500000000,
104 ['SMALLDATETIME', # minute precision
118 for my $dt_type (@dt_types) {
119 my ($type, $col, $source, $pk, $create_extra, $sample_dt) = @$dt_type;
121 delete $sample_dt->{nanosecond} if $dsn =~ /:ADO:/;
123 ok(my $dt = DateTime->new($sample_dt));
126 ok( $row = $schema->resultset($source)->create({
130 ok( $row = $schema->resultset($source)
131 ->search({ $pk => $row->$pk }, { select => [$col] })
134 is( $row->$col, $dt, "$type roundtrip" );
136 cmp_ok( $row->$col->nanosecond, '==', $sample_dt->{nanosecond},
137 'DateTime fractional portion roundtrip' )
138 if exists $sample_dt->{nanosecond};
141 # Check for bulk insert SQL_DATE funtimes when using DBD::ODBC and sqlncli
142 # dbi:ODBC:driver=SQL Server Native Client 10.0;server=10.6.0.9;database=odbctest;
144 $schema->resultset('Event')->populate([{
149 starts_at => '2011-03-22',
151 } 'populate with datetime does not throw';
152 ok ( my $row = $schema->resultset('Event')->find(2), 'SQL_DATE bulk insert check' );
161 if (my $dbh = eval { $schema->storage->dbh }) {
162 $dbh->do('DROP TABLE track');
163 $dbh->do('DROP TABLE event_small_dt');
164 $dbh->do('DROP TABLE event');