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 _ping
56 $schema->storage->_dbh->disconnect;
59 $schema->storage->dbh_do(sub { $_[1]->do('select 1') })
62 my $dbh = $schema->storage->dbh;
64 $dbh->do("IF OBJECT_ID('artist', 'U') IS NOT NULL
66 $dbh->do("IF OBJECT_ID('cd', 'U') IS NOT NULL
69 $dbh->do("CREATE TABLE artist (artistid INT IDENTITY PRIMARY KEY, name VARCHAR(100), rank INT DEFAULT '13', charfield CHAR(10) NULL);");
70 $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);");
71 # Just to test compat shim, Auto is in Core
72 $schema->class('Artist')->load_components('PK::Auto::MSSQL');
75 my $new = $schema->resultset('Artist')->create( { name => 'foo' } );
76 ok($new->artistid, "Auto-PK worked");
80 $schema->resultset('Artist')->create( { name => 'Artist ' . $_, rank => $_ } );
83 my $it = $schema->resultset('Artist')->search( { },
86 order_by => 'artistid'
90 # Test ? in data don't get treated as placeholders
91 my $cd = $schema->resultset('CD')->create( {
93 title => 'Does this break things?',
96 ok($cd->id, 'Not treating ? in data as placeholders');
98 is( $it->count, 3, "LIMIT count ok" );
99 ok( $it->next->name, "iterator->next ok" );
102 is( $it->next, undef, "next past end of resultset ok" );
104 # test MONEY column support
105 $schema->storage->dbh_do (sub {
106 my ($storage, $dbh) = @_;
107 eval { $dbh->do("DROP TABLE money_test") };
109 CREATE TABLE money_test (
110 id INT IDENTITY PRIMARY KEY,
117 my $rs = $schema->resultset('Money');
121 $row = $rs->create({ amount => 100 });
122 } 'inserted a money value';
124 cmp_ok $rs->find($row->id)->amount, '==', 100, 'money value round-trip';
127 $row->update({ amount => 200 });
128 } 'updated a money value';
130 cmp_ok $rs->find($row->id)->amount, '==', 200,
131 'updated money value round-trip';
134 $row->update({ amount => undef });
135 } 'updated a money value to NULL';
137 is $rs->find($row->id)->amount,
138 undef, 'updated money value to NULL round-trip';
140 $rs->create({ amount => 300 }) for (1..3);
142 # test multiple active statements
144 my $artist_rs = $schema->resultset('Artist');
145 while (my $row = $rs->next) {
146 my $artist = $artist_rs->next;
149 } 'multiple active statements';
153 # test simple transaction with commit
155 $schema->txn_do(sub {
156 $rs->create({ amount => 400 });
158 } 'simple transaction';
160 cmp_ok $rs->first->amount, '==', 400, 'committed';
167 $schema->txn_do(sub {
168 $rs->create({ amount => 400 });
171 } qr/mtfnpy/, 'simple failed txn';
173 is $rs->first, undef, 'rolled back';
177 # test op-induced autoconnect
180 my $schema = DBICTest::Schema->clone;
181 $schema->connection($dsn, $user, $pass);
183 my $artist = $schema->resultset ('Artist')->search ({}, { order_by => 'artistid' })->next;
184 is ($artist->id, 1, 'Artist retrieved successfully');
185 }, 'Query-induced autoconnect works');
191 if (my $dbh = eval { $schema->storage->dbh }) {
192 $dbh->do("IF OBJECT_ID('artist', 'U') IS NOT NULL DROP TABLE artist");
193 $dbh->do("IF OBJECT_ID('cd', 'U') IS NOT NULL DROP TABLE cd");
194 $dbh->do("IF OBJECT_ID('money_test', 'U') IS NOT NULL DROP TABLE money_test");