[Zope] RE: dynamically assigning DB-connections to ZSQL-methods ?

Frederic Quin fquin@profile4u.com
Thu, 7 Jun 2001 18:16:45 +0200


Hi,
I meet the same problem...
I had to execute the same query but on different databases located on different hosts...
What I did to resolve my probleme :
I created as many Zope Folder as I had DB Con objects.
In each Folder, I put a different DB Con object and my Z SQL Methods.

Instead of calling the Z SQL Method "sqlGetDatas()" like this :
<dtml-in "sqlGetDatas()">

I call it like that :
<dtml-in "myHost1.sqlGetDatas()">

If it based on a cookie, you can put in the cookie the name of the Folder containing the Z SQL Method to call.
If all your "DB Folders" are in the Folder "DBCons",
you just have to call the Z SQL Method "sqlGetDatas()" like this :
<dtml-in "_.getattr( DBCons, myCookie['dbcon'] ).sqlGetDatas()">

I hope to be clear and helpfull, but I am not so sure...

Frederic Quin


####################################################################
I have to make some ZSQL-methods connect to different
database-connections based on a cookie, but am experiencing a bit of
trouble..

available DB-connections for a ZSQL-method are listed in a select-box
only, not as a simple string , so it is
troublesome just adding a python-script to return a DB-connection
conditionally....

Have anybody done anything like this ?
tips ?