Setup a connection to each of your databases as shown above - then db1 will 
represent the connection to the first database, db2 the second and so on - 
or you can just as easily name the database connections db_customer, 
db_purchases, db_relatives and so on so the names are a bit more 
descriptive.

There is some inspection/automated DAL model generation for a few databases 
but you can absolutely just write the SQL yourself - that's what I meant by 
using executesql (see here 
<http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#executesql>for
 
docs).

#assuming user_id_variable represents an identifier common across the 
databases
#if it isn't feel free to work out translation tables to take the ID from 
database 1 and figure out what it is in database 2
user_id_variable = 123

#get user's profile in db #1
db1.executesql('SELECT * from user_profile WHERE userid = ?',user_id_variable
, as_dict=True)

#get user's purchases in last 6 months from db #2
db2.executesql('SELECT purchase_date, item, price FROM purchase_history 
WHERE user_id = ? AND date BETWEEN ? AND ?', [user_id_variable, '2013-10-20'
, '2014-03-20'], as_dict=True)


I'd highly recommend reviewing the DAL chapter in the online web2py book: 
http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer

~Brian


On Thursday, March 20, 2014 3:33:50 PM UTC-5, learning wrote:
>
> I don't know about the syntax.  I'm trying to decide which Framework I 
> should go with.  I have one database that has information about personal 
> details.  Another database has information about various purchases, still 
> another database has information about other family members.  This is an 
> example, but there are this many databases I have to use with information 
> that is related.
>
> I have to create a webpage that goes out and gets all that information and 
> puts in a single webpage, so the user doesn't have to go to six pages to 
> see all the data.
>
> I do not need to create any tables.  I only need to do the retrieval.
>
> In Django I read something about getting inspectdb to create the objects 
> via their ORM.
>
> Is that the same way in web2py?  Can I write just regular SQL?  How does 
> it work?
>
> On Thursday, March 20, 2014 3:55:36 PM UTC-4, 黄祥 wrote:
>>
>> hm, pardon me, not sure what do you want to achieve. is it something like 
>> this?
>> e.g.
>> ## Use SQLite
>> db0 = DAL('sqlite://testmultipledb.sqlite')
>>
>> ## Use MySQL
>> db1 = DAL('mysql://root:@localhost/testmultipledb')
>>
>> ## Use PostgreSQL
>> db2 = DAL('postgres://postgres:a@localhost/testmultipledb')
>>
>> db0.define_table('person', Field('name'), format='%(name)s')
>> db1.define_table('person', Field('name'), format='%(name)s')
>> db2.define_table('person', Field('name'), format='%(name)s')
>>
>> db0.person.insert(name="Alex")
>> db1.person.insert(name="BAlex")
>> db2.person.insert(name="CAlex")
>>
>> row0 = db0().select(db0.person.ALL).first()
>> row1 = db1().select(db1.person.ALL).first()
>> row2 = db2().select(db2.person.ALL).first()
>>
>> best regards,
>> stifan
>>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to