I'm not sure I understand. Suppose my sql query string looks like this:
sqlstatement='''<params>admin_login_name admin_password</params>
Lose the <params /> part.
You specify the parameters to the ZSQL method when instantiating the ZSQL object.
The signature of the ZSQL __init__ looks like this:
def __init__(self, id, title, connection_id, arguments, template):
self is self
id is the id of the zope object
title is the title string of the zope object
connection_id is the id of the database connection
arguments is a string specifying the keyword args, eg. """admin_login_name:string admin_password:string"""
template is your sql statement incl. dtml
Ok. I understand.
SELECT * FROM service_provider WHERE <dtml-let admin_login_name="_.string.upper(admin_login_name)"> UPPER(admin_login_name) = <dtml-sqlvar admin_login_name type="string"> </dtml-let> AND admin_password = <dtml-sqlvar admin_password type="string">'''
How do I then pass the keyword arguments?
If I do some os.listdir(...) on my files, I'll be able to hack-parse the parameters and create the methods on the fly with parameters. Added benefit is that I'll be able to use arguments instead of only keyword arguments.
I THINK you still have to pass keyword args (but I could be mistaken)
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?