You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Laurent Marchal <lm...@smaeur.com> on 2008/09/11 17:53:07 UTC

Returning updated rows from SQLTemplate

Hello !

I use Cayenne 3.0M4 and since UpdateQuery is deprecated i use a 
SQLTemplate query to do an UPDATE.
The thing is i would like to know how many rows are updated, and the 
query returns no DataRows.

SQLTemplate query = new SQLTemplate(..., "UPDATE...");
query.setFetchingDataRows(true);

List<DataRow> dtList = context.performQuery(query);

the returned list is always empty....
How can i get the precious Integer saying "X rows updated" ?

Thanks.
Laurent Marchal.



Re: Returning updated rows from SQLTemplate

Posted by Michael Shea <mi...@nitido.com>.
int[] updateCounts = context.performNonSelectingQuery( query );

=).

Mike Shea.

> Hello !
>
> I use Cayenne 3.0M4 and since UpdateQuery is deprecated i use a 
> SQLTemplate query to do an UPDATE.
> The thing is i would like to know how many rows are updated, and the 
> query returns no DataRows.
>
> SQLTemplate query = new SQLTemplate(..., "UPDATE...");
> query.setFetchingDataRows(true);
>
> List<DataRow> dtList = context.performQuery(query);
>
> the returned list is always empty....
> How can i get the precious Integer saying "X rows updated" ?
>
> Thanks.
> Laurent Marchal.
>
>


Re: Returning updated rows from SQLTemplate

Posted by Andrus Adamchik <an...@objectstyle.org>.
Hi,

You need to use a different DataContext method

> List<DataRow> dtList = context.performQuery(query);

Should be

int[] updateCounts = context.performNonSelectingQuery(query);

now if you are referencing ObjectContext throughout the code (hiding  
DataContext implementation), there is an even more generic method:

QueryResponse result = context.performGenericQuery(query);
int[] updateCounts = result.firstUpdateCount();


The two examples above are doing the same exact thing.

Andrus


On Sep 11, 2008, at 6:53 PM, Laurent Marchal wrote:

> Hello !
>
> I use Cayenne 3.0M4 and since UpdateQuery is deprecated i use a  
> SQLTemplate query to do an UPDATE.
> The thing is i would like to know how many rows are updated, and the  
> query returns no DataRows.
>
> SQLTemplate query = new SQLTemplate(..., "UPDATE...");
> query.setFetchingDataRows(true);
>
> List<DataRow> dtList = context.performQuery(query);
>
> the returned list is always empty....
> How can i get the precious Integer saying "X rows updated" ?
>
> Thanks.
> Laurent Marchal.
>
>
>