1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
9 use DBIx::Class::Optional::Dependencies ();
10 use DBIx::Class::_Util 'scope_guard';
14 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_SQLANYWHERE_${_}" } qw/DSN USER PASS/};
15 my ($dsn2, $user2, $pass2) = @ENV{map { "DBICTEST_SQLANYWHERE_ODBC_${_}" } qw/DSN USER PASS/};
17 plan skip_all => 'Test needs ' .
18 (join ' or ', map { $_ ? $_ : () }
19 DBIx::Class::Optional::Dependencies->req_missing_for('test_rdbms_sqlanywhere'),
20 DBIx::Class::Optional::Dependencies->req_missing_for('test_rdbms_sqlanywhere_odbc'))
22 $dsn && DBIx::Class::Optional::Dependencies->req_ok_for('test_rdbms_sqlanywhere')
24 $dsn2 && DBIx::Class::Optional::Dependencies->req_ok_for('test_rdbms_sqlanywhere_odbc')
28 DBICTest::Schema->load_classes('ArtistGUID');
30 # tests stolen from 748informix.t
32 plan skip_all => <<'EOF' unless $dsn || $dsn2;
33 Set $ENV{DBICTEST_SQLANYWHERE_DSN} and/or $ENV{DBICTEST_SQLANYWHERE_ODBC_DSN},
34 _USER and _PASS to run these tests
38 [ $dsn, $user, $pass ],
39 [ $dsn2, $user2, $pass2 ],
44 foreach my $info (@info) {
45 my ($dsn, $user, $pass) = @$info;
49 $schema = DBICTest::Schema->connect($dsn, $user, $pass, {
53 my $guard = scope_guard { cleanup($schema) };
55 my $dbh = $schema->storage->dbh;
57 eval { $dbh->do("DROP TABLE artist") };
61 artistid INT IDENTITY PRIMARY KEY,
62 name VARCHAR(255) NULL,
63 charfield CHAR(10) NULL,
68 my $ars = $schema->resultset('Artist');
69 is ( $ars->count, 0, 'No rows at first' );
71 # test primary key handling
72 my $new = $ars->create({ name => 'foo' });
73 ok($new->artistid, "Auto-PK worked");
75 # test explicit key spec
76 $new = $ars->create ({ name => 'bar', artistid => 66 });
77 is($new->artistid, 66, 'Explicit PK worked');
78 $new->discard_changes;
79 is($new->artistid, 66, 'Explicit PK assigned');
86 $ars->create({ name => 'in_savepoint' });
87 die "rolling back savepoint";
90 ok ((not $ars->search({ name => 'in_savepoint' })->first),
91 'savepoint rolled back');
92 $ars->create({ name => 'in_outer_txn' });
93 die "rolling back outer txn";
95 } qr/rolling back outer txn/,
96 'correct exception for rollback';
98 ok ((not $ars->search({ name => 'in_outer_txn' })->first),
99 'outer txn rolled back');
105 push @pop, { name => "Artist_$_" };
107 $ars->populate (\@pop);
110 # test populate with explicit key
114 push @pop, { name => "Artist_expkey_$_", artistid => 100 + $_ };
116 $ars->populate (\@pop);
119 # count what we did so far
120 is ($ars->count, 6, 'Simple count works');
123 my $lim = $ars->search( {},
127 order_by => 'artistid'
130 is( $lim->count, 2, 'ROWS+OFFSET count ok' );
131 is( $lim->all, 2, 'Number of ->all objects matches count' );
135 is( $lim->next->artistid, 101, "iterator->next ok" );
136 is( $lim->next->artistid, 102, "iterator->next ok" );
137 is( $lim->next, undef, "next past end of resultset ok" );
141 local $ars->result_source->column_info('artistid')->{is_auto_increment} = 0;
143 lives_ok { $ars->create({}) }
144 'empty insert works';
147 # test blobs (stolen from 73oracle.t)
148 eval { $dbh->do('DROP TABLE bindtype_test') };
150 CREATE TABLE bindtype_test
152 id INT NOT NULL PRIMARY KEY,
154 blob LONG BINARY NULL,
155 clob LONG VARCHAR NULL,
158 ],{ RaiseError => 1, PrintError => 1 });
160 my %binstr = ( 'small' => join('', map { chr($_) } ( 1 .. 127 )) );
161 $binstr{'large'} = $binstr{'small'} x 1024;
163 my $maxloblen = length $binstr{'large'};
164 local $dbh->{'LongReadLen'} = $maxloblen;
166 my $rs = $schema->resultset('BindType');
169 foreach my $type (qw( blob clob )) {
170 foreach my $size (qw( small large )) {
173 # turn off horrendous binary DBIC_TRACE output
174 local $schema->storage->{debug} = 0;
176 lives_ok { $rs->create( { 'id' => $id, $type => $binstr{$size} } ) }
177 "inserted $size $type without dying";
179 ok($rs->find($id)->$type eq $binstr{$size}, "verified inserted $size $type" );
183 my @uuid_types = qw/uniqueidentifier uniqueidentifierstr/;
185 # test uniqueidentifiers (and the cursor_class).
187 for my $uuid_type (@uuid_types) {
188 local $schema->source('ArtistGUID')->column_info('artistid')->{data_type}
191 local $schema->source('ArtistGUID')->column_info('a_guid')->{data_type}
194 $schema->storage->dbh_do (sub {
195 my ($storage, $dbh) = @_;
196 eval { $dbh->do("DROP TABLE artist_guid") };
198 CREATE TABLE artist_guid (
199 artistid $uuid_type NOT NULL,
201 rank INT NOT NULL DEFAULT '13',
202 charfield CHAR(10) NULL,
204 primary key(artistid)
209 local $TODO = 'something wrong with uniqueidentifierstr over ODBC'
210 if $dsn =~ /:ODBC:/ && $uuid_type eq 'uniqueidentifierstr';
214 $row = $schema->resultset('ArtistGUID')->create({ name => 'mtfnpy' })
215 } 'created a row with a GUID';
218 eval { $row->artistid },
219 'row has GUID PK col populated',
224 eval { $row->a_guid },
225 'row has a GUID col with auto_nextval populated',
229 my $row_from_db = try { $schema->resultset('ArtistGUID')
230 ->search({ name => 'mtfnpy' })->first }
233 is try { $row_from_db->artistid }, $row->artistid,
234 'PK GUID round trip (via ->search->next)';
236 is try { $row_from_db->a_guid }, $row->a_guid,
237 'NON-PK GUID round trip (via ->search->next)';
239 $row_from_db = try { $schema->resultset('ArtistGUID')
240 ->find($row->artistid) }
243 is try { $row_from_db->artistid }, $row->artistid,
244 'PK GUID round trip (via ->find)';
246 is try { $row_from_db->a_guid }, $row->a_guid,
247 'NON-PK GUID round trip (via ->find)';
249 ($row_from_db) = try { $schema->resultset('ArtistGUID')
250 ->search({ name => 'mtfnpy' })->all }
253 is try { $row_from_db->artistid }, $row->artistid,
254 'PK GUID round trip (via ->search->all)';
256 is try { $row_from_db->a_guid }, $row->a_guid,
257 'NON-PK GUID round trip (via ->search->all)';
265 eval { $schema->storage->dbh->do("DROP TABLE $_") }
266 for qw/artist artist_guid bindtype_test/;