Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Opening a SQLite DB after accessing it w/ DBI module

by Riales (Hermit)
on Feb 25, 2012 at 05:28 UTC ( #956055=perlquestion: print w/replies, xml ) Need Help??
Riales has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I created a SQLite database using the following command:
$ sqlite database.db
I can go in, create tables, etc. That's all fine. Then, I connect to it through the Perl DBI module:
my $dbh = DBI->connect('dbi:SQLite:bandwidth.db', RaiseError=> 1) or d +ie $DBI::errstr;
But then I can't open the database with the sqlite command afterwards. Does anybody know what's going on? I am using the Dancer web framework if that's relevant.

Replies are listed 'Best First'.
Re: Opening a SQLite DB after accessing it w/ DBI module
by roboticus (Chancellor) on Feb 25, 2012 at 05:37 UTC


    Hmmm .. I couldn't reproduce the problem. I tried:

    $ cat #!/usr/bin/perl use strict; use warnings; use DBI; my $DB = DBI->connect('dbi:SQLite:test.db', RaiseError=>1) or die $DBI +::errstr; $DB->do('create table foo (id int)') or die $DBI::errstr; $DB->do('insert into foo (id) values (1)') or die $DBI::errstr; $ perl $ sqlite3 test.db SQLite version 3.7.3 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> select * from foo; 1 sqlite>

    Are you perhaps running your perl script under a different account than the sqlite3 command? (Such as having the perl code run in a web server or some such?)

    Note: I'm making the assumption that you meant sqlite3...


    When your only tool is a hammer, all problems look like your thumb.

      Ah, your note solved the problem. Using sqlite3 instead of sqlite worked. Thanks so much! I wonder what the difference between the two is...


        Good question. I don't seem to have sqlite on my system, only sqlite3, which is why I assumed that's what you meant. ;^)


        When your only tool is a hammer, all problems look like your thumb.

        There are some differences between versions in terms of how the data is stored. That might be an issue here. As a tip, I use the Firefox plugin - SQLite Manager which so far I've found easier than the command line. Well actually I don't even have the command line installed! I just installed DBD::SQLite and the Firefox plug-in and that worked well enough..
Re: Opening a SQLite DB after accessing it w/ DBI module
by GrandFather (Sage) on Feb 25, 2012 at 05:49 UTC

    What error does the die report? Are you sure you are working in the directory you think you are? In particular, is your script running in the same directory that you created the file in? Are the file permissions on the database file correct for the credentials the script is running under - if your script is running in the context of Apache for example it will probably have different user credentials than you used to create the file.

    True laziness is hard work

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://956055]
Approved by oko1
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2018-05-24 10:36 GMT
Find Nodes?
    Voting Booth?