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'
23 my $schema = DBICTest::Schema->clone;
24 $schema->connection($dsn, $user, $pass);
26 # start disconnected to test reconnection
27 $schema->storage->ensure_connected;
28 $schema->storage->_dbh->disconnect;
30 isa_ok($schema->storage, 'DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server');
34 $dbh = $schema->storage->dbh;
35 }, 'reconnect works');
37 $dbh->do("IF OBJECT_ID('artist', 'U') IS NOT NULL
39 $dbh->do("IF OBJECT_ID('cd', 'U') IS NOT NULL
42 $dbh->do("CREATE TABLE artist (artistid INT IDENTITY PRIMARY KEY, name VARCHAR(100), rank INT DEFAULT '13', charfield CHAR(10) NULL);");
43 $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);");
44 # Just to test compat shim, Auto is in Core
45 $schema->class('Artist')->load_components('PK::Auto::MSSQL');
48 my $new = $schema->resultset('Artist')->create( { name => 'foo' } );
49 ok($new->artistid, "Auto-PK worked");
53 $schema->resultset('Artist')->create( { name => 'Artist ' . $_, rank => $_ } );
56 my $it = $schema->resultset('Artist')->search( { },
59 order_by => 'artistid'
63 # Test ? in data don't get treated as placeholders
64 my $cd = $schema->resultset('CD')->create( {
66 title => 'Does this break things?',
69 ok($cd->id, 'Not treating ? in data as placeholders');
71 is( $it->count, 3, "LIMIT count ok" );
72 ok( $it->next->name, "iterator->next ok" );
75 is( $it->next, undef, "next past end of resultset ok" );
77 # test MONEY column support
78 $schema->storage->dbh_do (sub {
79 my ($storage, $dbh) = @_;
80 eval { $dbh->do("DROP TABLE money_test") };
83 CREATE TABLE money_test (
84 id INT IDENTITY PRIMARY KEY,
92 my $rs = $schema->resultset('Money');
96 $row = $rs->create({ amount => 100 });
97 } 'inserted a money value';
99 is $rs->find($row->id)->amount, 100, 'money value round-trip';
102 $row->update({ amount => 200 });
103 } 'updated a money value';
105 is $rs->find($row->id)->amount, 200, 'updated money value round-trip';
108 $row->update({ amount => undef });
109 } 'updated a money value to NULL';
111 is $rs->find($row->id)->amount, undef,'updated money value to NULL round-trip';
115 $dbh->do("IF OBJECT_ID('artist', 'U') IS NOT NULL DROP TABLE artist")
117 $dbh->do("IF OBJECT_ID('cd', 'U') IS NOT NULL DROP TABLE cd")
119 $dbh->do("IF OBJECT_ID('money_test', 'U') IS NOT NULL DROP TABLE money_test")