[Zope-DB] Querying many DBs from one set of SQL methods?

Matthew T. Kromer matt@zope.com
Tue, 18 Sep 2001 07:16:20 -0400


on 9/17/01 12:49 AM, Stuart Nicholson at stuart.nicholson@wirelessdatanz.com
wrote:

> The itch: I need to have a single set of Z SQL methods that can be run against
> multiple databases as part of a common web interface driven by data held in
> different client's
> databases. 
> 
> A problem: However when defining a Z SQL method you are required to select an
> existing Zope Database Connection instance that the SQL method will run
> against. 
> 
> A scatch?: To me (being something of a Zope novice), it would appear to
> scratch my itch I have to 'copy and paste' into different folders (say one per
> client), duplicating my
> common SQL methods, defining the appropriate DB Connection in each folder and
> then changing each duplicated SQL method to point to that connection. This
> seems a rather
> inelegant solution.
> 
> Is there a better way?: I haven't tried but imagine I can programatically
> change the DB Connection properties prior to running each request. Is this a
> viable solution? Will
> this work with multiple clients running the same query for example? Can
> anybody suggest a better solution?
> 
> Thanks in advance,

There's not a better way defined in any API.

What you *could* do is from a python external method (or maybe a python
script; I dont know if the security machinery would let you though) is grab
the SQL method, and grab the connection, and splice the connection into the
method manually.  As long as you do this from an external method, and don't
commit the changes (ie set the _p_changed flag) on the SQL method, it
shouldn't be written back out to the ZODB.