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 if ($storage_idx != 0) { # autodetect
35 $schema->storage_type("::$storage_type");
38 $schema->connection($dsn, $user, $pass);
40 $schema->storage->ensure_connected;
42 if ($storage_idx == 0 && ref($schema->storage) =~ /NoBindVars\z/) {
43 my $tb = Test::More->builder;
44 $tb->skip('no placeholders') for 1..$NUMBER_OF_TESTS_IN_BLOCK;
48 isa_ok($schema->storage, "DBIx::Class::Storage::$storage_type");
50 # start disconnected to test reconnection
51 $schema->storage->_dbh->disconnect;
55 $dbh = $schema->storage->dbh;
56 }, 'reconnect works');
58 $dbh->do("IF OBJECT_ID('artist', 'U') IS NOT NULL
60 $dbh->do("IF OBJECT_ID('cd', 'U') IS NOT NULL
63 $dbh->do("CREATE TABLE artist (artistid INT IDENTITY PRIMARY KEY, name VARCHAR(100), rank INT DEFAULT '13', charfield CHAR(10) NULL);");
64 $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);");
65 # Just to test compat shim, Auto is in Core
66 $schema->class('Artist')->load_components('PK::Auto::MSSQL');
69 my $new = $schema->resultset('Artist')->create( { name => 'foo' } );
70 ok($new->artistid, "Auto-PK worked");
74 $schema->resultset('Artist')->create( { name => 'Artist ' . $_, rank => $_ } );
77 my $it = $schema->resultset('Artist')->search( { },
80 order_by => 'artistid'
84 # Test ? in data don't get treated as placeholders
85 my $cd = $schema->resultset('CD')->create( {
87 title => 'Does this break things?',
90 ok($cd->id, 'Not treating ? in data as placeholders');
92 is( $it->count, 3, "LIMIT count ok" );
93 ok( $it->next->name, "iterator->next ok" );
96 is( $it->next, undef, "next past end of resultset ok" );
98 # test MONEY column support
99 $schema->storage->dbh_do (sub {
100 my ($storage, $dbh) = @_;
101 eval { $dbh->do("DROP TABLE money_test") };
103 CREATE TABLE money_test (
104 id INT IDENTITY PRIMARY KEY,
111 my $rs = $schema->resultset('Money');
115 $row = $rs->create({ amount => 100 });
116 } 'inserted a money value';
118 cmp_ok $rs->find($row->id)->amount, '==', 100, 'money value round-trip';
121 $row->update({ amount => 200 });
122 } 'updated a money value';
124 cmp_ok $rs->find($row->id)->amount, '==', 200,
125 'updated money value round-trip';
128 $row->update({ amount => undef });
129 } 'updated a money value to NULL';
131 is $rs->find($row->id)->amount,
132 undef, 'updated money value to NULL round-trip';
134 $rs->create({ amount => 300 }) for (1..3);
136 # test multiple active statements
138 my $artist_rs = $schema->resultset('Artist');
139 while (my $row = $rs->next) {
140 my $artist = $artist_rs->next;
143 } 'multiple active statements';
147 # test simple transaction with commit
149 $schema->txn_do(sub {
150 $rs->create({ amount => 400 });
152 } 'simple transaction';
154 cmp_ok $rs->first->amount, '==', 400, 'committed';
161 $schema->txn_do(sub {
162 $rs->create({ amount => 400 });
165 } qr/mtfnpy/, 'simple failed txn';
167 is $rs->first, undef, 'rolled back';
171 # test op-induced autoconnect
174 my $schema = DBICTest::Schema->clone;
175 $schema->connection($dsn, $user, $pass);
177 my $artist = $schema->resultset ('Artist')->search ({}, { order_by => 'artistid' })->next;
178 is ($artist->id, 1, 'Artist retrieved successfully');
179 }, 'Query-induced autoconnect works');
185 if (my $dbh = eval { $schema->storage->dbh }) {
186 $dbh->do("IF OBJECT_ID('artist', 'U') IS NOT NULL DROP TABLE artist");
187 $dbh->do("IF OBJECT_ID('cd', 'U') IS NOT NULL DROP TABLE cd");
188 $dbh->do("IF OBJECT_ID('money_test', 'U') IS NOT NULL DROP TABLE money_test");