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

Hello,

Newbie to Perl. Using the DBD::AnyData module with a simple test case:

use strict; use DBI; my $dbh = DBI->connect('dbi:AnyData(RaiseError=>1):'); $dbh->func( 'test', 'CSV', 'mytest.csv', 'ad_catalog' ); my $sth = $dbh->prepare( "SELECT * FROM test" ); $sth->execute(); while (my $row = $sth->fetch) { print "@$row\n"; } $dbh->disconnect;

When I run the above code, the data prints out fine but I get the error:

DBI handle 0x1d9e180 cleared whilst still active. dbih_clearcom (sth 0x1d9e180, com 0x1d9f3c4, imp DBD::AnyData::st) +: FLAGS 0x182195: COMSET Active Warn RaiseError PrintError PrintW +arn ShowErrorStatement PARENT DBI::db=HASH(0x1d9e084) KIDS 0 (0 Active) IMP_DATA undef NUM_OF_FIELDS 4 NUM_OF_PARAMS 0

I did find a post on this site saying to use the temporary fix ( $sth->{Active}=0; ) but I think that temporary fix was for another problem (STORE method in DBD::File??). This temporary fix does prevent the error message I'm getting from displaying though!

My Question: Should I just continue to use the temporary fix for the error I get or will that likely cause some other problems?

Currently the modules I have installed that are referenced by DBD::AnyData are:
DBI 1.48
AnyData 0.10
DBD::AnyData 0.08
DBD::File 0.33
SQL::StateMent 1.14

Any feedback would be much appreciated! Cheers, Victor

Replies are listed 'Best First'.
Re: DBD::AnyData error message for DBI handle
by jZed (Prior) on Jun 13, 2005 at 17:40 UTC
    Yes, use $sth->{Active}=0; for now. I will release a new version of DBD::AnyData that makes this unecessary.
      Shouldn't $sth->{Active} automatically be cleared when $sth->fetch returns undef, thus, when there are no more records to fetch?

      And shouldn't clearing $sth->{Active} be the same as calling $sth->finish?

      Quoting the DBI docs:

      Fetching all the data or calling $sth->finish sets Active off.
        Yes, that's the way it should work. However the old DBD::File got it wrong. Newer versions of DBD::File corrected it, and I just haven't released a newer DBD::AnyData to follow suit. In normal practice, one should never explicitly set $sth->{Active}, I'm only recommending it in this case as a temporary work around to shut off the annoying (but harmless) warning about Active handles in DESTROY. Alternate solutions would be to go back to an earlier DBD::FIle or to patch DBD::AnyData to remove the finish() and DESTROY() methods of ::st.
Re: DBD::AnyData error message for DBI handle
by ikegami (Patriarch) on Jun 13, 2005 at 17:58 UTC

    Could it be because you didn't close your sth? Try adding $sth->finish; before $dbh->disconnect;.

    Note: The latest DBI docs claim "The finish method is rarely needed, and frequently overused" and is only needed when not all the data is fetched. However, it could be that this isn't properly implemented, since it is a complete reversal of the author's old policy. Older versions of DBI would complained (via a warning) that finish must be called before disconnect, and that allowing finish to be omitted is deprecated and may not be allowed in future versions. (Gee, I wonder why it was "overused".)

      See my reply to bart, you're right, in normal practice finish() is rarely required. This is a bug in DBD::AnyData, a new version is on the way.