Re: SelectQuery and getting where clause

From: David Marko (dmark..iscali.cz)
Date: Tue Oct 09 2007 - 10:21:46 EDT

  • Next message: Andrus Adamchik: "Re: SelectQuery and getting where clause"

    Thanks, its really what I needed.

    The reason why I asked is as follow. The EntityManager for Cayenne(my previous
    post) offers aggregate functions (count, sum, average, max). To accomblish this
    I created SelecteQuery e.g. q="SELECT COUNT(*) as count, $name as name FROM
    ROLE GROUP BY $name"; for queries with 'where' constrains I use special Query
    syntax(wrapper for cayenne expression) and I need the 'where' clause to be put
    into manualy created 'select count(*) .... ' query. Not easy to explain without
    detailed code though.

    // and this is how I call it: em is EntityManager
    List<DataRow> li= em.count(Item.class, Item.NAME_PROPERTY, Query.where("year >
    $year").addParam("year", 2003));

    // or sum
    List<DataRow> li= em.sum(Item.class, Item.PROFIT_PROPERTY,
    Item.PRODUCT_NAME_PROPERTY, Query.where("year > $year").addParam("year", 2003));

    David

    Michael Gentry wrote:
    > Will:
    >
    > Expression exp = sq.getQualifier();
    > String clause = exp.toString();
    >
    > do what you are wanting?
    >
    >
    > On 10/9/07, David Marko <dmark..iscali.cz> wrote:
    >> Hello, I need to create a select query that have some parameters and I need to
    >> get SQL where statement from it containing replaced parameters. (see snippet
    >> below) . Is there any way how to accomplish this?
    >>
    >>
    >> [Code snippet]
    >> SelectQuery sq = new
    >> SelectQuery(Role.class,Expression.fromString(this.whereClause));
    >> return sq.queryWithParameters(params);
    >>
    >



    This archive was generated by hypermail 2.0.0 : Tue Oct 09 2007 - 10:22:26 EDT