You can always use and old trick:
Select * from table where true ... This will return everything ;-))

Right, without kidding.

You can do something like this, if you're query depends on a lot of parameters

<xsp:logic>
String p1 = request.getParameter("p1") ;
String p2 = request.getParameter("p2") ;

String sql = "select * from myTable where true " ;

if (p1 != null)
{ sql = sql + " and p1 = '" + p1 + "'" } ;

if (p2 != null)
....
</xsp:logic>

In the end you have a decent query without having to check on parameters again, nor do you have to split you're code into if then else ...if then else




On 05 Apr 2004, at 16:53, olivier demah wrote:

This code is ok
<blog_addnews>
<xsp:logic>
String id_blog_user = request.getParameter("id_blog_user");
String id_blog_news = request.getParameter("id_blog_news");
if ( id_blog_user == null) {
id_blog_user = <xsp-session-fw:getxml context="authentication" as="string" path="/authentication/data/id_blog_user"/> ;
}
if (id_blog_news == null) {
<esql:connection>
<esql:pool>mblog_pg</esql:pool>
<esql:execute-query>
<esql:query>
SELECT * FROM blog_news WHERE blog_news.id_blog_user = '<xsp:expr>id_blog_user</xsp:expr>'
</esql:query>
<esql:results>
<esql:row-results>
<blog_new>
<id_blog_news><esql:get-int column="id_blog_news"/></id_blog_news>
<id_blog_user><esql:get-string column="id_blog_user"/></id_blog_user>
<news_title><esql:get-string column="news_title"/></news_title>
<news_text><esql:get-string column="news_text"/></news_text>
<news_image><esql:get-string column="news_image"/></news_image>
<news_date_creation><esql:get-string column="news_date_creation"/></news_date_creation>
<news_date_modify><esql:get-string column="news_date_modify"/></news_date_modify>

</blog_new>
</esql:row-results>
</esql:results>
</esql:execute-query>
</esql:connection>
} else {
<esql:connection>
<esql:pool>mblog_pg</esql:pool>

<esql:execute-query>
<esql:query>
SELECT * FROM blog_news WHERE blog_news.id_blog_user = '<xsp:expr>id_blog_user</xsp:expr>' AND id_blog_news = '<xsp:expr>id_blog_news</xsp:expr>'
</esql:query>
<esql:results>
<esql:row-results>
<blog_new>
<id_blog_news><esql:get-int column="id_blog_news"/></id_blog_news>
<id_blog_user><esql:get-string column="id_blog_user"/></id_blog_user>
<news_title><esql:get-string column="news_title"/></news_title>
<news_text><esql:get-string column="news_text"/></news_text>
<news_image><esql:get-string column="news_image"/></news_image>
<news_date_creation><esql:get-string column="news_date_creation"/></news_date_creation>
<news_date_modify><esql:get-string column="news_date_modify"/></news_date_modify>

</blog_new>
</esql:row-results>
</esql:results>
</esql:execute-query>
</esql:connection>
}
</xsp:logic>
</blog_addnews>
</xsp:page>



this one is not ok :

<blog_addnews>
<xsp:logic>
String id_blog_user = request.getParameter("id_blog_user");
String id_blog_news = request.getParameter("id_blog_news");
if ( id_blog_user == null) {
id_blog_user = <xsp-session-fw:getxml context="authentication" as="string" path="/authentication/data/id_blog_user"/> ;
}


<esql:connection>
<esql:pool>mblog_pg</esql:pool>

<esql:execute-query>
<esql:query>
if (id_blog_news == null) {
SELECT * FROM blog_news WHERE blog_news.id_blog_user = '<xsp:expr>id_blog_user</xsp:expr>'
} else {
SELECT * FROM blog_news WHERE blog_news.id_blog_user = '<xsp:expr>id_blog_user</xsp:expr>' AND id_blog_news = '<xsp:expr>id_blog_news</xsp:expr>'
}
</esql:query>
<esql:results>
<esql:row-results>
<blog_new>
<id_blog_news><esql:get-int column="id_blog_news"/></id_blog_news>
<id_blog_user><esql:get-string column="id_blog_user"/></id_blog_user>
<news_title><esql:get-string column="news_title"/></news_title>
<news_text><esql:get-string column="news_text"/></news_text>
<news_image><esql:get-string column="news_image"/></news_image>
<news_date_creation><esql:get-string column="news_date_creation"/></news_date_creation>
<news_date_modify><esql:get-string column="news_date_modify"/></news_date_modify>

</blog_new>
</esql:row-results>
</esql:results>
</esql:execute-query>
</esql:connection>
</xsp:logic>
</blog_add>


but why cant i just do a simple if just on the esql-query part ?


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Met vriendelijke groeten,
Bien � vous,
Kind regards,

Yves Vindevogel
Implements

Mail: [EMAIL PROTECTED] - Mobile: +32 (478) 80 82 91

Kempische Steenweg 206 - 3500 Hasselt - Tel-Fax: +32 (11) 43 55 76
Markt 18c - 9700 Oudenaarde - Tel: +32 (55) 30 55 76

Web: http://www.implements.be
<x-tad-smaller>
First they ignore you. Then they laugh at you. Then they fight you. Then you win.
Mahatma Ghandi.</x-tad-smaller>

Reply via email to