Using a SQL database connection in Python scripts
Hello, I just created a database connection and want to do some queries from a Python script and solving the problem without defining explicite ZSQL methods and just do some queries from the python script. In a former mail to this list I've got the following hint according to a similiar question: Mon, 13 May 2002, Gilles Lenfant <gilles@objectis.net> wrote:
Zope DAs have a "manage_test" method. The docstring says :
results = someDA.manage_test(query, REQUEST=None)
Executes the SQL in parameter query and returns results
Note you must set the proxy to "manager" to a python script or DTML that executes this method.
Thus I tried results = context.myDBconnection.manage_test('SELECT * FROM table;', \ REQUEST=None) print results return printed And got <Shared.DC.ZRDB.Results.Results instance at 0x91327bc> Hmmm, it seems to work in any way - but how to parse the results object? I tired to find some solutions in the Zope Book but failed because it describes only DTML methods to query databases. Is there any reason to use only DTML with databases and my intention has real drawbacks or is it just a lack of documentation? Kind regards Andreas.
Try reading the ZSQL Results How-To, at www.zope.org/Members/spinwing/ZSQL_Results. As for DTML versus Python, it's certainly a documentation issue - anything DTML can do, Python plus ZPT can do <flame>better</flame> David On Tue, 24 Sep 2002, Andreas Tille wrote:
Hello,
I just created a database connection and want to do some queries from a Python script and solving the problem without defining explicite ZSQL methods and just do some queries from the python script.
[snip]
I tired to find some solutions in the Zope Book but failed because it describes only DTML methods to query databases. Is there any reason to use only DTML with databases and my intention has real drawbacks or is it just a lack of documentation?
You could also look at the Zope Bible... It has nice python oriented approach at Zope AM DA Loeffler wrote:
Try reading the ZSQL Results How-To, at www.zope.org/Members/spinwing/ZSQL_Results. As for DTML versus Python, it's certainly a documentation issue - anything DTML can do, Python plus ZPT can do <flame>better</flame>
David
On Tue, 24 Sep 2002, Andreas Tille wrote:
Hello,
I just created a database connection and want to do some queries from a Python script and solving the problem without defining explicite ZSQL methods and just do some queries from the python script.
[snip]
I tired to find some solutions in the Zope Book but failed because it describes only DTML methods to query databases. Is there any reason to use only DTML with databases and my intention has real drawbacks or is it just a lack of documentation?
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
-- ================================================================== Aseem Mohanty Neurobehavioral Systems Inc, 828 San Pablo Ave, Albany, CA 94706 (R) 510 7696011 (M) 510 3014871 (O) 510 5279231 ================================================================== "I saw `cout' being shifted "Hello world" times to the left and stopped right there!!" -- Steve Gonedes ==================================================================
participants (3)
-
AM -
Andreas Tille -
DA Loeffler