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 => (27 + 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;
40 $schema->storage->_dbh->disconnect;
42 isa_ok( $schema->storage, "DBIx::Class::Storage::$storage_type" );
44 lives_ok (sub { $schema->storage->dbh }, 'reconnect works');
46 $schema->storage->dbh_do (sub {
47 my ($storage, $dbh) = @_;
48 eval { $dbh->do("DROP TABLE artist") };
51 artistid INT IDENTITY PRIMARY KEY,
53 rank INT DEFAULT 13 NOT NULL,
54 charfield CHAR(10) NULL
61 # so we start unconnected
62 $schema->storage->disconnect;
64 # test primary key handling
65 my $new = $schema->resultset('Artist')->create({ name => 'foo' });
66 ok($new->artistid > 0, "Auto-PK worked");
68 $seen_id{$new->artistid}++;
71 $new = $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
72 is ( $seen_id{$new->artistid}, undef, "id for Artist $_ is unique" );
73 $seen_id{$new->artistid}++;
77 is ($schema->resultset('Artist')->count, 7, 'count(*) of whole table ok');
80 my $it = $schema->resultset('Artist')->search({
81 artistid => { '>' => 0 }
84 order_by => 'artistid',
87 is( $it->count, 3, "LIMIT count ok" );
89 is( $it->next->name, "foo", "iterator->next ok" );
91 is( $it->next->name, "Artist 2", "iterator->next ok" );
92 is( $it->next, undef, "next past end of resultset ok" );
95 $it = $schema->resultset('Artist')->search({}, {
98 order_by => 'artistid',
101 is( $it->count, 3, "LIMIT with offset count ok" );
103 is( $it->next->name, "Artist 3", "iterator->next ok" );
105 is( $it->next->name, "Artist 5", "iterator->next ok" );
106 is( $it->next, undef, "next past end of resultset ok" );
108 # now try a grouped count
109 $schema->resultset('Artist')->create({ name => 'Artist 6' })
112 $it = $schema->resultset('Artist')->search({}, {
116 is( $it->count, 7, 'COUNT of GROUP_BY ok' );
118 # mostly stole the blob stuff Nniuq wrote for t/73oracle.t
119 my $dbh = $schema->storage->dbh;
121 local $SIG{__WARN__} = sub {};
122 eval { $dbh->do('DROP TABLE bindtype_test') };
125 CREATE TABLE bindtype_test
132 ],{ RaiseError => 1, PrintError => 1 });
135 my %binstr = ( 'small' => join('', map { chr($_) } ( 1 .. 127 )) );
136 $binstr{'large'} = $binstr{'small'} x 1024;
138 my $maxloblen = length $binstr{'large'};
139 note "Localizing LongReadLen to $maxloblen to avoid truncation of test data";
140 local $dbh->{'LongReadLen'} = $maxloblen;
142 my $rs = $schema->resultset('BindType');
145 foreach my $type (qw(blob clob)) {
146 foreach my $size (qw(small large)) {
147 no warnings 'uninitialized';
150 eval { $rs->create( { 'id' => $id, $type => $binstr{$size} } ) };
151 ok(!$@, "inserted $size $type without dying");
155 $rs->search({ id=> $id }, { select => [$type] })->single->$type
156 } eq $binstr{$size}, "verified inserted $size $type" );
163 local $TODO = 'updating TEXT/IMAGE does not work yet';
165 my $new_str = $binstr{large} . 'foo';
166 eval { $rs->search({ id => $id })->update({ blob => $new_str }) };
167 ok !$@, 'updated blob successfully';
170 $rs->search({ id=> $id }, { select => ['blob'] })->single->blob
171 } eq $new_str, "verified updated blob" );
178 if (my $dbh = eval { $schema->storage->_dbh }) {
179 $dbh->do('DROP TABLE artist');
180 $dbh->do('DROP TABLE bindtype_test');