Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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.

Comment on Opening a SQLite DB after accessing it w/ DBI module
Select or Download Code
Re: Opening a SQLite DB after accessing it w/ DBI module
by roboticus (Canon) on Feb 25, 2012 at 05:37 UTC

    Riales:

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

    $ cat mk_sqlite.pl #!/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 mk_sqlite.pl $ 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...

    ...roboticus

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

        Riales:

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

        ...roboticus

        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 (Cardinal) 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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://956055]
Approved by oko1
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2014-10-02 06:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (49 votes), past polls