zsql-Methods: how to make a dynamic where-clause?
Hi, is there any convenient way, to have a dynamic where-clause in zsql-Methods? All my effords had severe limitation up to now: 1. <dtml-sqltest .. needs a fixed column=.... expression 2. WHERE <dtml-var ...> with the whole clause in the var doesn't work because of quoting problems. ... So it seems that there is only very limited scope with <sql-group and explicit column=myExplicitColumnName constructs or am I missing something? A completely dynamic query with python script would be also a good alternative but how to do that? -- thanks for any input, Elena
Elena, you could pass a parameter like params={'col1':'val1', 'col2':'val2'} and write you SQL method like: select * from table <dtml-sqlgroup where> <dtml-in "params.keys()"> <dtml-var sequence-item> = '<dtml-var "params[_['sequence-value']]">' <dtml-unless sequence-end> and </dtml-unless> </dtml-in> </dtml-sqlgroup> you can extend this to check for types, different condition joiners etc. Babu -- http://vsbabu.org/ Elena Schulz wrote:
Hi,
is there any convenient way, to have a dynamic where-clause in zsql-Methods? All my effords had severe limitation up to now: 1. <dtml-sqltest .. needs a fixed column=.... expression 2. WHERE <dtml-var ...> with the whole clause in the var doesn't work because of quoting problems. ... So it seems that there is only very limited scope with <sql-group and explicit column=myExplicitColumnName constructs or am I missing something? A completely dynamic query with python script would be also a good alternative but how to do that?
-- thanks for any input, Elena
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Hi Babu, thanks for your hints:
<dtml-var sequence-item> = '<dtml-var "params[_['sequence-value']]">' Because of security reasons I'll try if it works with dtml-sqlvar, too or I'll use the sql_quote attribute (or fmt=sql-quote). My question with sqlvar is, is there a way to change the type=whatever dynamically?
you can extend this to check for types, different condition joiners etc. then this would be more elegant.
-- Elena
participants (2)
-
Elena Schulz -
Satheesh Babu