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..1) {
28 my ($dsn, $user, $pass) = @{ $info[$conn_idx] };
32 $schema = DBICTest::Schema->connect($dsn, $user, $pass, {
37 my $dbh = $schema->storage->dbh;
39 my $sg = Scope::Guard->new(\&cleanup);
41 eval { $dbh->do(q[DROP TABLE "artist"]) };
43 CREATE TABLE "artist" (
44 "artistid" INT PRIMARY KEY,
50 eval { $dbh->do(q[DROP GENERATOR "gen_artist_artistid"]) };
51 $dbh->do('CREATE GENERATOR "gen_artist_artistid"');
52 eval { $dbh->do('DROP TRIGGER "artist_bi"') };
54 CREATE TRIGGER "artist_bi" FOR "artist"
55 ACTIVE BEFORE INSERT POSITION 0
58 IF (NEW."artistid" IS NULL) THEN
59 NEW."artistid" = GEN_ID("gen_artist_artistid",1);
63 my $ars = $schema->resultset('Artist');
64 is ( $ars->count, 0, 'No rows at first' );
66 # test primary key handling
67 my $new = $ars->create({ name => 'foo' });
68 ok($new->artistid, "Auto-PK worked");
72 # $schema->txn_do(sub {
74 # $schema->txn_do(sub {
75 # $ars->create({ name => 'in_savepoint' });
76 # die "rolling back savepoint";
79 # ok ((not $ars->search({ name => 'in_savepoint' })->first),
80 # 'savepoint rolled back');
81 # $ars->create({ name => 'in_outer_txn' });
82 # die "rolling back outer txn";
85 # ok ((not $ars->search({ name => 'in_outer_txn' })->first),
86 # 'outer txn rolled back');
88 # test explicit key spec
89 $new = $ars->create ({ name => 'bar', artistid => 66 });
90 is($new->artistid, 66, 'Explicit PK worked');
91 $new->discard_changes;
92 is($new->artistid, 66, 'Explicit PK assigned');
95 $new->update({ name => 'baz' })
97 $new->discard_changes;
98 is $new->name, 'baz', 'row updated';
104 push @pop, { name => "Artist_$_" };
106 $ars->populate (\@pop);
109 # test populate with explicit key
113 push @pop, { name => "Artist_expkey_$_", artistid => 100 + $_ };
115 # XXX why does insert_bulk not work here?
116 my @foo = $ars->populate (\@pop);
119 # count what we did so far
120 is ($ars->count, 6, 'Simple count works');
124 $schema->resultset('Artist')
125 ->search({name => 'foo'})
126 ->update({rank => 4 });
127 } 'Can update a column';
129 my ($updated) = $schema->resultset('Artist')->search({name => 'foo'});
130 is $updated->rank, 4, 'and the update made it to the database';
134 my $lim = $ars->search( {},
138 order_by => 'artistid'
141 is( $lim->count, 2, 'ROWS+OFFSET count ok' );
142 is( $lim->all, 2, 'Number of ->all objects matches count' );
146 is( $lim->next->artistid, 101, "iterator->next ok" );
147 is( $lim->next->artistid, 102, "iterator->next ok" );
148 is( $lim->next, undef, "next past end of resultset ok" );
152 local $ars->result_source->column_info('artistid')->{is_auto_increment} = 0;
154 lives_ok { $ars->create({}) }
155 'empty insert works';
158 # test blobs (stolen from 73oracle.t)
160 eval { $dbh->do('DROP TABLE "bindtype_test2"') };
162 CREATE TABLE "bindtype_test2"
164 "id" INT PRIMARY KEY,
167 "a_clob" BLOB SUB_TYPE TEXT
171 my %binstr = ( 'small' => join('', map { chr($_) } ( 1 .. 127 )) );
172 $binstr{'large'} = $binstr{'small'} x 1024;
174 my $maxloblen = length $binstr{'large'};
175 local $dbh->{'LongReadLen'} = $maxloblen;
177 my $rs = $schema->resultset('BindType2');
180 foreach my $type (qw( a_blob a_clob )) {
181 foreach my $size (qw( small large )) {
184 # turn off horrendous binary DBIC_TRACE output
185 local $schema->storage->{debug} = 0;
187 lives_ok { $rs->create( { 'id' => $id, $type => $binstr{$size} } ) }
188 "inserted $size $type without dying";
190 ok($rs->find($id)->$type eq $binstr{$size}, "verified inserted $size $type" );
203 $schema->storage->disconnect; # to avoid object FOO is in use errors
204 $dbh = $schema->storage->dbh;
208 eval { $dbh->do('DROP TRIGGER "artist_bi"') };
211 eval { $dbh->do('DROP GENERATOR "gen_artist_artistid"') };
214 foreach my $table (qw/"artist" "bindtype_test"/) {
215 eval { $dbh->do(q[DROP TABLE "$table"]) };