10 # tests stolen from 749sybase_asa.t
12 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_FIREBIRD_${_}" } qw/DSN USER PASS/};
13 my ($dsn2, $user2, $pass2) = @ENV{map { "DBICTEST_FIREBIRD_ODBC_${_}" } qw/DSN USER PASS/};
15 plan skip_all => <<'EOF' unless $dsn || $dsn2;
16 Set $ENV{DBICTEST_FIREBIRD_DSN} and/or $ENV{DBICTEST_FIREBIRD_ODBC_DSN},
17 _USER and _PASS to run these tests
21 [ $dsn, $user, $pass ],
22 [ $dsn2, $user2, $pass2 ],
27 foreach my $conn_idx (0..$#info) {
28 my ($dsn, $user, $pass) = @{ $info[$conn_idx] || [] };
32 $schema = DBICTest::Schema->connect($dsn, $user, $pass, {
36 on_connect_call => 'use_softcommit',
38 my $dbh = $schema->storage->dbh;
40 my $sg = Scope::Guard->new(\&cleanup);
42 eval { $dbh->do(q[DROP TABLE "artist"]) };
44 CREATE TABLE "artist" (
45 "artistid" INT PRIMARY KEY,
51 eval { $dbh->do(q[DROP GENERATOR "gen_artist_artistid"]) };
52 $dbh->do('CREATE GENERATOR "gen_artist_artistid"');
53 eval { $dbh->do('DROP TRIGGER "artist_bi"') };
55 CREATE TRIGGER "artist_bi" FOR "artist"
56 ACTIVE BEFORE INSERT POSITION 0
59 IF (NEW."artistid" IS NULL) THEN
60 NEW."artistid" = GEN_ID("gen_artist_artistid",1);
64 my $ars = $schema->resultset('Artist');
65 is ( $ars->count, 0, 'No rows at first' );
67 # test primary key handling
68 my $new = $ars->create({ name => 'foo' });
69 ok($new->artistid, "Auto-PK worked");
76 $ars->create({ name => 'in_savepoint' });
77 die "rolling back savepoint";
80 ok ((not $ars->search({ name => 'in_savepoint' })->first),
81 'savepoint rolled back');
82 $ars->create({ name => 'in_outer_txn' });
83 die "rolling back outer txn";
87 like $@, qr/rolling back outer txn/,
88 'correct exception for rollback';
90 ok ((not $ars->search({ name => 'in_outer_txn' })->first),
91 'outer txn rolled back');
93 # test explicit key spec
94 $new = $ars->create ({ name => 'bar', artistid => 66 });
95 is($new->artistid, 66, 'Explicit PK worked');
96 $new->discard_changes;
97 is($new->artistid, 66, 'Explicit PK assigned');
100 $new->update({ name => 'baz' })
102 $new->discard_changes;
103 is $new->name, 'baz', 'row updated';
109 push @pop, { name => "Artist_$_" };
111 $ars->populate (\@pop);
114 # test populate with explicit key
118 push @pop, { name => "Artist_expkey_$_", artistid => 100 + $_ };
120 $ars->populate (\@pop);
123 # count what we did so far
124 is ($ars->count, 6, 'Simple count works');
128 $ars->search({ name => 'foo' })->update({ rank => 4 });
130 is eval { $ars->search({ name => 'foo' })->first->rank }, 4;
131 } 'Can update a column';
133 my ($updated) = $schema->resultset('Artist')->search({name => 'foo'});
134 is eval { $updated->rank }, 4, 'and the update made it to the database';
138 my $lim = $ars->search( {},
142 order_by => 'artistid'
145 is( $lim->count, 2, 'ROWS+OFFSET count ok' );
146 is( $lim->all, 2, 'Number of ->all objects matches count' );
150 is( eval { $lim->next->artistid }, 101, "iterator->next ok" );
151 is( eval { $lim->next->artistid }, 102, "iterator->next ok" );
152 is( $lim->next, undef, "next past end of resultset ok" );
154 # test multiple executing cursors
156 my $rs1 = $ars->search({}, { order_by => { -asc => 'artistid' }});
157 my $rs2 = $ars->search({}, { order_by => { -desc => 'artistid' }});
159 is $rs1->next->artistid, 1, 'multiple cursors';
160 is $rs2->next->artistid, 102, 'multiple cursors';
165 local $ars->result_source->column_info('artistid')->{is_auto_increment} = 0;
167 lives_ok { $ars->create({}) }
168 'empty insert works';
171 # test blobs (stolen from 73oracle.t)
173 eval { $dbh->do('DROP TABLE "bindtype_test2"') };
175 CREATE TABLE "bindtype_test2"
177 "id" INT PRIMARY KEY,
180 "a_clob" BLOB SUB_TYPE TEXT
184 my %binstr = ( 'small' => join('', map { chr($_) } ( 1 .. 127 )) );
185 $binstr{'large'} = $binstr{'small'} x 1024;
187 my $maxloblen = length $binstr{'large'};
188 local $dbh->{'LongReadLen'} = $maxloblen;
190 my $rs = $schema->resultset('BindType2');
193 foreach my $type (qw( a_blob a_clob )) {
194 foreach my $size (qw( small large )) {
197 # turn off horrendous binary DBIC_TRACE output
198 local $schema->storage->{debug} = 0;
200 lives_ok { $rs->create( { 'id' => $id, $type => $binstr{$size} } ) }
201 "inserted $size $type without dying";
203 ok($rs->find($id)->$type eq $binstr{$size}, "verified inserted $size $type" );
216 $schema->storage->disconnect; # to avoid object FOO is in use errors
217 $dbh = $schema->storage->dbh;
221 eval { $dbh->do('DROP TRIGGER "artist_bi"') };
224 eval { $dbh->do('DROP GENERATOR "gen_artist_artistid"') };
227 foreach my $table (qw/artist bindtype_test/) {
228 eval { $dbh->do(qq[DROP TABLE "$table"]) };