[Zope] ZSQL method and database connection acquisition.

Dieter Maurer dieter@handshake.de
Sat, 1 Sep 2001 23:40:48 +0200 (CEST)


jon@totient.demon.co.uk writes:
 > I have a folder X with many ZSQLMethods inside it. To add these
 > I had to add a connection object to folder X before hand.
 > 
 > However I have other folders say test1 and test2 in which I place
 > a database connection with the same id but connecting to different
 > databases. I am have the same schema in two databases, so I want to
 > group the sql all together and then use the differing connections
 > in different folders to manipulate the data differently.
 > 
 > so we have (as a minimum)
 > 
 > /X containing
 >        dbconn ; a 'fake' database connection
 >        a_sql_method ; uses dbconn
 > /test1
 > 	dbconn ; a database connection to database1
 > 
 > /test2 
 >        dbconn ; a database connection to database2
 > 
 > 
 > Now once this is all set up you have to delete the /X/dbconn.
 > (If you rename it though, the connection_id in the sql_method
 > changes as well, which makes the calls from the test1/2 folders
 > break). So delete it you must.
 > 
 > and then using the magic of acquistion call
 > 
 > /X/test1/a_sql_method  
 > 
 > and this queries on database1
 > 
 > and
 > /X/test2/a_sql_method
 > 
 > and this queries database2
I used a ZClass to solve a similar problem:

  I defined the Z SQL method as a ZClass method.

  That this works, I had to add a fake (non-working)
  Database Connection in the product folder containing
  the ZClass.

  I then create instances of the ZClass whereever I need
  them. The Z SQL method will use the Database Connection
  in the respective acquisition context (and not the
  on in the product folder).


Dieter