Rik Hoekstra <rik.hoekstra@inghist.nl> wrote:
Jonothan Farr wrote:
Um, more or less (apart from the quotes). The ZSQL Methods use namespace different from than normal DTML documents/methods (though I don't exactly know how). Therefore you have to call them explicitly with an argument.
Sometimes you do, sometimes you don't. I know that sometimes I can acquire ZSQL method parameters from the request. Sometimes I have to provide them explicitly. I haven't been able to figure out what the rules are, either. If anyone out there could explain this behavior I'm sure lots of us would be grateful.
Hm, I _think_ I recall (but I can't test this right now) that the ZSQL method will only accept values that are given explicitly in its arguments and in that case it will also acquire them. That would make sense from a security point of view. Or perhaps it was a bit more complicated - I have to investigate this
I think the best analogy is to think of ZSQLMethods, ExternalMethods, and PythonMethods like "normal" functions in C: they receive information via arguments, and acquisition is always done via one of the explicitly-passed arguments. DTMLMethods/Documents are in some ways more like C macros: they grab information from the surrounding DTML context, without having to be told what they can "see". The analogy breaks down at the "call site": Zope looks at the explicit parameter lists and tries hard to match arguments to any parameters which are not explicitly passed by the caller: normally, it does this by looking them up in the REQUEST object, *not* in the current DTML namespace. Therefore, whenever calling a non-DTML method (External/Python/ZSQL/...): * poke all interesting values into the REQUEST object before calling:: <dtml-comment> calling 'foo( bar, baz )' </dtml-comment> <dtml-call "REQUEST.update( { 'bar' : 42, 'baz' : 3.1415926 } )"> <dtml-var foo> This version has the advantage of avoiding the "expression" syntax of DTML, but does require polluting the REQUEST namespace (may be an actual advantage if multiple methods use the same values). * pass the values explicitly, using positional arguments:: <dtml-comment> calling 'foo( bar, baz )' </dtml-comment> <dtml-var "foo( 42, 3.1415926 )"> This version looks most "natural" to a programmer, but is fragile WRT changes in the parameter list (changing the order of parameters on the method silently breaks this call). * pass the values explicitly, using keyword arguments for clarity:: <dtml-comment> calling 'foo( bar, baz )' </dtml-comment> <dtml-var "foo( bar=42, baz=3.1415926 )"> This version, which I prefer for any method taking more than one argument, says explicitly what it is doing, and therefore eases maintenance. Tres. -- ========================================================= Tres Seaver tseaver@palladion.com 713-523-6582 Palladion Software http://www.palladion.com