better DT inflation for Firebird and _ping
[dbsrgits/DBIx-Class.git] / t / 750firebird.t
index 44efe7c..0c98f95 100644 (file)
@@ -22,19 +22,18 @@ my @info = (
   [ $dsn2, $user2, $pass2 ],
 );
 
-my @handles_to_clean;
+my $schema;
 
-foreach my $info (@info) {
-  my ($dsn, $user, $pass) = @$info;
+foreach my $conn_idx (0..1) {
+  my ($dsn, $user, $pass) = @{ $info[$conn_idx] };
 
   next unless $dsn;
 
-  my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
-
+  $schema = DBICTest::Schema->connect($dsn, $user, $pass, {
+    auto_savepoint => 1
+  });
   my $dbh = $schema->storage->dbh;
 
-  push @handles_to_clean, $dbh;
-
   my $sg = Scope::Guard->new(\&cleanup);
 
   eval { $dbh->do("DROP TABLE artist") };
@@ -66,6 +65,24 @@ EOF
   my $new = $ars->create({ name => 'foo' });
   ok($new->artistid, "Auto-PK worked");
 
+# test savepoints
+#  eval {
+#    $schema->txn_do(sub {
+#      eval {
+#        $schema->txn_do(sub {
+#          $ars->create({ name => 'in_savepoint' });
+#          die "rolling back savepoint";
+#        });
+#      };
+#      ok ((not $ars->search({ name => 'in_savepoint' })->first),
+#        'savepoint rolled back');
+#      $ars->create({ name => 'in_outer_txn' });
+#      die "rolling back outer txn";
+#    });
+#  };
+#  ok ((not $ars->search({ name => 'in_outer_txn' })->first),
+#    'outer txn rolled back');
+
 # test explicit key spec
   $new = $ars->create ({ name => 'bar', artistid => 66 });
   is($new->artistid, 66, 'Explicit PK worked');
@@ -87,7 +104,8 @@ EOF
     for (1..2) {
       push @pop, { name => "Artist_expkey_$_", artistid => 100 + $_ };
     }
-    $ars->populate (\@pop);
+    # XXX why does insert_bulk not work here?
+    my @foo = $ars->populate (\@pop);
   });
 
 # count what we did so far
@@ -119,37 +137,39 @@ EOF
   }
 
 # test blobs (stolen from 73oracle.t)
-  eval { $dbh->do('DROP TABLE bindtype_test') };
-  $dbh->do(q[
-  CREATE TABLE bindtype_test
-  (
-    id    INT   NOT NULL PRIMARY KEY,
-    bytea INT,
-    blob  BLOB,
-    clob  CLOB
-  )
-  ]);
-
-  my %binstr = ( 'small' => join('', map { chr($_) } ( 1 .. 127 )) );
-  $binstr{'large'} = $binstr{'small'} x 1024;
-
-  my $maxloblen = length $binstr{'large'};
-  local $dbh->{'LongReadLen'} = $maxloblen;
-
-  my $rs = $schema->resultset('BindType');
-  my $id = 0;
-
-  foreach my $type (qw( blob clob )) {
-    foreach my $size (qw( small large )) {
-      $id++;
+  SKIP: {
+    eval { $dbh->do('DROP TABLE bindtype_test2') };
+    $dbh->do(q[
+    CREATE TABLE bindtype_test2
+    (
+      id     INT PRIMARY KEY,
+      bytea  INT,
+      a_blob BLOB,
+      a_clob BLOB SUB_TYPE TEXT
+    )
+    ]);
+
+    my %binstr = ( 'small' => join('', map { chr($_) } ( 1 .. 127 )) );
+    $binstr{'large'} = $binstr{'small'} x 1024;
+
+    my $maxloblen = length $binstr{'large'};
+    local $dbh->{'LongReadLen'} = $maxloblen;
+
+    my $rs = $schema->resultset('BindType2');
+    my $id = 0;
+
+    foreach my $type (qw( a_blob a_clob )) {
+      foreach my $size (qw( small large )) {
+        $id++;
 
 # turn off horrendous binary DBIC_TRACE output
-      local $schema->storage->{debug} = 0;
+        local $schema->storage->{debug} = 0;
 
-      lives_ok { $rs->create( { 'id' => $id, $type => $binstr{$size} } ) }
-      "inserted $size $type without dying";
+        lives_ok { $rs->create( { 'id' => $id, $type => $binstr{$size} } ) }
+        "inserted $size $type without dying";
 
-      ok($rs->find($id)->$type eq $binstr{$size}, "verified inserted $size $type" );
+        ok($rs->find($id)->$type eq $binstr{$size}, "verified inserted $size $type" );
+      }
     }
   }
 }
@@ -159,14 +179,21 @@ done_testing;
 # clean up our mess
 
 sub cleanup {
-  foreach my $dbh (@handles_to_clean) {
-    eval { $dbh->do('DROP TRIGGER artist_bi') };
-    diag $@ if $@;
-    eval { $dbh->do('DROP GENERATOR gen_artist_artistid') };
-    diag $@ if $@;
-    foreach my $table (qw/artist bindtype_test/) {
-      $dbh->do("DROP TABLE $table");
-      diag $@ if $@;
-    }
+  my $dbh;
+  eval {
+    $schema->storage->disconnect; # to avoid object FOO is in use errors
+    $dbh = $schema->storage->dbh;
+  };
+  return unless $dbh;
+
+  eval { $dbh->do('DROP TRIGGER artist_bi') };
+  diag $@ if $@;
+
+  eval { $dbh->do('DROP GENERATOR gen_artist_artistid') };
+  diag $@ if $@;
+
+  foreach my $table (qw/artist bindtype_test/) {
+    eval { $dbh->do("DROP TABLE $table") };
+    #diag $@ if $@;
   }
 }