Accessing a Sqlite Database from a 2 different Web2py Application

245 views
Skip to first unread message

anubhav aggarwal

unread,
Apr 12, 2011, 5:23:27 AM4/12/11
to sahan...@googlegroups.com
Hit Team,

  I wanted to get access of the, sqlite database of a Eden App from the WebSetup Co-app .Could you please tell me a way to do this.

  I tried copying all ".table" files from the database folder of Eden to my app and then calling Database statements .However this did not help.
  
  Is there any need to be change in web2py files ,could you please give me some pointers regarding this.


Thank you

Anubhav Aggarwal

Pat Tressel

unread,
Apr 12, 2011, 9:24:44 AM4/12/11
to sahan...@googlegroups.com, anubhav aggarwal
Anubhav --

  I wanted to get access of the, sqlite database of a Eden App from the WebSetup Co-app .Could you please tell me a way to do this.

  I tried copying all ".table" files from the database folder of Eden to my app and then calling Database statements .However this did not help.
  
  Is there any need to be change in web2py files ,could you please give me some pointers regarding this.

The sqlite database is the file databases/storage.db rather than the .table files -- those are web2py's record of the current schema.

I'm not sure sqlite will be your best choice here.  The "real" databases like MySQL and PostgreSQL are designed for multiple accessors -- you won't have problems with two accessors interfering with one another if you use those.

I recall seeing some info (either in the web2py book or on its mailing list) about accessing files / database of one application from another.  You might search for something like "web2py multiple applications shared database".  That turns up a note in the web2py book that says, yes, one can share a database, but they're talking about a multi-user database like MySQL / PostgreSQL when they say it...

-- Pat

Fran Boon

unread,
Apr 12, 2011, 9:50:29 AM4/12/11
to sahan...@googlegroups.com
On 12 April 2011 14:24, Pat Tressel <ptre...@myuw.net> wrote:
> I'm not sure sqlite will be your best choice here.  The "real" databases
> like MySQL and PostgreSQL are designed for multiple accessors -- you won't
> have problems with two accessors interfering with one another if you use
> those.

However the solution will need to work across all of our supported databases.
sqlite's lack of multi-user access shouldn't be an issue for it's
usecase: single user systems, such as laptops.

Since we perceive websetup as running before the main models are run
then it shouldn't need acess to the .table files, but if it does need
to access some then it should be able to create it's own independent
copy without issue.

Have you tried setting the DB access as
sqlite://../../eden/databases/storage.db?
- am not sure it'll work, but worth a first stab...

F

Dominic König

unread,
Apr 12, 2011, 10:04:26 AM4/12/11
to sahan...@googlegroups.com
If the WebSetup co-app is a web2py application as well, then you can access
the database by simply using the same connection string. Be careful to have
migrate set to False in all cases. That would be DB-type independent then.

However, this does not give you access to the model - that would need to be
replicated. However, you would not need to replicate all of the models if you
just need one table.

You can though also get access to the environment of the other application,
which is described here:
http://www.web2py.com/book/default/chapter/04?search=environment#Execution-
Environment

This gives you full access to the Eden database from another application
through the DAL. Also read the next section "Cooperation".

If it is not a web2py app (and why would that be?), then you need to manually
connect to the respective database, which highly depends on the DB type and
would probably require a separate setup (a setup application for the setup
application?). Doesn't seem to make that much sense, actually.

Dominic

signature.asc
Reply all
Reply to author
Forward
0 new messages