http://qs321.pair.com?node_id=622029

iguanodon has asked for the wisdom of the Perl Monks concerning the following question:

I recently started using DBD::AnyData to query some flat files and it works great - except for the warnings it spits out. If I run the basic example from the DBD::AnyData docs, it prints the result set, followed by:
DBI st handle 0x9bd6468 cleared whilst still active. dbih_clearcom (sth 0x9bd6468, com 0x9bd83b8, imp DBD::AnyData::st) +: FLAGS 0x88005: COMSET Active HandleError PARENT DBI::db=HASH(0x9bd6384) KIDS 0 (0 Active) NUM_OF_FIELDS 2 NUM_OF_PARAMS 0
I did add $sth->finish and $dbh->disconnect to my test script but I still get that output.

I thought I could just add a __WARN__ handler to ignore this particular warning, but that only solves part of the problem. It appears that only the first line of the above output is the warning, the part starting with dbih_clearcom still gets printed.

I also tried using $dbh->{HandleError} but my handler isn't being called. Here's what I've tried so far:

#!/usr/bin/env perl use strict; use warnings; $| = 1; use DBI; $SIG{__WARN__} = \&handle_warnings; my $dbh = DBI->connect('dbi:AnyData:'); $dbh->{HandleError} = \&handle_errors; $dbh->{RaiseError} = 0; $dbh->{PrintError} = 0; $dbh->{PrintWarn} = 0; $dbh->{ShowErrorStatement} = 0; $dbh->{Warn} = 0; $dbh->func( 'cars', 'CSV', 'cars.csv', 'ad_catalog'); my $sth = $dbh->prepare('select make, model from cars'); $sth->execute(); while (my $row = $sth->fetch) { print "@$row\n"; } $sth->finish; $dbh->disconnect; sub handle_warnings { print Data::Dumper->Dump([\@_], ['*_']); my $warning = shift; print "Handling WARNING:\n$warning\n"; return if $warning =~ /handle .*? cleared whilst still active/ms; } sub handle_errors { print Data::Dumper->Dump([\@_], ['*_']); my $error = shift; print "Handling ERROR:$error\n"; 1; }
There is a bug report for this issue but it's been open for about a year. I've seen several recommendations here for DBD::AnyData, but no mention of this problem. Am I missing something obvious, or is there a workaround?