cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Geoff Howard <coc...@leverageweb.com>
Subject Re: nested query with esql
Date Mon, 05 May 2003 14:31:10 GMT
It looks like it's getting tripped up on the white space around your 
esql:parameter inside your second query.  Since white space is significant 
in both xml and java, you'll need to pay attention to it when problems 
arise in xsp's.  First, try to change that line to:
AND categories_id = <esql:parameter type="long"><esql:get-long ancestor="1" 
column="categories_id"/></esql:parameter>

that is, no whitespace (even though your email client will probably wrap 
that line).

I'm not sure that will work, though because it may reveal a second problem 
- I'm not sure you can reference the previous result set from there (try it 
first though).  You may need to set up a local variable with the value you 
want to reference in an xsp:logic block _before_ you start the next 
esql:execute-query, and use the variable by name inside xsp:expr within the 
esql:parameter.

By the way, I don't know that you'll be able to use it with this particular 
query (because of the count() function) but using esql's group-by 
functionality should generally get you better results than actually nesting 
queries.  The examples and docs should cover its use pretty well.

HTH,
Geoff

At 10:12 AM 5/5/2003, you wrote:
>hi all,
>
>first, my environment:
>cocoon 2.0.4
>tomcat 4.0.4
>jdk 1.3.1_02
>mm.mysql driver 2.0.11
>
>i only began working with cocoon about a week ago, so i'm definitely a 
>newbie.  i'm trying to work with a nested query but it's producing an 
>error in the generated java code.  here's my xsp code:
>
><xsp:page
>     language="java"
>     xmlns:xsp="<http://apache.org/xsp>http://apache.org/xsp"
> 
>xmlns:esql="<http://apache.org/cocoon/SQL/v2>http://apache.org/cocoon/SQL/v2"
>     >
>
>         <esql:connection>
>             <esql:pool>quotescape</esql:pool>
>
>             <esql:execute-query>
>
>                 <esql:query>
>                     SELECT categories_id, categories_name
>                         FROM categories_description
>                 </esql:query>
>
>                 <esql:results>
>                     <product-categories>
>                         <esql:row-results>
>                             <category>
>                                 <id><esql:get-long 
> column="categories_id"/></id>
>                                 <name><esql:get-string 
> column="categories_name"/></name>
>
>                                 <!-- get the number of products in the 
> category -->
>                                 <esql:execute-query>
>                                     <esql:query>
>                                         SELECT COUNT(*) AS count FROM 
> products, products_to_categories
>                                             WHERE products.products_id = 
> products_to_categories.products_id
>                                                 AND categories_id =
>                                                     <esql:parameter 
> type="long">
>                                                         <esql:get-long 
> ancestor="1" column="categories_id"/>
>                                                     </esql:parameter>
>                                     </esql:query>
>
>                                     <esql:results>
>                                         <esql:row-results>
>                                             <count><esql:get-int 
> column="count"/></count>
>                                         </esql:row-results>
>                                     </esql:results>
>                                 </esql:execute-query>
>                             </category>
>                         </esql:row-results>
>                     </product-categories>
>                 </esql:results>
>
>             </esql:execute-query>
>         </esql:connection>
></xsp:page>
>
>and here's the relevant snippet from the exception in error.log:
>
>org.apache.cocoon.components.language.LanguageException: Error compiling 
>index_productcategories_xsp:
>Line 432, column 56:  unclosed character literal
>Line 432, column 55:  illegal start of expression
>Line 434, column 55:  unclosed character literal
>
>and here are the relevant lines in the generated java:
>
>     _esql_query = new EsqlQuery( _esql_connection, String.valueOf(
>       ""
>
>
>                 + "                                         SELECT 
> COUNT(*) AS count FROM products, 
> products_to_categories                                             WHERE 
> products.products_id = 
> products_to_categories.products_id 
> AND categories_id =                                                      "
>
>
>                 + "?"
>
>                 + "                                     "
>               ) );
>
>
>
>     try {
>
>             _esql_query.prepareStatement();
>           _esql_query.getPreparedStatement().setLong(1,"
>
>                                                     ");
>
>             _esql_query.execute();
>
>i've search through the archives and noticed a few cases where people were 
>having similar problems, but i didn't see any resolutions.  i also saw a 
>post that seemed to mention a bug dealing with prepared statements, but 
>i'm not sure.
>
>thanks in advance for your help!
>
>Mike Lenyon


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-users-help@xml.apache.org


Mime
View raw message