1 use DBIx::Class::Optional::Dependencies -skip_all_without => qw( ic_dt _rdbms_mssql_common );
9 use DBIx::Class::_Util 'scope_guard';
13 my @tdeps = qw( test_rdbms_mssql_odbc test_rdbms_mssql_sybase test_rdbms_mssql_ado );
14 plan skip_all => 'Test needs ' . (join ' OR ', map
15 { "[ @{[ DBIx::Class::Optional::Dependencies->req_missing_for( $_ ) ]} ]" }
18 { DBIx::Class::Optional::Dependencies->req_ok_for( $_ ) }
22 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MSSQL_ODBC_${_}" } qw/DSN USER PASS/};
23 my ($dsn2, $user2, $pass2) = @ENV{map { "DBICTEST_MSSQL_${_}" } qw/DSN USER PASS/};
24 my ($dsn3, $user3, $pass3) = @ENV{map { "DBICTEST_MSSQL_ADO_${_}" } qw/DSN USER PASS/};
26 DBICTest::Schema->load_classes('EventSmallDT');
29 [ $dsn, $user, $pass ],
30 [ $dsn2, $user2, $pass2 ],
31 [ $dsn3, $user3, $pass3 ],
37 for my $connect_info (@connect_info) {
38 my ($dsn, $user, $pass) = @$connect_info;
42 $schema = DBICTest::Schema->connect($dsn, $user, $pass, {
43 on_connect_call => 'datetime_setup'
48 local $SIG{__WARN__} = sub { $w = shift };
49 $schema->storage->ensure_connected;
50 if ($w =~ /Your DBD::Sybase is too old to support DBIx::Class::InflateColumn::DateTime/) {
51 skip "Skipping tests on old DBD::Sybase " . DBD::Sybase->VERSION, 1;
55 my $guard = scope_guard { cleanup($schema) };
57 # $^W because DBD::ADO is a piece of crap
58 try { local $^W = 0; $schema->storage->dbh->do("DROP TABLE track") };
59 $schema->storage->dbh->do(<<"SQL");
61 trackid INT IDENTITY PRIMARY KEY,
64 last_updated_at DATETIME,
67 try { local $^W = 0; $schema->storage->dbh->do("DROP TABLE event_small_dt") };
68 $schema->storage->dbh->do(<<"SQL");
69 CREATE TABLE event_small_dt (
70 id INT IDENTITY PRIMARY KEY,
71 small_dt SMALLDATETIME,
74 try { local $^W = 0; $schema->storage->dbh->do("DROP TABLE event") };
75 $schema->storage->dbh->do(<<"SQL");
77 id int IDENTITY(1,1) NOT NULL,
78 starts_at smalldatetime NULL,
79 created_on datetime NULL,
80 varchar_date varchar(20) NULL,
81 varchar_datetime varchar(20) NULL,
82 skip_inflation datetime NULL,
83 ts_without_tz datetime NULL
87 # coltype, column, source, pk, create_extra, datehash
101 nanosecond => 500000000,
103 ['SMALLDATETIME', # minute precision
117 for my $dt_type (@dt_types) {
118 my ($type, $col, $source, $pk, $create_extra, $sample_dt) = @$dt_type;
120 delete $sample_dt->{nanosecond} if $dsn =~ /:ADO:/;
122 ok(my $dt = DateTime->new($sample_dt));
125 ok( $row = $schema->resultset($source)->create({
129 ok( $row = $schema->resultset($source)
130 ->search({ $pk => $row->$pk }, { select => [$col] })
133 is( $row->$col, $dt, "$type roundtrip" );
135 cmp_ok( $row->$col->nanosecond, '==', $sample_dt->{nanosecond},
136 'DateTime fractional portion roundtrip' )
137 if exists $sample_dt->{nanosecond};
140 # Check for bulk insert SQL_DATE funtimes when using DBD::ODBC and sqlncli
141 # dbi:ODBC:driver=SQL Server Native Client 10.0;server=10.6.0.9;database=odbctest;
143 $schema->resultset('Event')->populate([{
148 starts_at => '2011-03-22',
150 } 'populate with datetime does not throw';
151 ok ( my $row = $schema->resultset('Event')->find(2), 'SQL_DATE bulk insert check' );
160 if (my $dbh = eval { $schema->storage->dbh }) {
161 $dbh->do('DROP TABLE track');
162 $dbh->do('DROP TABLE event_small_dt');
163 $dbh->do('DROP TABLE event');