You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Christian Parpart <cp...@t-online.de> on 2000/11/15 00:14:23 UTC

how to create dynamic SQL-queries?

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?

Regards,
Christian Parpart
mailto:cparpart@surakware.com
http://www.surakware.com (new http://surak.cocoonhsot.com)


Re: AW: how to create dynamic SQL-queries?

Posted by Donald Ball <ba...@webslingerZ.com>.
On Wed, 15 Nov 2000, Christian Parpart wrote:

> > > 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>
> >
> 
> Please give me an example for the below.
> 
> > 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.

oh, c'mon, it's not that hard to mess around and figure it out:

<xsp:logic>
  String my_query = // whatever;
</xsp:logic>
<esql:connection>
  ...
  <esql:execute-query> 
    <esql:query><xsp:expr>my_query</xsp:expr></esql:query>
  </esql:execute-query>
</esql:connection>

- donald


AW: how to create dynamic SQL-queries?

Posted by Christian Parpart <tr...@gmx.de>.
> > 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>
>

Please give me an example for the below.

> 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
>

Regards,
Christian Parpart
mailto:cparpart@surakware.com
http://www.surakware.com (new http://surak.cocoonhsot.com)


Re: how to create dynamic SQL-queries?

Posted by Donald Ball <ba...@webslingerZ.com>.
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