ZSQL to Python ???
Could someone please tell me, what would be the best way to pass in the query- result of a ZSQL method to a python method. thanks Sunit
At 11:37 am -0500 8/10/99, Joshi, Sunit wrote:
Could someone please tell me, what would be the best way to pass in the query- result of a ZSQL method to a python method.
thanks Sunit
Here's what I do; def get_file(self, filenumber, RESPONSE): ''' nothing yet ''' # get the directory dir = self.savedir # get data from database res_data = self.Actors.SQL_Upload.res_data_from_filenumber(filenumber=filenumber) if len(res_data) != 1: return "Error: no data matched filenumber:%s" %filenumber resdata = res_data[0] # get the mimetype if resdata['mimetype'] == 'not known': # get some mimetypes atype = mimetypes.guess_type(resdata['filename']) if atype[0] != None: resdata['mimetype'] = atype[0] etc etc etc (I'm importing mimetypes and other stuff). It's not optimal, because it doesn't loop over the returned records, but it works! :) The SQL method is in res_data_from_filenumber (which is in a folder called SQL_Upload in a folder called Actors). It's passed the filenumber. The ZSQL method looks like this; select * from res_data where filenumber = <dtml-sqlvar filenumber type=int> (parameter filenumber:int) The database schema looks like; CREATE TABLE res_data ( filename varchar(255), filenumber int(11) DEFAULT '0' NOT NULL auto_increment, identifier varchar(20), identifier_type varchar(40), keywords varchar(255), extra_info varchar(255), user varchar(40), mimetype varchar(40), uploaded timestamp(14), filesize int(11), display varchar(4) DEFAULT 'y', PRIMARY KEY (filenumber) ); Hope this helps, tone. ------ Dr Tony McDonald, FMCC, Networked Learning Environments Project http://nle.ncl.ac.uk/ The Medical School, Newcastle University Tel: +44 191 222 5888 Fingerprint: 3450 876D FA41 B926 D3DD F8C3 F2D0 C3B9 8B38 18A2
At 11:12 AM 10/10/1999 +0100, Tony McDonald wrote:
At 11:37 am -0500 8/10/99, Joshi, Sunit wrote:
Could someone please tell me, what would be the best way to pass in the query- result of a ZSQL method to a python method.
thanks Sunit
Rather than pass the query-result to the python method, surely it would be easier to pass the DA and then extract the results using Python ? From an earlier post : [snip] On Mon, 27 Sep 1999, Hannu Krosing wrote:
Can anyone point out how do I reference a Zope DA Connection from an external method. This way I can make use of an existing open connection instead.
From a short look at the source it seems that you can just use
YourZopeConnection.query('select * from data')
I quess the result will be the same as from using ZSQL Method, but it may be something simpler. [/snip]
It may also depend on the DB connector you're using but I remember seeing posts about passing the MySQL DA on the list. I guess python methods and external methods will both work ok. chas
participants (3)
-
chas -
Joshi, Sunit -
Tony McDonald