Sorry.. I actually had a typo in that sample, but even with it fixed I
get the same results (just runs slower). New code with fixed typo:


#!/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 = $dbh2->prepare( $query );  #Typo was here
        $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



 


Brad DerManouelian
Sane Solutions, LLC
Phone: 401-295-4809 x122
http://www.sane.com 

This e-mail message may contain confidential information. If you are not
the intended recipient, any use, dissemination, distribution or copying
of this e-mail message is strictly prohibited. If you have received this
message in error, please immediately notify the sender and delete this
e-mail message from your computer.


-----Original Message-----
From: Brad DerManouelian [mailto:[EMAIL PROTECTED] 
Sent: Monday, March 28, 2005 12:24 PM
To: sqlite-users@sqlite.org
Subject: [sqlite] DBD::SQLite not closing file handles

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