[Zope] ZSQLMethodFile?

Peter Sabaini sabaini@inode.at
Thu, 12 Jun 2003 08:50:04 +0200


This is a cryptographically signed message in MIME format.

--------------ms090809020209070107070804
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Peter Bengtsson wrote:

[snip]

>>>>
>>> IF I wrap them are class methods, will it correctly look like this:
>>>
>>> def Mysqlstuff(Aq...):
>>>     def zsql_method(self, name, age):
>>>         return SQL(..., ..., ...)(name=name, age=age)
>>>
>>> Or do I need anything else?
>>
>>
>>
>> This should about work, but it would be more efficient if you stored 
>> the ZSQL object somewhere.  Otherwise you'd have to reparse the dtml 
>> each time you call zsql_method() and won't be able to use zope caching.
>>
> 
> You're right.
> So, if I don't wrap them like that but do define them as attributes, 
> they don't have to reparse them?
> Then I can do this:
> 
> class Mysqlstuff(Aq...):
> 
>     _login = SQL('null','dummy title', dbconnection,
>                  'name:string pass:string', sqlfile.read())
>     def login(self, name, pass):
>         ...do other things such as debug...
>         return _login(name=name, pass=pass)
> 
> What do you think about that?


Should work -- I use a somewhat different pattern though:

class AllSQL(Acquisition.Implicit):
     zsql = SQL('id', 'title', 'dbconnection', 'arg:type', \
                "select foo from bar where <dtml- ...")

class ZopeObject(OFS.SimpleItem, ...):
     sql = AllSQL()

     def a_method(self):
         zsql = self.sql.zsql
         result_set = zsql(arg="spam")
         ...


So I can keep all SQL in one place and I like to separate SQL from 
Python :-)

cheers, peter.

--------------ms090809020209070107070804
Content-Type: application/x-pkcs7-signature; name="smime.p7s"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="smime.p7s"
Content-Description: S/MIME Cryptographic Signature

MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAQAAoIIJcjCC
AxcwggKAoAMCAQICAwlZhTANBgkqhkiG9w0BAQQFADCBkjELMAkGA1UEBhMCWkExFTATBgNV
BAgTDFdlc3Rlcm4gQ2FwZTESMBAGA1UEBxMJQ2FwZS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