[Zope-dev] Using db_connections from Zope products
I would like to make an SQL query directly from python code. Do I have to make a ZSQL Method dynamically, or is there another way without making the class database dependent (i.e. Gadfly, PoPy, etc), utilizing an existing db_con? Suppose I am using the ZPoPy DA and have established a database connection externally. How can I access this database and submit a query from my own class? Thanks, Tom Brown [EMAIL PROTECTED] __ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail http://personal.mail.yahoo.com/ ___ Zope-Dev maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
Re: [Zope-dev] Using db_connections from Zope products
Thanks fo the info! I had seen those How-Tos... but was really asking.. How can I use APIs directly instead of having an External ZSQL method. I have created a product and would like to be able to do sql queries in order to populate members of my class. For this example, I have the creation of a selection box as a member and the options will be generated by a select statement. I have gone through the product creation how to and was able to add, etc, my object. I can display html, make dtml on the fly, etc.. from an object, just wanted to do a query as well. .. would like to be able to do something like the Connection class without management interface, etc, or use pieces, just not sure how --- Jim Penny [EMAIL PROTECTED] wrote: On Wed, Jun 20, 2001 at 08:54:41AM -0700, Tom Brown wrote: I would like to make an SQL query directly from python code. Do I have to make a ZSQL Method dynamically, or is there another way without making the class database dependent (i.e. Gadfly, PoPy, etc), utilizing an existing db_con? Suppose I am using the ZPoPy DA and have established a database connection externally. How can I access this database and submit a query from my own class? You can use an established connection. If it is ZSQL based, you will have to deal with the results object. A good overview of the results object is http://www.zope.org/Members/spinwing/ZSQL_Results You might also look at the somewhat dated http://www.zope.org/Members/jpenny/Accessing_a_ZSQL_Method_from_an_External_Method This would work from Script (Python), as well. Jim Penny Thanks, Tom Brown [EMAIL PROTECTED] __ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail http://personal.mail.yahoo.com/ ___ Zope-Dev maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
Re: [Zope-dev] Using db_connections from Zope products
You want to recreate all of the machinery of ZSQL methods yourself? No, I want to be able to intelligently use pieces that are already there. Well, actually it can be done if your database supports some reasonable API, like the python DB-SIG DB-API 2.0. I know it can be done, which is why I was asking for input But you are creating a fair amount of work for yourself. I'm fine with the work, but I believe there must be a way to do it that doesn't require tons. I could do it from scratch using pg module, etc.. but figured there must be something I could use already there Just use a ZSQL method and be happy. (It will probably I don't want to use ZSQL methods, or I want to be able to define them Dynamically. I see this sight as a product with componenets. Why would I want to maintain 20 ZSQL methods when I could merely pass a couple of arguments such as DB name, which would be instantiated by a manage_addProduct form. I guess I could just trick it and pass everything (the whole select) into the one method as a var, but if I can do that I should be able to do it directly. make your site more secure if you use ZSQL, as well, as you will not have to worry as much about argument quoting). As far as argument quoting, why would there be any? I'm using a class member to take care of querying for me, why would I be passing arguments to it? Any arguments would have been dynamically created based on the class instantiation. There are database hooks for user administration, etc... all I was asking is for a good example of how to do it... I was trying to adhere to the principles used in designing ZClasses, make it look simple... tons of dtml and external python methods mixed in with 15-20 ZSQL methods just didn't seem to be simple when it could be made into a product... __ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail http://personal.mail.yahoo.com/ ___ Zope-Dev maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )