3 no warnings 'uninitialized';
10 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_SYBASE_${_}" } qw/DSN USER PASS/};
12 if (not ($dsn && $user)) {
14 'Set $ENV{DBICTEST_SYBASE_DSN}, _USER and _PASS to run this test' .
15 "\nWarning: This test drops and creates the tables " .
16 "'artist' and 'bindtype_test'";
18 plan tests => (29 + 2)*2;
23 'DBI::Sybase::NoBindVars',
27 for my $storage_type (@storage_types) {
28 $schema = DBICTest::Schema->clone;
30 unless ($storage_type eq 'DBI::Sybase') { # autodetect
31 $schema->storage_type("::$storage_type");
33 $schema->connection($dsn, $user, $pass, {
36 [ blob_setup => log_on_update => 1 ], # this is a safer option
40 $schema->storage->ensure_connected;
41 $schema->storage->_dbh->disconnect;
43 isa_ok( $schema->storage, "DBIx::Class::Storage::$storage_type" );
45 lives_ok (sub { $schema->storage->dbh }, 'reconnect works');
47 $schema->storage->dbh_do (sub {
48 my ($storage, $dbh) = @_;
49 eval { $dbh->do("DROP TABLE artist") };
52 artistid INT IDENTITY PRIMARY KEY,
54 rank INT DEFAULT 13 NOT NULL,
55 charfield CHAR(10) NULL
62 # so we start unconnected
63 $schema->storage->disconnect;
65 # test primary key handling
66 my $new = $schema->resultset('Artist')->create({ name => 'foo' });
67 ok($new->artistid > 0, "Auto-PK worked");
69 $seen_id{$new->artistid}++;
72 $new = $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
73 is ( $seen_id{$new->artistid}, undef, "id for Artist $_ is unique" );
74 $seen_id{$new->artistid}++;
78 is ($schema->resultset('Artist')->count, 7, 'count(*) of whole table ok');
81 my $it = $schema->resultset('Artist')->search({
82 artistid => { '>' => 0 }
85 order_by => 'artistid',
88 is( $it->count, 3, "LIMIT count ok" );
90 is( $it->next->name, "foo", "iterator->next ok" );
92 is( $it->next->name, "Artist 2", "iterator->next ok" );
93 is( $it->next, undef, "next past end of resultset ok" );
96 $it = $schema->resultset('Artist')->search({}, {
99 order_by => 'artistid',
102 is( $it->count, 3, "LIMIT with offset count ok" );
104 is( $it->next->name, "Artist 3", "iterator->next ok" );
106 is( $it->next->name, "Artist 5", "iterator->next ok" );
107 is( $it->next, undef, "next past end of resultset ok" );
109 # now try a grouped count
110 $schema->resultset('Artist')->create({ name => 'Artist 6' })
113 $it = $schema->resultset('Artist')->search({}, {
117 is( $it->count, 7, 'COUNT of GROUP_BY ok' );
119 # mostly stole the blob stuff Nniuq wrote for t/73oracle.t
120 my $dbh = $schema->storage->dbh;
122 local $SIG{__WARN__} = sub {};
123 eval { $dbh->do('DROP TABLE bindtype_test') };
126 CREATE TABLE bindtype_test
128 id INT IDENTITY PRIMARY KEY,
133 ],{ RaiseError => 1, PrintError => 0 });
136 my %binstr = ( 'small' => join('', map { chr($_) } ( 1 .. 127 )) );
137 $binstr{'large'} = $binstr{'small'} x 1024;
139 my $maxloblen = length $binstr{'large'};
140 note "Localizing LongReadLen to $maxloblen to avoid truncation of test data";
141 local $dbh->{'LongReadLen'} = $maxloblen;
143 my $rs = $schema->resultset('BindType');
146 foreach my $type (qw(blob clob)) {
147 foreach my $size (qw(small large)) {
148 no warnings 'uninitialized';
150 my $created = eval { $rs->create( { $type => $binstr{$size} } ) };
151 ok(!$@, "inserted $size $type without dying");
154 $last_id = $created->id if $created;
157 $rs->search({ id => $last_id }, { select => [$type] })->single->$type
160 ok($got eq $binstr{$size}, "verified inserted $size $type");
166 local $TODO = 'updating TEXT/IMAGE does not work yet';
168 my $new_str = $binstr{large} . 'foo';
169 eval { $rs->search({ id => $last_id })->update({ blob => $new_str }) };
170 ok !$@, 'updated blob successfully';
173 $rs->search({ id => $last_id }, { select => ['blob'] })->single->blob
174 } eq $new_str, "verified updated blob" );
178 # blob insert with explicit PK
180 local $SIG{__WARN__} = sub {};
181 eval { $dbh->do('DROP TABLE bindtype_test') };
184 CREATE TABLE bindtype_test
191 ],{ RaiseError => 1, PrintError => 0 });
193 my $created = eval { $rs->create( { id => 1, blob => $binstr{large} } ) };
194 ok(!$@, "inserted large blob without dying");
198 $rs->search({ id => 1 }, { select => ['blob'] })->single->blob
201 ok($got eq $binstr{large}, "verified inserted large blob");
206 if (my $dbh = eval { $schema->storage->_dbh }) {
207 $dbh->do('DROP TABLE artist');
208 $dbh->do('DROP TABLE bindtype_test');