Hey all, got a problem here which I don't quite understand.  I need to
share a pool of dbi connections between N perl processes.  I know that only
one process may use a DBH at at time, and can handle that.  The problem that
I am having can been seen in the code below.  If I just start up a
connection, place it in a segment and then try to attach to that segment
from another process and use the DBH I get the following error.

"dbih_getcom handle DBI::db=HASH(0x828e438) is not a DBI handle (has no
magic) at  ./connection_pool_client.pl line 59."


Any idea why a dbh can not be shared via shared memory?  What is trying a
dbh to its original process?  What's magic?

Thanks all.


Here is my code

connection_pool.pl
============================
#!/usr/bin/perl

############################################################################
######
##    File: connection_pool
##
##     Des:
##
##  Author: James Maes
##
##   Notes:
##
##    Todo:
##
##    Bugs:
##
##    Date: Wed Sep 25 2002
##
## Version: $Revision$
##
############################################################################
######

use DBI;
use IPC::Shareable (':lock');

###########################################
## setup the needed global semaphore var ##
###########################################
%IPC_INIT_OPTIONS =
(
   create => 'yes',
   exclusive => 0,
   mode => 0777,
   destroy => 'yes',
);

$STAT_FILES_GLUE = "SFDS";

################################################################
## use IPC::Shareable to put shared hashes into shared memory ##
################################################################
print "Initializing shared memeory pool\n";
my $sharedMem;
tie $sharedMem, 'IPC::Shareable', $STAT_FILES_GLUE, { %IPC_INIT_OPTIONS } or
die("tie write failed.");

##########################################################################
## place the connection in a share memory segment to allow access to it ##
##########################################################################
print "Initializing database connections\n";
$dbh =
DBI->connect("dbi:Informix:usermgr\@mldbtcp",,,{AutoCommit=>0,PrintError=>1}
) || print "Error : $!\n";
$sharedMem->{dbh}    = $dbh;
$sharedMem->{name}   = "db_connection";
$sharedMem->{time}   = time();


print "Done\n";

####################################
## make the stdout filehandle hot ##
####################################
while(1)
{
   print " . \n";
   sleep(10);
}




connection_pool_client.pl
============================
#!/usr/bin/perl

############################################################################
######
##    File: connection_pool_client.pl
##
##     Des:
##
##  Author: James Maes
##
##   Notes:
##
##    Todo:
##
##    Bugs:
##
##    Date: Wed Sep 25 2002
##
## Version: $Revision$
##
############################################################################
######

use DBI;
use INFOplus::DB;
use IPC::Shareable (':lock');

require "/usr/lib/perl5/5.6.0/dumpvar.pl";

###########################################
## setup the needed global semaphore var ##
###########################################
%IPC_READ_OPTIONS =
(
   create => 0,
   exclusive => 0,
   mode => 0777,
   destroy => 0,
);

$STAT_FILES_GLUE = "SFDS";


############################################################
## get the stat file hash from the IPC::Shareable segment ##
############################################################
my $sharedMem;
tie $sharedMem, 'IPC::Shareable', $STAT_FILES_GLUE, { %IPC_READ_OPTIONS } or
die("tie read failed.");

print "Values\n";
print "dbh  = $sharedMem->{dbh}\n";
print "name = $sharedMem->{name}\n";
print "time = $sharedMem->{time}\n";
## main::dumpValue($sharedMem);


$dbh = $sharedMem->{dbh};

print "DBH\n";
## main::dumpValue($dbh);
$dbh->commit();


print "Connection\n";

Reply via email to