Perl to SQLite bridge is not working, database connect fails ....

Discussion in 'Perl Misc' started by vishwanathsen03, Apr 8, 2014.

  1. Hi,

    I have installed the perl modules -

    Now I am running a simple perl script that calls sqlite database.


    use DBI;
    use strict;

    my $driver = "SQLite";
    my $database = "ex2.db";
    my $dsn = "DBI:$driver:dbname=$database";
    my $userid = "";
    my $password = "";
    my $dbh = DBI->connect($dsn, $userid, $password, { RaiseError => 1 })
    or die $DBI::errstr;

    print "Opened database successfully\n";

    Perl script fails on the line that does connect (DBI->connect) with the message -

    DBI connect('dbname=ex2.db','',...) failed: database disk image is malformed at line 11

    SQLite and database seems to be fine, I could open/load the database using sqlite3 and I could do insert and select operations.
    I could write a C program and I could use the C program to do an insert operation successfully in the database.

    So it is the perl to sqlite bridge that has issues....

    Kindly suggest.....

    vishwanathsen03, Apr 8, 2014
    1. Advertisements

  2. vishwanathsen03

    John Bokma Guest

    Which version did you use to create the database file (it sounds like
    version 2)? You might have to pass legacy_file_format, see documentation
    of DBD::SQLite.
    John Bokma, Apr 8, 2014
    1. Advertisements

  3. # take a working sample from one of my scripts and adapt it ...

    use strict;
    use warnings;
    use DBI qw:)sql_types); # για blobs

    my $dbh = DBI->connect('dbi:SQLite:dbname=C:/Program
    Files/WebApp/sites/database/sms.db', undef, undef, {AutoCommit=>1,
    RaiseError=>1, sqlite_unicode=>1}) or die "$DBI::errstr\n";;
    $dbh->do('PRAGMA foreign_keys = OFF');
    $dbh->do('PRAGMA cache_size = 1000');
    $dbh->do('PRAGMA synchronous = OFF');
    $dbh->do('PRAGMA sqlite_allow_multiple_statements = OFF')
    $dbh->{'sqlite_see_if_its_a_number'} = 1;
    $dbh->{'sqlite_use_immediate_transaction'} = 0;

    my $sth = $dbh->prepare('SELECT provider_name, account_username FROM
    Account WHERE webapp_username == ?1 ORDER BY
    provider_name,account_username') or die "$DBI::errstr\n";
    $sth->bind_param(1, 'user1', SQL_VARCHAR);

    $sth->execute() or die "$DBI::errstr\n";
    my ($provider, $username);


    while ( $sth->fetchrow_array )
    print "$provider,$username\n";

    George Mpouras, Apr 8, 2014
  4. vishwanathsen03

    John Bokma Guest

    Which I probably would write as:

    $dbh->do( "PRAGMA $_->[0] = $_->[1]" ) for (
    [ foreign_keys => 'OFF' ],
    [ cache_size => 1000 ],
    [ synchonous => 'OFF' ],
    [ sqlite_allow_multiple_statements => 'OFF' ]

    But I am afraid your working example is not going to work as well, at
    least if I am correct that it's an SQLite version issue.
    John Bokma, Apr 9, 2014
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.