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

I'm using sqlite 3.6.15, DBI 1.21, DBD::SQLite 0.31 with perl 5.6.1. From perl, when I attempt to make a database connection using DBD::SQLite (to, as far as I can tell, any non-empty file I create with the command line client), I get the following error:
[Tue Jun 23 17:10:22 2009] projectory.cgi: DBI->connect(dbname=projectory.sqlite3) failed: database disk image is malformed at ./projectory.cgi line 1577
At line 1577 it is executing this code
$dbh = DBI->connect("dbi:SQLite:dbname=projectory.sqlite3","","") or die "$DBI::errstr\n";
When I use the sqlite3 command line tool to do an integrity check, I get the following:
rintintin> sqlite3 projectory.sqlite3 SQLite version 3.6.15 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> PRAGMA integrity_check; ok sqlite> .exit
Debugging seems to show that the error causing the database to be reported as corrupted is in the DBD::SQLite XS or C code as it exits on DBD::SQLite::db::_login.
main::getDBConnection(projectory.cgi:1577): 1577: $dbh = DBI->connect("dbi:SQLite:dbname=projectory.sqlite3","","") or die "$DBI::errstr\n"; . . . DBI::connect(/home/talbert/lib/perl5/sun4-solaris/DBI.pm:471): 471: unless ($dbh = $drh->$connect_meth($dsn, $user, $pass, $at +tr)) { DB<2> p $drh DBI::dr=HASH(0x5d069c) DB<3> p $dsn dbname=projectory.sqlite3 DB<4> p $user DB<5> p $pass DB<6> p $attr HASH(0x5a5b04) . . . DBD::SQLite::dr::connect(/home/talbert/lib/perl5/sun4-solaris/DBD/SQLi +te.pm:57): 57: DBD::SQLite::db::_login($dbh, $real_dbname, $user, $auth) 58: or return undef; . . . DB<7> p $dbh DBI::db=HASH(0x9c92bc) DB<8> p $real_dbname projectory.sqlite3 DB<9> p $user DB<10> p $auth DB<11>
I would be grateful for any ideas you might have.
  • Comment on DBD::SQLite reporting a database file is corrupted, sqlite3 command line tool does not
  • Select or Download Code

Replies are listed 'Best First'.
Re: DBD::SQLite reporting a database file is corrupted, sqlite3 command line tool does not
by CSJewell (Beadle) on Jun 27, 2009 at 04:40 UTC
    DBD::SQLite versions less than 1.0 expect an SQLite 2.x file, not a SQLite 3.x file. You NEED to update your DBD::SQLite, or downgrade your database file. I think upgrading DBD::SQLite will be easier.
Re: DBD::SQLite reporting a database file is corrupted, sqlite3 command line tool does not
by Anonymous Monk on Jun 27, 2009 at 02:42 UTC
    You probably need to upgrade DBD::SQLite to a recent version
    use DBD::SQLite; warn $DBD::SQLite::VERSION; warn $DBD::SQLite::sqlite_version; __END__ 1.25 at - line 3. 3.6.13 at - line 4.