cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Donald Ball <ba...@webslingerZ.com>
Subject Re: how to create dynamic SQL-queries?
Date Wed, 15 Nov 2000 01:12:55 GMT
On Wed, 15 Nov 2000, Christian Parpart wrote:

> Hi
> 
> it's really hard and I tried it quite a long time to produce a more complex
> sql-query in xsp. But it doesn't work, why and how do I make it better?
> 
> THIS IS ONE WAY, BUT WRONG! (i hope you know what I finally want to do)
> 
> ...
> <xsp:content>
>   ...
>   <sql:query>
>     SELECT Name, Address
>       FROM AddrBook
>       WHERE 1=1
>       <xsp:logic>
>         if (request.getParameter("Name")) {
>           <xsp:content>
>             AND Name='<xsp:expr>request.getParameter("Name")</xsp:expr>'
>           </xsp:content>
>         }
>         if (request.getParameter("Address")) {
>           <xsp:content>
>             AND
> Address='<xsp:expr>request.getParameter("Address")</xsp:expr>'
>           </xsp:content>
>         }
>       </xsp:logic>
>   </sql:query>
>   ...
> </xsp:content>
> ...
> 
> Maybe, the problem is here the nested tags
> (xsp:logic/xsp:content/xsp:logic/xsp:content).
> But is there anyone, who can solve the problem?

use <xsp:expr> and java expressions:

<xsp:expr>(
  (request.getParameter("Name") != null) 
  ? " and name = '"+request.getParameter("Name")+"'"
)</xsp:expr>

or else use xsp:logic elements before the query element to build the query
string and include it in the query element as an expression.

- donald


Mime
View raw message