[Zope-DB] Dynamically generate sql-query in ZSQL Method

Ian Bicking ianb at colorstudy.com
Tue Apr 6 19:12:12 EDT 2004

On Apr 6, 2004, at 3:23 PM, Jim Penny wrote:
> Ian has told you how to do it.  Now, I will tell you, don't do it.

I would disagree with you -- not for some principled reason, but for a 
very practical reason: Z SQL Methods suck.  A lot.  A huge, huge 
amount.  They are horrible.  Generating your own SQL inline sucks.  A 
lot.  It is horrible.  *Sometimes* the inline method is less horrible.  
These are the unfortunate choices foisted upon us by the environment.

(Actually, it's Z SQL plus the ZMI plus DTML that is the real poison, 
IMHO -- they all work together to make things extra unpleasant)

Note also that well designed SQL generation in Python isn't horrible.  
A Python script like:

## select_all
## parameters: table_name
# re isn't available in the default Zope installation; I'd actually 
# do this with an extension method...
import re
assert re.search(r'^[a-zA-Z_][a-zA-Z0-9_]*$', table_name), "Invalid 
table name: %s" % table_name
return container.raw_sql(sql='SELECT * FROM %s' % table_name)

That isn't so bad.  In fact, I would assert it is much better than the 
Z SQL analog.

Ian Bicking | ianb at colorstudy.com | http://blog.ianbicking.org

More information about the Zope-DB mailing list