Sorry if this is the wrong forum, but has anyone run into a problem with
leaking file handles when using SQLite with Perl DBI and DBD::SQLite?

I am calling finish() and disconnect() when I'm done with each
connection, but lsof reports my database file opens once for each
connection and never closes. Curious if it's an issue with SQLite, DBI
or the DBD::SQLite driver itself.

Sample code to print every row from every table:

#!/usr/bin/perl -w
use strict;
use DBI;
my ( $query, $table_name, $sth, $sth2, $dbh, $dbh2, @rows, @rows2,
$count );
my $database_name = "/home/brad/test.db";
$query = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY
name";
$dbh = DBI->connect( "DBI:SQLite:dbname=$database_name","","",
                               { PrintError => 1 } ) or die "Cannot
connect to SQLite database $database_name";
$sth = $dbh->prepare( $query );
$sth->execute();

while ( @rows = $sth->fetchrow() )
{
    foreach $table_name ( @rows )
    {
        $count++;
        print "$count****$table_name\n";
        $query = "select * from $table_name";
        $dbh2 = DBI->connect( "DBI:SQLite:dbname=$database_name","","",
                                       { PrintError => 1 } ) or die
"Cannot connect to SQLite database $database_name";
        $sth2 = $dbh->prepare( $query );
        $sth2->execute();

        while ( @rows2 = $sth2->fetchrow() )
        {
            foreach my $row_contents ( @rows2 )
            {
                print "\t$row_contents";
            }
        print "\n";
        }
        $sth2->finish();
        $dbh2->disconnect();
    }
}
$sth->finish();
$dbh->disconnect();

## End of code

$count tells me it dies at the 1021st table with "Can't locate
Carp/Heavy.pm in @INC" error.
Using RedHat AS2, Perl 5.8.0, latest SQLite, DBI and SQLite as of 2
weeks ago.
This code works when connecting to MySQL, Oracle, DB2 and MS SQL Server
via ODBC which makes me suspect SQLite or DBD::SQLite.

Thanks for any help!

-Brad

Reply via email to