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

Hi you all, I try to create a connection with SQLite by DBI-SQLite but, when I launch my Perl program from DOS shell, I received the following msg :
DBD::SQLite::db prepare failed: file is encrypted or is not a database +(26) at dbdimp.c line 268 at prova.pl line 3. Can't call method "execute" on an undefined value at prova.pl line 4.
My Perl Code is :
use DBI; my $dbh = DBI->connect("DBI:SQLite:dbname=prova.db","",""); $sth = $dbh->prepare("select * from joe1test"); $sth->execute; $numRows = $sth->rows; print "Righe : $numRows\n";
Can You help me ? Thanks a lot

Replies are listed 'Best First'.
Re: Problem with SQLite connection
by davido (Cardinal) on Sep 07, 2005 at 15:26 UTC

    Is it possible that the database was created using an older version of DBD::SQLite? Older versions (2.x and earlier) are incompatible with current versions. This is why you'll find on CPAN both DBD::SQLite2 (for backward compatibility) and DBD::SQLite (for most current version).


    Dave

      YES! Now it work ... Fantastic! I installed the DBD-SQLite2 and I used it also DBD-SQLite ... And now It Work very Well... Thanks to Dave, jZed, iKegami and sh1tn Have a nice Day Gioacchino
Re: Problem with SQLite connection
by jZed (Prior) on Sep 07, 2005 at 15:28 UTC
    How and where was "prova.db" created? If it wasn't created with SQLite on the same platform you are trying to access it from, you won't be able to read it. Also, If it was created with an earlier version of SQLite, you will need that version to read it. Paradoxically, the older version is accessible with DBD::SQLite2.
Re: Problem with SQLite connection
by ikegami (Patriarch) on Sep 07, 2005 at 15:28 UTC

    The first message is from connect failing. Since connect returns undef on failure, Perl gives the second message and dies when it tries to call the execute method of undef. You should either check the return value of connect or set the RaiseError option to 1.

    So why does connect fail? The error message indicates SQLite doesn't recognize the format of prova.db.

Re: Problem with SQLite connection
by sh1tn (Priest) on Sep 07, 2005 at 15:57 UTC
    This error comes when the .db file does not exist or is not in the format of SQLite. You can try with empty file and re-created table(s). Otherwise your code works without errors for me.


Re: Problem with SQLite connection
by giobis (Acolyte) on Sep 08, 2005 at 06:31 UTC
    YES! Now it work ... Fantastic! I installed the DBD-SQLite2 and I used it also DBD-SQLite ... And now It Work very Well... Thanks to Dave, jZed, iKegami and sh1tn Have a nice Day Gioacchino