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 $schema = DBICTest::Schema->clone;
34 unless ($storage_type eq 'DBI::Sybase') { # autodetect
35 $schema->storage_type("::$storage_type");
37 $schema->connection($dsn, $user, $pass, {
40 [ blob_setup => log_on_update => 1 ], # this is a safer option
44 $schema->storage->ensure_connected;
45 $schema->storage->_dbh->disconnect;
47 if ($storage_idx == 0 &&
48 $schema->storage->isa('DBIx::Class::Storage::DBI::Sybase::NoBindVars')) {
49 # no placeholders in this version of Sybase or DBD::Sybase
50 my $tb = Test::More->builder;
51 $tb->skip('no placeholders') for 1..$TESTS;
55 isa_ok( $schema->storage, "DBIx::Class::Storage::$storage_type" );
57 lives_ok (sub { $schema->storage->dbh }, 'reconnect works');
59 $schema->storage->dbh_do (sub {
60 my ($storage, $dbh) = @_;
61 eval { $dbh->do("DROP TABLE artist") };
64 artistid INT IDENTITY PRIMARY KEY,
66 rank INT DEFAULT 13 NOT NULL,
67 charfield CHAR(10) NULL
74 # so we start unconnected
75 $schema->storage->disconnect;
77 # test primary key handling
78 my $new = $schema->resultset('Artist')->create({ name => 'foo' });
79 ok($new->artistid > 0, "Auto-PK worked");
81 $seen_id{$new->artistid}++;
84 $new = $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
85 is ( $seen_id{$new->artistid}, undef, "id for Artist $_ is unique" );
86 $seen_id{$new->artistid}++;
90 is ($schema->resultset('Artist')->count, 7, 'count(*) of whole table ok');
93 my $it = $schema->resultset('Artist')->search({
94 artistid => { '>' => 0 }
97 order_by => 'artistid',
100 is( $it->count, 3, "LIMIT count ok" );
102 is( $it->next->name, "foo", "iterator->next ok" );
104 is( $it->next->name, "Artist 2", "iterator->next ok" );
105 is( $it->next, undef, "next past end of resultset ok" );
107 # now try with offset
108 $it = $schema->resultset('Artist')->search({}, {
111 order_by => 'artistid',
114 is( $it->count, 3, "LIMIT with offset count ok" );
116 is( $it->next->name, "Artist 3", "iterator->next ok" );
118 is( $it->next->name, "Artist 5", "iterator->next ok" );
119 is( $it->next, undef, "next past end of resultset ok" );
121 # now try a grouped count
122 $schema->resultset('Artist')->create({ name => 'Artist 6' })
125 $it = $schema->resultset('Artist')->search({}, {
129 is( $it->count, 7, 'COUNT of GROUP_BY ok' );
131 # mostly stolen from the blob stuff Nniuq wrote for t/73oracle.t
133 skip 'Need at least version 1.09 of DBD::Sybase to test TEXT/IMAGE', 12
134 unless $DBD::Sybase::VERSION >= 1.09;
136 my $dbh = $schema->storage->dbh;
138 local $SIG{__WARN__} = sub {};
139 eval { $dbh->do('DROP TABLE bindtype_test') };
142 CREATE TABLE bindtype_test
144 id INT IDENTITY PRIMARY KEY,
149 ],{ RaiseError => 1, PrintError => 0 });
152 my %binstr = ( 'small' => join('', map { chr($_) } ( 1 .. 127 )) );
153 $binstr{'large'} = $binstr{'small'} x 1024;
155 my $maxloblen = length $binstr{'large'};
157 "Localizing LongReadLen to $maxloblen to avoid truncation of test data";
158 local $dbh->{'LongReadLen'} = $maxloblen;
160 my $rs = $schema->resultset('BindType');
163 foreach my $type (qw(blob clob)) {
164 foreach my $size (qw(small large)) {
165 no warnings 'uninitialized';
167 my $created = eval { $rs->create( { $type => $binstr{$size} } ) };
168 ok(!$@, "inserted $size $type without dying");
171 $last_id = $created->id if $created;
174 $rs->search({ id => $last_id }, { select => [$type] })->single->$type
177 ok($got eq $binstr{$size}, "verified inserted $size $type");
183 local $TODO = 'updating TEXT/IMAGE does not work yet';
185 my $new_str = $binstr{large} . 'foo';
186 eval { $rs->search({ id => $last_id })->update({ blob => $new_str }) };
187 ok !$@, 'updated blob successfully';
190 $rs->search({ id => $last_id }, { select => ['blob'] })->single->blob
191 } eq $new_str, "verified updated blob" );
195 # blob insert with explicit PK
197 local $SIG{__WARN__} = sub {};
198 eval { $dbh->do('DROP TABLE bindtype_test') };
201 CREATE TABLE bindtype_test
208 ],{ RaiseError => 1, PrintError => 0 });
210 my $created = eval { $rs->create( { id => 1, blob => $binstr{large} } ) };
211 ok(!$@, "inserted large blob without dying");
215 $rs->search({ id => 1 }, { select => ['blob'] })->single->blob
218 ok($got eq $binstr{large}, "verified inserted large blob");
224 if (my $dbh = eval { $schema->storage->_dbh }) {
225 $dbh->do('DROP TABLE artist');
226 eval { $dbh->do('DROP TABLE bindtype_test') };