zalldone - 2005-05-20

I'm running Windows 2000 SP4, FireBird 1.5.0. The day before I had ActiveState Perl 5.8.4.810, DBI 1.47 and DBD::InterBase 0.43 downloaded from CPAN (DBD-InterBase-0.43.tar.gz, 25-Feb-2004 04:30) and built with Gygwin utils. Now I have AS Perl 5.8.6.811, DBI 1.48 and DBD::InterBase 0.43 checked out from CVS on May 11th and built with MS VC++ 7.1 (GNU make 3.80 from Cygwin utils failed to make it).

I can't I make it work with one DBI handle shared between threads. The test script says:
<code>
Error: DBD::InterBase::db prepare failed: handle 2 is owned by thread 15d492c not current thread 1
c1318c (handles can't be shared between threads and your driver may need a CLONE method added) at
X:\MYDOCS\Perl\ib_thread_test.pl line 27.
</code>

Here's the test script:
<code>
use strict;
use warnings;

use DBI;
use threads;

my $g_dbh;

sub getDSN() {
  return <<DSN
dbi:InterBase:database=D:\\TEMP\\test.gdb;
host=localhost;
ib_dialect=3;
DSN
}

sub getDBConnection() {
  if ( defined($g_dbh) ) { return $g_dbh; }
  my %attrs = (PrintError => 0, RaiseError => 1, AutoCommit => 0);
  return $g_dbh = DBI->connect(getDSN(), "sysdba", "masterkey", \%attrs);
}

sub thread_func {
  my ($dbh, $sth);
  eval {
    $dbh = getDBConnection();
    $sth = $dbh->prepare("select count(*) from Q"); # line 27
  };
  if ( $@ ) {
    printf("Error: %s\n", $@);
  }
  if ( defined($sth) ) {
    $sth->finish();
  }
}

sub main() {
  my $dbh = getDBConnection();
  my $sth = $dbh->prepare("select count(*) from Q");
  $sth->finish();

  my $t = threads->create(\&amp;thread_func);
  $t->join();
}

main();
</code>