Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Querying an existing sqlite DB on a remote machine

by Anonymous Monk
on Jan 28, 2010 at 06:43 UTC ( [id://820103]=perlquestion: print w/replies, xml ) Need Help??

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

Hi all...
Using DBD::SQLite, can i query an existing sqlite DB on a remote machine.
The DB handler is:
DBI->connect("dbi:SQLite:dbname=$dbfile","","").
It doesnt even ask for any remote info.My code is:
$db_handler = "dbi:SQLite:$database:$host";#used host name to connect +to the remote machine but not sure if its correct. $DBIconnect = DBI->connect($db_handler, $user, $pw) or die die "Unable + to connect: $DBI::errstr\n"; $a_query = "SELECT * FROM $tablename where user_name=\"psibond\""; $res = $DBIconnect->prepare($a_query);

this just creates the $database on the local machine and gives me the following error.
DBD::SQLite::db prepare failed: no such table:
So i came to know that this dint connect to the remote machine rather just created a DB on the local machine.
Can u tell me where i went wrong or guide me how to query a remote DB with data

Replies are listed 'Best First'.
Re: Querying an existing sqlite DB on a remote machine
by ikegami (Patriarch) on Jan 28, 2010 at 06:50 UTC
    There's nothing to which to connect on the remote machine. SQLite is server-less. It might work over a networked drive, but the thought makes me cringe.
      . It might work over a networked drive, but the thought makes me cringe.

      If the DB was fairly small, it would be catched locally and might work surprisingly well.

      But yeah! you wouldn't want to rely upon it.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        Well..Now i copied the DB to my local machine.modified the code as follows
        $db_handler = DBI->connect("dbi:SQLite:dbname=$dbfile","","") or die " +Unable to connect: $DBI::errstr\n"; $a_query = "SELECT * FROM $tablename where user_name=\"Psibond\""; $res = $db_handler->prepare($a_query); $res->execute(); $row = $res->fetch;

        I am geeting the followin erros now:
        DBD::SQLite::db prepare failed: no such module: calmfts2 at DB-Querying.pl line 22.
        Can't call method "execute" on an undefined value at DB-Querying.pl line 24.
        Is there anything wrong.I guess the sqlite module supports prepare n execute methods. I also will be glad if u can tell me how to fetch out data
        Thanks,
        Psibond
Re: Querying an existing sqlite DB on a remote machine
by stefbv (Curate) on Jan 28, 2010 at 08:24 UTC
    Try DBD::Proxy or DBD::Gofer

    Update: From the description:

    DBD::Proxy is a Perl module for connecting to a database via a remote DBI driver. See DBD::Gofer for an alternative with different trade-offs.

    This is of course not needed for DBI drivers which already support connecting to a remote database, but there are engines which don't offer network connectivity.

      Agreed, DBD::Gofer is a good solution for this problem.
Re: Querying an existing sqlite DB on a remote machine
by bart (Canon) on Jan 28, 2010 at 09:47 UTC
    SQLite works on a file as a database, so you must have access to the database file. If you can reach that file, for example via an UNC path, then you can use it from within DBD::SQLite.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-03-28 08:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found