I have a strange problem where a database handle is being destroyed for no
apparent reason. My initial idea was to parse some xml, and translate it
into a database. Deleting line after line of code I came up with this short
meaningles program which exhibits the same behavior as its real-life
sibling (tested against two different mysql instalations on different
machines):
use warnings;
use strict;
use DBI;
use XML::Twig;
++$|; #so I can see the progress in _dummy ()
my $dbh = DBI->connect ( "dbi:mysql:$random_db:localhost",
$user,
$pass,
{ AutoCommit => 0,
RaiseError => 1,
PrintError => 0,
}
);
unless ($dbh) {
print "Unable to connect:\n$DBI::errstr\n";
exit 1;
};
eval { $dbh->do ("DROP TABLE IF EXISTS some_nonexistant_table") };
die ($@) if $@;
my $objinfo_parser = XML::Twig->new (
twig_handlers => {
'Products/Product' => \&_dummy
}
);
$objinfo_parser->parseurl ('http://www.3btech.net/3btech/objinfo.xml');
$dbh->commit;
$dbh->disconnect;
exit 0;
sub _dummy {
my ($twig, $child) = @_;
print '.';
$twig->purge();
return 'dummy';
}
Note that I am not even doing any real operations on the MySQL side, thus I
don't care what database I connect to. I put the DROP TABLE there just to
make sure that commands are reaching the server, and yes I can see that in
the logs.
If I run the real program I end up stuffing about 480 out of roughly 510
products into a designated table and then the handle goes out to lunch with
the same error message.
I use the very same XML::Twig setup in another script that packs results
into a hash and returns it, and everything works flawlessly. Any help is
priceless, as after nearly two days playing with this I am totally lost...
Thanks
Peter