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 $info (@info) {
28 my ($dsn, $user, $pass) = @$info;
32 my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
34 my $dbh = $schema->storage->dbh;
36 push @handles_to_clean, $dbh;
38 my $sg = Scope::Guard->new(\&cleanup);
40 eval { $dbh->do("DROP TABLE artist") };
43 artistid INT PRIMARY KEY,
49 eval { $dbh->do("DROP GENERATOR gen_artist_artistid") };
50 $dbh->do('CREATE GENERATOR gen_artist_artistid');
51 eval { $dbh->do("DROP TRIGGER artist_bi") };
53 CREATE TRIGGER artist_bi FOR artist
54 ACTIVE BEFORE INSERT POSITION 0
57 IF (NEW.artistid IS NULL) THEN
58 NEW.artistid = GEN_ID(gen_artist_artistid,1);
62 my $ars = $schema->resultset('Artist');
63 is ( $ars->count, 0, 'No rows at first' );
65 # test primary key handling
66 my $new = $ars->create({ name => 'foo' });
67 ok($new->artistid, "Auto-PK worked");
69 # test explicit key spec
70 $new = $ars->create ({ name => 'bar', artistid => 66 });
71 is($new->artistid, 66, 'Explicit PK worked');
72 $new->discard_changes;
73 is($new->artistid, 66, 'Explicit PK assigned');
79 push @pop, { name => "Artist_$_" };
81 $ars->populate (\@pop);
84 # test populate with explicit key
88 push @pop, { name => "Artist_expkey_$_", artistid => 100 + $_ };
90 $ars->populate (\@pop);
93 # count what we did so far
94 is ($ars->count, 6, 'Simple count works');
97 my $lim = $ars->search( {},
101 order_by => 'artistid'
104 is( $lim->count, 2, 'ROWS+OFFSET count ok' );
105 is( $lim->all, 2, 'Number of ->all objects matches count' );
109 is( $lim->next->artistid, 101, "iterator->next ok" );
110 is( $lim->next->artistid, 102, "iterator->next ok" );
111 is( $lim->next, undef, "next past end of resultset ok" );
115 local $ars->result_source->column_info('artistid')->{is_auto_increment} = 0;
117 lives_ok { $ars->create({}) }
118 'empty insert works';
121 # test blobs (stolen from 73oracle.t)
122 eval { $dbh->do('DROP TABLE bindtype_test') };
124 CREATE TABLE bindtype_test
126 id INT NOT NULL PRIMARY KEY,
133 my %binstr = ( 'small' => join('', map { chr($_) } ( 1 .. 127 )) );
134 $binstr{'large'} = $binstr{'small'} x 1024;
136 my $maxloblen = length $binstr{'large'};
137 local $dbh->{'LongReadLen'} = $maxloblen;
139 my $rs = $schema->resultset('BindType');
142 foreach my $type (qw( blob clob )) {
143 foreach my $size (qw( small large )) {
146 # turn off horrendous binary DBIC_TRACE output
147 local $schema->storage->{debug} = 0;
149 lives_ok { $rs->create( { 'id' => $id, $type => $binstr{$size} } ) }
150 "inserted $size $type without dying";
152 ok($rs->find($id)->$type eq $binstr{$size}, "verified inserted $size $type" );
162 foreach my $dbh (@handles_to_clean) {
163 eval { $dbh->do('DROP TRIGGER artist_bi') };
165 eval { $dbh->do('DROP GENERATOR gen_artist_artistid') };
167 foreach my $table (qw/artist bindtype_test/) {
168 $dbh->do("DROP TABLE $table");