[Zope] ZSQLMethodFile?

Oliver Bleutgen myzope@gmx.net
Wed, 11 Jun 2003 18:47:21 +0200


Peter Bengtsson wrote:
> 
> 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?

I'd guess that this has trouble finding the db connection.
I have had your problem, too, and after a lot of looking around, I found 
this (maybe it's the right thing for you).
http://www.zope.org/Members/jccooper/extzsql

Since I didn't have a lot of SQL-connections, I didn't do it that way.
My product looks like this:

from Products.ZSQLMethods.SQL import SQLConnectionIDs

class my_product(...)

    def __init__(self,container):
         wrapped_self = self.__of__(container)
         wrapped_self._addSQLMethods()

    def _addSQLMethods(self):
         self.manage_addFolder('SQLFolder')
         SQLFolder = getattr(self,'SQLFolder')
         addSQL = 
SQLFolder.manage_addProduct['ZSQLMethods'].manage_addZSQLMethod
         SQLConnectionID = SQLConnectionIDs(SQLFolder)[0][0]
         insertSQL = """INSERT INTO bla VALUES (<dtml-sqlvar ...  ) """
         inserSQLArguments = """name:string ..."""
         addSQL('insertSQL',...)
         ...

    def refresh(self):
         """ refresh all instance SQL_methods"""
         self.manage_delObjects('SQLFolder')
         self._addSQLMethods()



This is surely not the most elegant way to do it, but it works. And it 
helps in development to be able to edit/test the sql methods directly.

cheers,
oliver