Multiple database servers

2 views
Skip to first unread message

james

unread,
Jan 2, 2007, 4:15:54 PM1/2/07
to web.py
Hi,

I'm new to Python, so hopefully this isn't too obvious a question. I'm
just wondering if it's possible to use two database servers with
web.py? I've added basic support for odbtpapi to web.py, and I also
have a mysql database.

Say I want to do something like:

a_results = web.select(...select from odbtapi data source...)
for a in a_results:
b_results = web.select(...select from mysql data source...)
...

tit...@gmail.com

unread,
Jan 3, 2007, 4:09:55 PM1/3/07
to web.py
Well, what you probably need to do is hack in 2 DB instances to ctx
(the connection object). It gets built for each connection. It
requires editing web.py itself.

You'd want something like:
web.ctx.db.select(blah)
web.ctx.db1.select(blah)

Hope this helps,
Ccraig

james

unread,
Jan 3, 2007, 8:18:44 PM1/3/07
to web.py
Thanks, I'm glad web.py is so small as it makes learning how things
work that much easier!

Anand

unread,
Jan 3, 2007, 8:48:24 PM1/3/07
to we...@googlegroups.com

On 04-Jan-07, at 2:39 AM, cr...@yuma.ca wrote:

>
> Well, what you probably need to do is hack in 2 DB instances to ctx
> (the connection object). It gets built for each connection. It
> requires editing web.py itself.
>
> You'd want something like:
> web.ctx.db.select(blah)
> web.ctx.db1.select(blah)

How about this.

import dbhack

db1 = dbhack.db(dbn="mysql", db="", user=...)
db2 = dbhack.db(....)

db1.select(blah)
db2.select(blah)


here is the code. (caution: i havent tested this).

dbhack.py

Anand

unread,
Jan 3, 2007, 9:42:59 PM1/3/07
to we...@googlegroups.com

there were some bugs and mistakes. fixed now.
i have tested this with 2 databases one mysql and one postgres. it
works fine.

dbhack.py

james

unread,
Jan 4, 2007, 11:32:10 AM1/4/07
to web.py
Sweet, thanks! Wish I could hack up code like that!

james

unread,
Jan 4, 2007, 1:29:41 PM1/4/07
to web.py
Anand wrote:
> there were some bugs and mistakes. fixed now.
> i have tested this with 2 databases one mysql and one postgres. it
> works fine.

Are you considering adding something like this to web.py?

Thanks again.

Reply all
Reply to author
Forward
0 new messages