Re: How do I return a record count?

From: Frank (farocc..otmail.com)
Date: Fri Mar 23 2007 - 11:19:43 EDT

  • Next message: Frank: "Re: How do I return a record count?"

    Thanks Mike, that did the trick.

    List list = context.performQuery(query);
    Map row = (Map)list.get(0);
    String cnt = row.get("cnt").toString();

    Regards,

    Frank
    ----- Original Message -----
    From: "Mike Kienenberger" <mkienen..mail.com>
    To: <use..ayenne.apache.org>
    Sent: Friday, March 23, 2007 11:13 AM
    Subject: Re: How do I return a record count?

    > Sounds right. I haven't used named queries so I wasn't aware of how
    > they are configured. If that's the case, what sql output do you see
    > in the logs?
    >
    > Here's some sample code that might be helpful. It doesn't do quite
    > the same thing, but it's pretty close in structure and data returned.
    >
    > private Integer fetchDocumentNumberAutoIncrement() {
    > String defaultSql = "SELECT #result('max(DOCUMENT_NUMBER)+1'
    > 'long' 'ID') FROM ENG_WORK_MGMT.AUTHORIZATION_DOCUMENT";
    > String oracleSql = "SELECT
    > #result('SEQ_AuthDocDocumentNumber.NextVal' 'long' 'ID') FROM DUAL";
    >
    > SQLTemplate rawSelect = new SQLTemplate(getClass(), defaultSql);
    > rawSelect.setTemplate(OracleAdapter.class.getName(), oracleSql);
    > rawSelect.setFetchingDataRows(true);
    >
    > List list = getDataContext().performQuery(rawSelect);
    > Map row = (Map)list.get(0);
    >
    > Number autoincrementID = (Number)row.get("ID");
    >
    > return new Integer(autoincrementID.intValue());
    > }
    >
    >
    >
    > On 3/23/07, Frank <farocc..otmail.com> wrote:
    >> Fetch DataObjects is unchecked.
    >> Does this default to fetch DataRows?
    >>
    >> Frank
    >>
    >> ----- Original Message -----
    >> From: "Mike Kienenberger" <mkienen..mail.com>
    >> To: <use..ayenne.apache.org>
    >> Sent: Friday, March 23, 2007 11:01 AM
    >> Subject: Re: How do I return a record count?
    >>
    >>
    >> > Did you set the query to fetch DataRows (Maps) instead of DataObjects
    >> > (Entities)?
    >> >
    >> > On 3/23/07, Frank <farocc..otmail.com> wrote:
    >> >> Hello,
    >> >> I have a named query defined as:
    >> >> SELECT COUNT(ticketId) AS cnt FROM tickets
    >> >> WHERE ticketClosed = 0
    >> >>
    >> >> This is not working, how do I get the count returned?
    >> >> NamedQuery query = new NamedQuery("openTicketsQuery");
    >> >> List records = context.performQuery(query).;
    >> >> String cnt = records.get(0).toString();
    >> >>
    >> >> Thanks
    >> >>
    >> >> Frank
    >> >>
    >> >
    >>
    >



    This archive was generated by hypermail 2.0.0 : Fri Mar 23 2007 - 11:21:26 EDT