Hey folks. How do you use the <dtml-sqlgroup> & <dtml-where> clauses when you want to do a join? If I have a table of items, and a table of owners, and items have an owner_id, then selecting all of them would be something like: select o.name as ownername, i.name as itemname from owners o, items i where i.owner_id = o.id; If you wanted to re-use this query for showing items owned by a single owner, you can extend it as: select o.name as ownername, i.name as itemname from owners o, items i where i.owner_id = o.id and o.id = 2; -- Assuming the owner you were interested in was #2 Is it possible to do the join always, but the "o.id = 2" only if an owner id was provided as an optional argument? Also - in some cases I want "limit 10", and others I don't want a limit. Is the limit keyword optionable? Thanks in advance! -- Colin Fox cfox@crystalcherry.com CF Consulting Inc. GPG Fingerprint: D8F0 84E7 E7CC 5C6C 9982 F1A7 A3EB 6EA3 BC97 572F
Colin Fox writes:
How do you use the <dtml-sqlgroup> & <dtml-where> clauses when you want to do a join? Please see the embedded Zope Online Help:
Zope Help --> DTML-Reference --> sqlgroup It has a complete example. For qualified column access, you may also need the "column" attribute to "sqltest". It allows you to specify the column name. When an optional part of an SQL group operand cannot be realized with "sqltest", you can use direct SQL-fragments. The "sqlgroup"s "and/or" will be generated when the operand is non-empty independent on how it has been generated. You example will look like: select ... <dtml-sqlgroup where> i.owner_id = o.id <dtml-and> <dtml-sqltest owner_id column="o.id" type="int" optional> </dtml-group> Your ZSQL Method will need to list "owner_id" with a default value of "". Dieter
participants (2)
-
Colin Fox -
Dieter Maurer