You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Frank <fa...@hotmail.com> on 2007/05/10 03:26:02 UTC

how do I read group records?

Hello,

I have a cayenne routine that returns records using an SQLTemplate.
I return the records in a List

sql = "SELECT COUNT(ticketId) AS cnt, userName FROM table"

List list - query.performQuery(ticket.class, sql)
return list

How do I access each column in the list?
I tried created a class with th etwo fields in the query, but that failed.

I want to iterate through the list and assign the values of cnt and userName

Thanks

Frank

Re: how do I read group records?

Posted by Frank <fa...@hotmail.com>.
Thanks Mike,

I'll try it tomorrow.
The only difference, is I need to iterate each row in the list and pull the 
values.
so I am thinking I should use the Map in your example on each list.next().

regards,
Frank
----- Original Message ----- 
From: "Mike Kienenberger" <mk...@gmail.com>
To: <us...@cayenne.apache.org>
Sent: Wednesday, May 09, 2007 9:30 PM
Subject: Re: how do I read group records?


> Here's an example.  Maybe it'll help.
>
>
>    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 5/9/07, Frank <fa...@hotmail.com> wrote:
>> Hello,
>>
>> I have a cayenne routine that returns records using an SQLTemplate.
>> I return the records in a List
>>
>> sql = "SELECT COUNT(ticketId) AS cnt, userName FROM table"
>>
>> List list - query.performQuery(ticket.class, sql)
>> return list
>>
>> How do I access each column in the list?
>> I tried created a class with th etwo fields in the query, but that 
>> failed.
>>
>> I want to iterate through the list and assign the values of cnt and 
>> userName
>>
>> Thanks
>>
>> Frank
> 


Re: how do I read group records?

Posted by Mike Kienenberger <mk...@gmail.com>.
Here's an example.  Maybe it'll help.


    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 5/9/07, Frank <fa...@hotmail.com> wrote:
> Hello,
>
> I have a cayenne routine that returns records using an SQLTemplate.
> I return the records in a List
>
> sql = "SELECT COUNT(ticketId) AS cnt, userName FROM table"
>
> List list - query.performQuery(ticket.class, sql)
> return list
>
> How do I access each column in the list?
> I tried created a class with th etwo fields in the query, but that failed.
>
> I want to iterate through the list and assign the values of cnt and userName
>
> Thanks
>
> Frank