[Zope] How to keep table aliases apart in an ZSQL method

Joel Burton jburton@scw.org
Fri, 20 Jul 2001 16:41:43 -0400 (EDT)


On Fri, 20 Jul 2001, Ernst Eeldert wrote:

> Hi,
> 
> I'm having trouble passing a parameter to a ZSQL which uses table aliases.
> The SQL statement is as follows:
> 
> select
> 	e.empno
> 	,e.ename
> 	,d.dname
> from
> 	emp e
> 	,dept d
> where
> 	e.deptno = d.deptno
> <sql-group and>
> 	<dtml-sqltest e.deptno op=eq type=int optional
> </sql-group>
> 
> Now, this isn't working on two points:
> 
> 1. the <sql-group and> is my own idea, and doesn't work (apparently :)
> 2. when I put a snippet like
> 	<dtml-in expr="emp_list(e.deptno=deptno)">
> 	  <li><dtml-var ename>
> 	</dtml-in>
>    into an DTML-method, I get the following error:
> 
> 	Error Value: keyword can't be an expression

try <dtml-in expr="emp_list( { 'deptno': deptno } )">

Not that what matters is that you have 'deptno' defined as a parameter of
the ZSQL method. The fact that, in your table, the field is "deptno" is
just a coincedence. The field in the table is referenced as "e.deptno" is
fine--but that's the name of the parameter for the ZSQL method. To make is
clearer:


ZSQL method, name="find_person", parameter="name_to_find"

  SELECT * FROM People WHERE name = <dtml-sqlvar name_to_find type=string>

You'd call this as

  <dtml-in "find_person ( { 'name_to_find':'Smith, John' } )">

*not* as

  <dtml-in "find_person ( { 'name':'Smith, John' } )">


hth,

-- 
Joel Burton   <jburton@scw.org>
Director of Information Systems, Support Center of Washington