Imagine a table like:

map = {'company1': 'sqlite://company1.sqlite','company2: 
'sqlite://company2.sqlite','company3': 'sqlite://company3.sqlite'}

then you can do:

dburi = map.get(request.args(0))
if not dburi: raise HTTP(404)
db = DAL(dburi)

Now when you do

http://127.0.0.1:8000/app/default/index/company1

The company1 specifies the database.

If you have another app you can do the same but replace

db = DAL(dburi)

with

db = DAL(dburi, 
folder=os.path.join(request.folder,'..','otherapp','databases'))

and it will share the database with the otherapp.


On Friday, 26 April 2013 23:43:47 UTC-5, LJ wrote:
>
> Hi
>
> I am new to web2py as well as python, but i found it very interesting 
> developing some simple applications. However, i am unsure about how to 
> configure the application for using multiple database depending on user 
> login. There are two possible scenarios i am considering:
>
> Scenario 1 (Single instance, multiple databases)
> 1. User visits www.foobar.com
> 2. Login page asks for username, password, company code.
> 3. Controllers/Views/Models are identical for users from all companies. 
> Databases are different.
> 4. Depending on company code, the application connects to the appropriate 
> DB and authenticates user.
> 5. User from different company accesses different database.
>
>
> Scenario 2: Multiple instances, multiple databases
> 1. User visits www.foobar.com
> 2. Login page asks for username, password, company code.
> 3. Controllers/Views/Models are slightly different for each company as are 
> the databases.
> 4. Depending on company code, the appropriate functions/views are called 
> and the appropriate database is affected.
> 5. User from different company accesses different database and has a 
> different set of controllers and views.
>
> How should the application be structured to enable each of these 
> scenarios. I was unable to find the solution in other threads.
>
> Thanks in advance
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to