Sorry, this was mis-addressed.  Should have gone to the list...

----- Forwarded Message ----
From: Clark Christensen <[EMAIL PROTECTED]>
To: Alexander Batyrshin <[EMAIL PROTECTED]>
Sent: Monday, February 4, 2008 9:46:49 AM
Subject: Re: [sqlite] DBD::SQLite 1.14 prepare_cached bug?

bash,

What do you expect to see?  From the code, I'm guessing something like:

$VAR1=[...]

If you're just trying to silence the "closing dbh with active handles..." 
warning, "undef $sth;" usually works for me.  I see you have it commented in 
your code?  DBD-SQLite has spewed this warning for as long as I can remember.  
And $dbh->finish; doesn't squash it.

Also, I see you could save the sprintf and $dbh->quote by changing to:

my $sql = "select a_session from sessions where id = ?";
my $sth = $dbh->prepare_cached($sql);
$sth->execute($sid);

In your example, the value of $sid, after doing the $dbh->quote, is parsed by 
the SQL parser.  Doing that has always been unreliable for me, and it's 
generally open to SQL injection.  In the example above, $sid isn't 
parsed/compiled by SQLite, it's just passed as-is as a bound parameter after 
$sth is prepared.

Are you building a web session manager using SQLite as the data store?  How is 
Storable working for you?  I usually just use Data::Dumper, and eval the stored 
hash.  But doing the eval has always worried me :-))

Thanks!

 -Clark


----- Original Message ----
From: Alexander Batyrshin <[EMAIL PROTECTED]>
To: sqlite-users@sqlite.org
Sent: Saturday, February 2, 2008 3:27:35 PM
Subject: [sqlite] DBD::SQLite 1.14 prepare_cached bug?

 Hello All,
I don't know is it right place to discuss this or not. Sorry If I am
doing something wrong.
Installed sqlite-3.5.4 and DBD::SQLite-1.14
I get problems with this code:

----%<--------------------------------------------
#!/usr/bin/perl -w

use strict;
use DBI;
use Data::Dumper;
use Storable;
use warnings;

sub get_session {
    my ($dbh) = shift;
    #$dbh->{TraceLevel} = 2;
    my $sid = $ARGV[0];
    my $SQL = sprintf("select a_session from sessions where id = %s",
$dbh->quote($sid));
    my $sth = $dbh->prepare_cached($SQL, undef, 3);
    $sth->execute;
    my ($val) = $sth->fetchrow_array;
    #my ($val2) = $sth->fetchrow_array;
    $sth->finish;
    #[3] undef $sth;
    my $session = Storable::thaw($val);
}


my $dbh = DBI->connect('dbi:SQLite:dbname=db/sessions.db');
print Dumper(get_session($dbh));
$dbh->disconnect;
----%<--------------------------------------------

If we run program as it looks, result will be:

DBI::db=HASH(0x87a79c)->disconnect invalidates 1 active statement
handle (either destroy statement handles or call finish on them before
disconnecting) at ./decode_sessions.pl line 26.
closing dbh with active statement handles at ./decode_sessions.pl line 26.

Note: that my database does not contain duplicated records.

If I uncomment (1), (2) or (1)+(2) result:

closing dbh with active statement handles at ./decode_sessions.pl line 26.

Inside DBD-SQLite this errors goes from this:
--------%<----------------------------------------
int
sqlite_db_disconnect (SV *dbh, imp_dbh_t *imp_dbh)
{
    dTHR;
    DBIc_ACTIVE_off(imp_dbh);

    if (DBIc_is(imp_dbh, DBIcf_AutoCommit) == FALSE) {
        sqlite_db_rollback(dbh, imp_dbh);
    }

    if (sqlite3_close(imp_dbh->db) == SQLITE_BUSY) {
        /* active statements! */
        warn("closing dbh with active statement handles");
    }
    imp_dbh->db = NULL;

    av_undef(imp_dbh->functions);
    imp_dbh->functions = (AV *)NULL;

    av_undef(imp_dbh->aggregates);
    imp_dbh->aggregates = (AV *)NULL;

    return TRUE;
}
--------%<----------------------------------------


-- 
Alexander Batyrshin aka bash
bash = Biomechanica Artificial Sabotage Humanoid
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users






_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to