4 # use this if you keep a copy of DBD::Sybase linked to FreeTDS somewhere else
6 if (my $lib_dirs = $ENV{DBICTEST_MSSQL_PERL5LIB}) {
7 unshift @INC, $_ for split /:/, $lib_dirs;
16 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MSSQL_${_}" } qw/DSN USER PASS/};
18 plan skip_all => 'Set $ENV{DBICTEST_MSSQL_DSN}, _USER and _PASS to run this test'
22 'DBI::Sybase::Microsoft_SQL_Server',
23 'DBI::Sybase::Microsoft_SQL_Server::NoBindVars',
28 my $NUMBER_OF_TESTS_IN_BLOCK = 18;
29 for my $storage_type (@storage_types) {
32 $schema = DBICTest::Schema->clone;
34 $schema->connection($dsn, $user, $pass);
36 if ($storage_idx != 0) { # autodetect
37 no warnings 'redefine';
38 local *DBIx::Class::Storage::DBI::_typeless_placeholders_supported =
40 # $schema->storage_type("::$storage_type");
41 $schema->storage->ensure_connected;
44 $schema->storage->ensure_connected;
47 if ($storage_idx == 0 && ref($schema->storage) =~ /NoBindVars\z/) {
48 my $tb = Test::More->builder;
49 $tb->skip('no placeholders') for 1..$NUMBER_OF_TESTS_IN_BLOCK;
53 isa_ok($schema->storage, "DBIx::Class::Storage::$storage_type");
55 # start disconnected to test reconnection
56 $schema->storage->_dbh->disconnect;
60 $dbh = $schema->storage->dbh;
61 }, 'reconnect works');
63 $dbh->do("IF OBJECT_ID('artist', 'U') IS NOT NULL
65 $dbh->do("IF OBJECT_ID('cd', 'U') IS NOT NULL
68 $dbh->do("CREATE TABLE artist (artistid INT IDENTITY PRIMARY KEY, name VARCHAR(100), rank INT DEFAULT '13', charfield CHAR(10) NULL);");
69 $dbh->do("CREATE TABLE cd (cdid INT IDENTITY PRIMARY KEY, artist INT, title VARCHAR(100), year VARCHAR(100), genreid INT NULL, single_track INT NULL);");
70 # Just to test compat shim, Auto is in Core
71 $schema->class('Artist')->load_components('PK::Auto::MSSQL');
74 my $new = $schema->resultset('Artist')->create( { name => 'foo' } );
75 ok($new->artistid, "Auto-PK worked");
79 $schema->resultset('Artist')->create( { name => 'Artist ' . $_, rank => $_ } );
82 my $it = $schema->resultset('Artist')->search( { },
85 order_by => 'artistid'
89 # Test ? in data don't get treated as placeholders
90 my $cd = $schema->resultset('CD')->create( {
92 title => 'Does this break things?',
95 ok($cd->id, 'Not treating ? in data as placeholders');
97 is( $it->count, 3, "LIMIT count ok" );
98 ok( $it->next->name, "iterator->next ok" );
101 is( $it->next, undef, "next past end of resultset ok" );
103 # test MONEY column support
104 $schema->storage->dbh_do (sub {
105 my ($storage, $dbh) = @_;
106 eval { $dbh->do("DROP TABLE money_test") };
108 CREATE TABLE money_test (
109 id INT IDENTITY PRIMARY KEY,
116 my $rs = $schema->resultset('Money');
120 $row = $rs->create({ amount => 100 });
121 } 'inserted a money value';
123 cmp_ok $rs->find($row->id)->amount, '==', 100, 'money value round-trip';
126 $row->update({ amount => 200 });
127 } 'updated a money value';
129 cmp_ok $rs->find($row->id)->amount, '==', 200,
130 'updated money value round-trip';
133 $row->update({ amount => undef });
134 } 'updated a money value to NULL';
136 is $rs->find($row->id)->amount,
137 undef, 'updated money value to NULL round-trip';
139 $rs->create({ amount => 300 }) for (1..3);
141 # test multiple active statements
143 my $artist_rs = $schema->resultset('Artist');
144 while (my $row = $rs->next) {
145 my $artist = $artist_rs->next;
148 } 'multiple active statements';
152 # test simple transaction with commit
154 $schema->txn_do(sub {
155 $rs->create({ amount => 400 });
157 } 'simple transaction';
159 cmp_ok $rs->first->amount, '==', 400, 'committed';
166 $schema->txn_do(sub {
167 $rs->create({ amount => 400 });
170 } qr/mtfnpy/, 'simple failed txn';
172 is $rs->first, undef, 'rolled back';
176 # test op-induced autoconnect
179 my $schema = DBICTest::Schema->clone;
180 $schema->connection($dsn, $user, $pass);
182 my $artist = $schema->resultset ('Artist')->search ({}, { order_by => 'artistid' })->next;
183 is ($artist->id, 1, 'Artist retrieved successfully');
184 }, 'Query-induced autoconnect works');
190 if (my $dbh = eval { $schema->storage->dbh }) {
191 $dbh->do("IF OBJECT_ID('artist', 'U') IS NOT NULL DROP TABLE artist");
192 $dbh->do("IF OBJECT_ID('cd', 'U') IS NOT NULL DROP TABLE cd");
193 $dbh->do("IF OBJECT_ID('money_test', 'U') IS NOT NULL DROP TABLE money_test");