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

  • Thread starter vishwanathsen03
  • Start date
V

vishwanathsen03

Hi,

I have installed the perl modules -
DBI
DBD::SQLite

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

#!/usr/bin/perl

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 perl_sqllite_example1.pl 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.....


Regards,
Vishwanath
 
J

John Bokma

Hi,

I have installed the perl modules -
DBI
DBD::SQLite

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

#!/usr/bin/perl

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 perl_sqllite_example1.pl 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....

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.
 
G

George Mpouras

# 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);

$sth->bind_columns(\$provider,\$username);

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


$dbh->disconnect;
 
J

John Bokma

George Mpouras said:
$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')

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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,813
Messages
2,569,696
Members
45,483
Latest member
TedDvb6626

Latest Threads

Top