1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
8 use DBIx::Class::Optional::Dependencies ();
9 use DBIx::Class::_Util 'scope_guard';
13 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_SQLANYWHERE_${_}" } qw/DSN USER PASS/};
14 my ($dsn2, $user2, $pass2) = @ENV{map { "DBICTEST_SQLANYWHERE_ODBC_${_}" } qw/DSN USER PASS/};
16 plan skip_all => 'Test needs ' .
17 (join ' or ', map { $_ ? $_ : () }
18 DBIx::Class::Optional::Dependencies->req_missing_for('test_rdbms_sqlanywhere'),
19 DBIx::Class::Optional::Dependencies->req_missing_for('test_rdbms_sqlanywhere_odbc'))
21 $dsn && DBIx::Class::Optional::Dependencies->req_ok_for('test_rdbms_sqlanywhere')
23 $dsn2 && DBIx::Class::Optional::Dependencies->req_ok_for('test_rdbms_sqlanywhere_odbc')
27 DBICTest::Schema->load_classes('ArtistGUID');
29 # tests stolen from 748informix.t
31 plan skip_all => <<'EOF' unless $dsn || $dsn2;
32 Set $ENV{DBICTEST_SQLANYWHERE_DSN} and/or $ENV{DBICTEST_SQLANYWHERE_ODBC_DSN},
33 _USER and _PASS to run these tests
37 [ $dsn, $user, $pass ],
38 [ $dsn2, $user2, $pass2 ],
43 foreach my $info (@info) {
44 my ($dsn, $user, $pass) = @$info;
48 $schema = DBICTest::Schema->connect($dsn, $user, $pass, {
52 my $guard = scope_guard { cleanup($schema) };
54 my $dbh = $schema->storage->dbh;
56 eval { $dbh->do("DROP TABLE artist") };
60 artistid INT IDENTITY PRIMARY KEY,
61 name VARCHAR(255) NULL,
62 charfield CHAR(10) NULL,
67 my $ars = $schema->resultset('Artist');
68 is ( $ars->count, 0, 'No rows at first' );
70 # test primary key handling
71 my $new = $ars->create({ name => 'foo' });
72 ok($new->artistid, "Auto-PK worked");
74 # test explicit key spec
75 $new = $ars->create ({ name => 'bar', artistid => 66 });
76 is($new->artistid, 66, 'Explicit PK worked');
77 $new->discard_changes;
78 is($new->artistid, 66, 'Explicit PK assigned');
85 $ars->create({ name => 'in_savepoint' });
86 die "rolling back savepoint";
89 ok ((not $ars->search({ name => 'in_savepoint' })->first),
90 'savepoint rolled back');
91 $ars->create({ name => 'in_outer_txn' });
92 die "rolling back outer txn";
94 } qr/rolling back outer txn/,
95 'correct exception for rollback';
97 ok ((not $ars->search({ name => 'in_outer_txn' })->first),
98 'outer txn rolled back');
104 push @pop, { name => "Artist_$_" };
106 $ars->populate (\@pop);
109 # test populate with explicit key
113 push @pop, { name => "Artist_expkey_$_", artistid => 100 + $_ };
115 $ars->populate (\@pop);
118 # count what we did so far
119 is ($ars->count, 6, 'Simple count works');
122 my $lim = $ars->search( {},
126 order_by => 'artistid'
129 is( $lim->count, 2, 'ROWS+OFFSET count ok' );
130 is( $lim->all, 2, 'Number of ->all objects matches count' );
134 is( $lim->next->artistid, 101, "iterator->next ok" );
135 is( $lim->next->artistid, 102, "iterator->next ok" );
136 is( $lim->next, undef, "next past end of resultset ok" );
140 local $ars->result_source->column_info('artistid')->{is_auto_increment} = 0;
142 lives_ok { $ars->create({}) }
143 'empty insert works';
146 # test blobs (stolen from 73oracle.t)
147 eval { $dbh->do('DROP TABLE bindtype_test') };
149 CREATE TABLE bindtype_test
151 id INT NOT NULL PRIMARY KEY,
153 blob LONG BINARY NULL,
154 clob LONG VARCHAR NULL,
157 ],{ RaiseError => 1, PrintError => 1 });
159 my %binstr = ( 'small' => join('', map { chr($_) } ( 1 .. 127 )) );
160 $binstr{'large'} = $binstr{'small'} x 1024;
162 my $maxloblen = length $binstr{'large'};
163 local $dbh->{'LongReadLen'} = $maxloblen;
165 my $rs = $schema->resultset('BindType');
168 foreach my $type (qw( blob clob )) {
169 foreach my $size (qw( small large )) {
172 # turn off horrendous binary DBIC_TRACE output
173 local $schema->storage->{debug} = 0;
175 lives_ok { $rs->create( { 'id' => $id, $type => $binstr{$size} } ) }
176 "inserted $size $type without dying";
178 ok($rs->find($id)->$type eq $binstr{$size}, "verified inserted $size $type" );
182 my @uuid_types = qw/uniqueidentifier uniqueidentifierstr/;
184 # test uniqueidentifiers (and the cursor_class).
186 for my $uuid_type (@uuid_types) {
187 local $schema->source('ArtistGUID')->column_info('artistid')->{data_type}
190 local $schema->source('ArtistGUID')->column_info('a_guid')->{data_type}
193 $schema->storage->dbh_do (sub {
194 my ($storage, $dbh) = @_;
195 eval { $dbh->do("DROP TABLE artist_guid") };
197 CREATE TABLE artist_guid (
198 artistid $uuid_type NOT NULL,
200 rank INT NOT NULL DEFAULT '13',
201 charfield CHAR(10) NULL,
203 primary key(artistid)
208 local $TODO = 'something wrong with uniqueidentifierstr over ODBC'
209 if $dsn =~ /:ODBC:/ && $uuid_type eq 'uniqueidentifierstr';
213 $row = $schema->resultset('ArtistGUID')->create({ name => 'mtfnpy' })
214 } 'created a row with a GUID';
217 eval { $row->artistid },
218 'row has GUID PK col populated',
223 eval { $row->a_guid },
224 'row has a GUID col with auto_nextval populated',
230 $row_from_db = $schema->resultset('ArtistGUID')->search({ name => 'mtfnpy' })->first
234 eval { $row_from_db->artistid },
236 'PK GUID round trip (via ->search->next)'
240 eval { $row_from_db->a_guid },
242 'NON-PK GUID round trip (via ->search->next)'
246 $row_from_db = $schema->resultset('ArtistGUID')->find($row->artistid)
250 eval { $row_from_db->artistid },
252 'PK GUID round trip (via ->find)'
256 eval { $row_from_db->a_guid },
258 'NON-PK GUID round trip (via ->find)'
262 ($row_from_db) = $schema->resultset('ArtistGUID')->search({ name => 'mtfnpy' })->all
266 eval { $row_from_db->artistid },
268 'PK GUID round trip (via ->search->all)'
272 eval { $row_from_db->a_guid },
274 'NON-PK GUID round trip (via ->search->all)'
283 eval { $schema->storage->dbh->do("DROP TABLE $_") }
284 for qw/artist artist_guid bindtype_test/;