[ZPT] sql to zpt question, was: (no subject)
Wed, 9 Apr 2003 18:18:47 +0200
> 1 <body
> 2 tal:define=
> 3 "l_collaboration here/collaboration;
> 4 q_clbr_id
> 5 l_clbr_id q_clbr_id/clbr_id;
> [ I've provided line numbers for reference. ]
> Three points about the above:
> I) I've defined a new variable, l_collaboration, based on an acquired
> value. I've done this because I couldn't get a direct use of the value
> as a query parameter to work. That is, use of "here/collaboration"
> instead of "l_collaboration" in line 4 did not work. Should this be?
"here/collaboration" is a "path expression" which does not work inside
a "python expression". Using "here.collaboration" instead should do.
> II) In 4, I use  to get the first (and what should be only) member of
> the rowset. I've seen this idiom referenced elsewhere on this list.
If You can get multiple results, You have to tell which one to pick.
The ZSQLMethod does not know you select by primary key or so, thus
it expects multiple results, and always returns a list.
> III) In 5, I extract the column of interest from the row.
> Wordy? Yes. Sufficient? Apparently so. Necessary? You tell me.
If You think its too lengthy or obfuscated, You could write a
"Python script" instead doing the necessary caclulations, and call this
from the Page template.
The advantage of this approach is that there is less code in the page
The disadvantage is a that you will have a lot of little Python script
lying around preparing things for your page template, if You use this
I guess its a matter of taste what is better