8 use DBIx::Class::Optional::Dependencies ();
12 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_SQLANYWHERE_${_}" } qw/DSN USER PASS/};
13 my ($dsn2, $user2, $pass2) = @ENV{map { "DBICTEST_SQLANYWHERE_ODBC_${_}" } qw/DSN USER PASS/};
15 plan skip_all => 'Test needs ' .
16 (join ' or ', map { $_ ? $_ : () }
17 DBIx::Class::Optional::Dependencies->req_missing_for('test_rdbms_sqlanywhere'),
18 DBIx::Class::Optional::Dependencies->req_missing_for('test_rdbms_sqlanywhere_odbc'))
20 $dsn && DBIx::Class::Optional::Dependencies->req_ok_for('test_rdbms_sqlanywhere')
22 $dsn2 && DBIx::Class::Optional::Dependencies->req_ok_for('test_rdbms_sqlanywhere_odbc')
26 DBICTest::Schema->load_classes('ArtistGUID');
28 # tests stolen from 748informix.t
30 plan skip_all => <<'EOF' unless $dsn || $dsn2;
31 Set $ENV{DBICTEST_SQLANYWHERE_DSN} and/or $ENV{DBICTEST_SQLANYWHERE_ODBC_DSN},
32 _USER and _PASS to run these tests
36 [ $dsn, $user, $pass ],
37 [ $dsn2, $user2, $pass2 ],
42 foreach my $info (@info) {
43 my ($dsn, $user, $pass) = @$info;
47 $schema = DBICTest::Schema->connect($dsn, $user, $pass, {
51 my $guard = Scope::Guard->new(sub{ cleanup($schema) });
53 my $dbh = $schema->storage->dbh;
55 eval { $dbh->do("DROP TABLE artist") };
59 artistid INT IDENTITY PRIMARY KEY,
60 name VARCHAR(255) NULL,
61 charfield CHAR(10) NULL,
66 my $ars = $schema->resultset('Artist');
67 is ( $ars->count, 0, 'No rows at first' );
69 # test primary key handling
70 my $new = $ars->create({ name => 'foo' });
71 ok($new->artistid, "Auto-PK worked");
73 # test explicit key spec
74 $new = $ars->create ({ name => 'bar', artistid => 66 });
75 is($new->artistid, 66, 'Explicit PK worked');
76 $new->discard_changes;
77 is($new->artistid, 66, 'Explicit PK assigned');
84 $ars->create({ name => 'in_savepoint' });
85 die "rolling back savepoint";
88 ok ((not $ars->search({ name => 'in_savepoint' })->first),
89 'savepoint rolled back');
90 $ars->create({ name => 'in_outer_txn' });
91 die "rolling back outer txn";
93 } qr/rolling back outer txn/,
94 'correct exception for rollback';
96 ok ((not $ars->search({ name => 'in_outer_txn' })->first),
97 'outer txn rolled back');
103 push @pop, { name => "Artist_$_" };
105 $ars->populate (\@pop);
108 # test populate with explicit key
112 push @pop, { name => "Artist_expkey_$_", artistid => 100 + $_ };
114 $ars->populate (\@pop);
117 # count what we did so far
118 is ($ars->count, 6, 'Simple count works');
121 my $lim = $ars->search( {},
125 order_by => 'artistid'
128 is( $lim->count, 2, 'ROWS+OFFSET count ok' );
129 is( $lim->all, 2, 'Number of ->all objects matches count' );
133 is( $lim->next->artistid, 101, "iterator->next ok" );
134 is( $lim->next->artistid, 102, "iterator->next ok" );
135 is( $lim->next, undef, "next past end of resultset ok" );
139 local $ars->result_source->column_info('artistid')->{is_auto_increment} = 0;
141 lives_ok { $ars->create({}) }
142 'empty insert works';
145 # test blobs (stolen from 73oracle.t)
146 eval { $dbh->do('DROP TABLE bindtype_test') };
148 CREATE TABLE bindtype_test
150 id INT NOT NULL PRIMARY KEY,
152 blob LONG BINARY NULL,
153 clob LONG VARCHAR NULL,
156 ],{ RaiseError => 1, PrintError => 1 });
158 my %binstr = ( 'small' => join('', map { chr($_) } ( 1 .. 127 )) );
159 $binstr{'large'} = $binstr{'small'} x 1024;
161 my $maxloblen = length $binstr{'large'};
162 local $dbh->{'LongReadLen'} = $maxloblen;
164 my $rs = $schema->resultset('BindType');
167 foreach my $type (qw( blob clob )) {
168 foreach my $size (qw( small large )) {
171 # turn off horrendous binary DBIC_TRACE output
172 local $schema->storage->{debug} = 0;
174 lives_ok { $rs->create( { 'id' => $id, $type => $binstr{$size} } ) }
175 "inserted $size $type without dying";
177 ok($rs->find($id)->$type eq $binstr{$size}, "verified inserted $size $type" );
181 my @uuid_types = qw/uniqueidentifier uniqueidentifierstr/;
183 # test uniqueidentifiers (and the cursor_class).
185 for my $uuid_type (@uuid_types) {
186 local $schema->source('ArtistGUID')->column_info('artistid')->{data_type}
189 local $schema->source('ArtistGUID')->column_info('a_guid')->{data_type}
192 $schema->storage->dbh_do (sub {
193 my ($storage, $dbh) = @_;
194 eval { $dbh->do("DROP TABLE artist_guid") };
196 CREATE TABLE artist_guid (
197 artistid $uuid_type NOT NULL,
199 rank INT NOT NULL DEFAULT '13',
200 charfield CHAR(10) NULL,
202 primary key(artistid)
207 local $TODO = 'something wrong with uniqueidentifierstr over ODBC'
208 if $dsn =~ /:ODBC:/ && $uuid_type eq 'uniqueidentifierstr';
212 $row = $schema->resultset('ArtistGUID')->create({ name => 'mtfnpy' })
213 } 'created a row with a GUID';
216 eval { $row->artistid },
217 'row has GUID PK col populated',
222 eval { $row->a_guid },
223 'row has a GUID col with auto_nextval populated',
227 my $row_from_db = try { $schema->resultset('ArtistGUID')
228 ->search({ name => 'mtfnpy' })->first }
231 is try { $row_from_db->artistid }, $row->artistid,
232 'PK GUID round trip (via ->search->next)';
234 is try { $row_from_db->a_guid }, $row->a_guid,
235 'NON-PK GUID round trip (via ->search->next)';
237 $row_from_db = try { $schema->resultset('ArtistGUID')
238 ->find($row->artistid) }
241 is try { $row_from_db->artistid }, $row->artistid,
242 'PK GUID round trip (via ->find)';
244 is try { $row_from_db->a_guid }, $row->a_guid,
245 'NON-PK GUID round trip (via ->find)';
247 ($row_from_db) = try { $schema->resultset('ArtistGUID')
248 ->search({ name => 'mtfnpy' })->all }
251 is try { $row_from_db->artistid }, $row->artistid,
252 'PK GUID round trip (via ->search->all)';
254 is try { $row_from_db->a_guid }, $row->a_guid,
255 'NON-PK GUID round trip (via ->search->all)';
263 eval { $schema->storage->dbh->do("DROP TABLE $_") }
264 for qw/artist artist_guid bindtype_test/;