9 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_SYBASE_${_}" } qw/DSN USER PASS/};
11 if (not ($dsn && $user)) {
13 'Set $ENV{DBICTEST_SYBASE_DSN}, _USER and _PASS to run this test' .
14 "\nWarning: This test drops and creates the tables " .
15 "'artist' and 'bindtype_test'";
17 plan tests => (26 + 2)*2;
22 'DBI::Sybase::NoBindVars',
26 for my $storage_type (@storage_types) {
27 $schema = DBICTest::Schema->clone;
29 unless ($storage_type eq 'DBI::Sybase') { # autodetect
30 $schema->storage_type("::$storage_type");
32 $schema->connection($dsn, $user, $pass, {
35 [ blob_setup => log_on_update => 1 ], # this is a safer option
39 $schema->storage->ensure_connected;
41 isa_ok( $schema->storage, "DBIx::Class::Storage::$storage_type" );
43 $schema->storage->dbh_do (sub {
44 my ($storage, $dbh) = @_;
45 eval { $dbh->do("DROP TABLE artist") };
48 artistid INT IDENTITY PRIMARY KEY,
50 rank INT DEFAULT 13 NOT NULL,
51 charfield CHAR(10) NULL
58 # so we start unconnected
59 $schema->storage->disconnect;
61 # test primary key handling
62 my $new = $schema->resultset('Artist')->create({ name => 'foo' });
63 ok($new->artistid > 0, "Auto-PK worked");
65 $seen_id{$new->artistid}++;
68 $new = $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
69 is ( $seen_id{$new->artistid}, undef, "id for Artist $_ is unique" );
70 $seen_id{$new->artistid}++;
74 is ($schema->resultset('Artist')->count, 7, 'count(*) of whole table ok');
77 my $it = $schema->resultset('Artist')->search({
78 artistid => { '>' => 0 }
81 order_by => 'artistid',
84 is( $it->count, 3, "LIMIT count ok" );
86 is( $it->next->name, "foo", "iterator->next ok" );
88 is( $it->next->name, "Artist 2", "iterator->next ok" );
89 is( $it->next, undef, "next past end of resultset ok" );
92 $it = $schema->resultset('Artist')->search({}, {
95 order_by => 'artistid',
98 is( $it->count, 3, "LIMIT with offset count ok" );
100 is( $it->next->name, "Artist 3", "iterator->next ok" );
102 is( $it->next->name, "Artist 5", "iterator->next ok" );
103 is( $it->next, undef, "next past end of resultset ok" );
105 # now try a grouped count
106 $schema->resultset('Artist')->create({ name => 'Artist 6' })
109 $it = $schema->resultset('Artist')->search({}, {
113 is( $it->count, 7, 'COUNT of GROUP_BY ok' );
115 # mostly stole the blob stuff Nniuq wrote for t/73oracle.t
116 my $dbh = $schema->storage->dbh;
118 local $SIG{__WARN__} = sub {};
119 eval { $dbh->do('DROP TABLE bindtype_test') };
122 CREATE TABLE bindtype_test
129 ],{ RaiseError => 1, PrintError => 1 });
132 my %binstr = ( 'small' => join('', map { chr($_) } ( 1 .. 127 )) );
133 $binstr{'large'} = $binstr{'small'} x 1024;
135 my $maxloblen = length $binstr{'large'};
136 note "Localizing LongReadLen to $maxloblen to avoid truncation of test data";
137 local $dbh->{'LongReadLen'} = $maxloblen;
139 my $rs = $schema->resultset('BindType');
142 foreach my $type (qw(blob clob)) {
143 foreach my $size (qw(small large)) {
144 no warnings 'uninitialized';
147 eval { $rs->create( { 'id' => $id, $type => $binstr{$size} } ) };
148 ok(!$@, "inserted $size $type without dying");
152 $rs->search({ id=> $id }, { select => [$type] })->single->$type
153 } eq $binstr{$size}, "verified inserted $size $type" );
159 local $TODO = 'updating TEXT/IMAGE does not work yet';
161 my $new_str = $binstr{large} . 'foo';
162 eval { $rs->search({ id => $id })->update({ blob => $new_str }) };
163 ok !$@, 'updated blob successfully';
166 $rs->search({ id=> $id }, { select => ['blob'] })->single->blob
167 } eq $new_str, "verified updated blob" );
174 if (my $dbh = eval { $schema->storage->_dbh }) {
175 $dbh->do('DROP TABLE artist');
176 $dbh->do('DROP TABLE bindtype_test');