3 no warnings 'uninitialized';
10 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_SYBASE_${_}" } qw/DSN USER PASS/};
14 if (not ($dsn && $user)) {
16 'Set $ENV{DBICTEST_SYBASE_DSN}, _USER and _PASS to run this test' .
17 "\nWarning: This test drops and creates the tables " .
18 "'artist' and 'bindtype_test'";
20 plan tests => $TESTS*2;
25 'DBI::Sybase::NoBindVars',
30 for my $storage_type (@storage_types) {
32 # this is so we can set ->storage_type before connecting
33 my $schema = DBICTest::Schema->clone;
35 unless ($storage_type eq 'DBI::Sybase') { # autodetect
36 $schema->storage_type("::$storage_type");
39 $schema->connection($dsn, $user, $pass, {
42 [ blob_setup => log_on_update => 1 ], # this is a safer option
46 $schema->storage->ensure_connected;
48 if ($storage_idx == 0 &&
49 $schema->storage->isa('DBIx::Class::Storage::DBI::Sybase::NoBindVars')) {
50 # no placeholders in this version of Sybase or DBD::Sybase (or using FreeTDS)
51 my $tb = Test::More->builder;
52 $tb->skip('no placeholders') for 1..$TESTS;
56 isa_ok( $schema->storage, "DBIx::Class::Storage::$storage_type" );
58 $schema->storage->_dbh->disconnect;
59 lives_ok (sub { $schema->storage->dbh }, 'reconnect works');
61 $schema->storage->dbh_do (sub {
62 my ($storage, $dbh) = @_;
63 eval { $dbh->do("DROP TABLE artist") };
66 artistid INT IDENTITY PRIMARY KEY,
68 rank INT DEFAULT 13 NOT NULL,
69 charfield CHAR(10) NULL
76 # so we start unconnected
77 $schema->storage->disconnect;
79 # test primary key handling
80 my $new = $schema->resultset('Artist')->create({ name => 'foo' });
81 ok($new->artistid > 0, "Auto-PK worked");
83 $seen_id{$new->artistid}++;
86 $new = $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
87 is ( $seen_id{$new->artistid}, undef, "id for Artist $_ is unique" );
88 $seen_id{$new->artistid}++;
92 is ($schema->resultset('Artist')->count, 7, 'count(*) of whole table ok');
95 my $it = $schema->resultset('Artist')->search({
96 artistid => { '>' => 0 }
99 order_by => 'artistid',
102 is( $it->count, 3, "LIMIT count ok" );
104 is( $it->next->name, "foo", "iterator->next ok" );
106 is( $it->next->name, "Artist 2", "iterator->next ok" );
107 is( $it->next, undef, "next past end of resultset ok" );
109 # now try with offset
110 $it = $schema->resultset('Artist')->search({}, {
113 order_by => 'artistid',
116 is( $it->count, 3, "LIMIT with offset count ok" );
118 is( $it->next->name, "Artist 3", "iterator->next ok" );
120 is( $it->next->name, "Artist 5", "iterator->next ok" );
121 is( $it->next, undef, "next past end of resultset ok" );
123 # now try a grouped count
124 $schema->resultset('Artist')->create({ name => 'Artist 6' })
127 $it = $schema->resultset('Artist')->search({}, {
131 is( $it->count, 7, 'COUNT of GROUP_BY ok' );
133 # mostly stolen from the blob stuff Nniuq wrote for t/73oracle.t
135 skip 'TEXT/IMAGE support does not work with FreeTDS', 12
136 if $schema->storage->_using_freetds;
138 my $dbh = $schema->storage->dbh;
140 local $SIG{__WARN__} = sub {};
141 eval { $dbh->do('DROP TABLE bindtype_test') };
144 CREATE TABLE bindtype_test
146 id INT IDENTITY PRIMARY KEY,
151 ],{ RaiseError => 1, PrintError => 0 });
154 my %binstr = ( 'small' => join('', map { chr($_) } ( 1 .. 127 )) );
155 $binstr{'large'} = $binstr{'small'} x 1024;
157 my $maxloblen = length $binstr{'large'};
159 "Localizing LongReadLen to $maxloblen to avoid truncation of test data";
160 local $dbh->{'LongReadLen'} = $maxloblen * 2;
162 my $rs = $schema->resultset('BindType');
165 foreach my $type (qw(blob clob)) {
166 foreach my $size (qw(small large)) {
167 no warnings 'uninitialized';
169 my $created = eval { $rs->create( { $type => $binstr{$size} } ) };
170 ok(!$@, "inserted $size $type without dying");
173 $last_id = $created->id if $created;
176 $rs->find($last_id)->$type
179 ok($got eq $binstr{$size}, "verified inserted $size $type");
183 # blob insert with explicit PK
184 # also a good opportunity to test IDENTITY_INSERT
186 local $SIG{__WARN__} = sub {};
187 eval { $dbh->do('DROP TABLE bindtype_test') };
190 CREATE TABLE bindtype_test
192 id INT IDENTITY PRIMARY KEY,
197 ],{ RaiseError => 1, PrintError => 0 });
199 my $created = eval { $rs->create( { id => 1, blob => $binstr{large} } ) };
200 ok(!$@, "inserted large blob without dying with manual PK");
207 ok($got eq $binstr{large}, "verified inserted large blob with manual PK");
210 my $new_str = $binstr{large} . 'mtfnpy';
211 eval { $rs->search({ id => 1 })->update({ blob => $new_str }) };
212 ok !$@, 'updated blob successfully';
218 ok($got eq $new_str, "verified updated blob");
224 if (my $dbh = eval { $schema->storage->_dbh }) {
225 $dbh->do('DROP TABLE artist');
226 eval { $dbh->do('DROP TABLE bindtype_test') };