Newbie question--external methods, DTML and DB connection persistence
Hello, I've been scouring all the documentation available (Zope Book, howtos, newsgroups, etc.) but still have not been able to establish: 1. Whether it is possible for external methods to send SQL queries to an RDBMS using database connections defined in Zope, so that the persistent database connections are used. Or, if this is not possible, how to do so with Python scripts. 2. How to return result rows from a SQL selection in an external method or Python script so that <dtml-in my_external_method> and <dtml-var column_name_from_result_set> tags work as well as when using ZSQL methods. I'm trying to do so because I'd like to move all logic out of DTML, using it just for templating (until ZPT is more mature and documented). I'd rather use external methods because Python scripts are just too limiting (e.g. no support for many of the modules I'd like to use). Can anybody please help me understand whether what I want to do is possible, and how to do it? ...Edmund.
On 30 Aug 2001 00:13:01 -0400, elian@inbrief.net wrote:
1. Whether it is possible for external methods to send SQL queries to an RDBMS using database connections defined in Zope, so that the persistent database connections are used. Or, if this is not possible, how to do so with Python scripts.
If you can acquire the DA, you can call it to get the underlying DB, and then use DB.query(query_string), but I do not believe this will cache your queries. You are probably better off defining your queries in ZSQL Methods and calling those from Python Script. It may be possible to call them from an External Method.
2. How to return result rows from a SQL selection in an external method or Python script so that <dtml-in my_external_method> and <dtml-var column_name_from_result_set> tags work as well as when using ZSQL methods.
The query() method above returns two items: a sequence of dictionaries, each dictionary describing a column; and a sequence (rows) of sequences (column) for the result set. You'll probably have to dig into a DA (like ZMySQLDA) to see what is going on. However, the DA (see Shared.DC.ZRDB.DA.__call__ for more details) also does caching and Brains, and mangles the result a bit (Shared.DC.ZRDB.Results.Results). In short, while doing the above is an interesting exercise for the reader, you should try to use a Z SQL Method rather than trying to interact directly with a database connection. You could also create your own (Python, not Zope) database connection in an External Method or Product (I believe MysqlUserFolder does this). However, I'm not sure how you would acquire the Z SQL Method in the first place. You'd have to pass it to your External Method, or pass the current object and get the Z SQL Method by acquisition. In other words, yes, it's probably possible. -- Andy Dustman PGP: 0x930B8AB6 @ .net http://dustman.net/andy I'll give spammers one bite of the apple, but they'll have to guess which bite has the razor blade in it.
participants (2)
-
Andy Dustman -
elian@inbrief.net