db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Scott Eade <se...@backstagetech.com.au>
Subject Re: Count(*) and criteria
Date Sun, 02 Feb 2003 22:50:53 GMT
On 3/02/2003 9:31 AM, "peter riegersperger" <rick@subnet.at> wrote:

> On Sunday 02 February 2003 23:15, Scott Eade wrote:
>> Try something like:
>> 
>> Criteria c = new Criteria();
>> c.addSelectColumn("COUNT(" + colName + ")");
>> List result = doSelect();
>> Record rec = (Record) result.get(0);
>> int count = rec.getValue(1).asInt();
> 
> i tried. the problem is that i need the exact criteria as in the original
> query, for example:
> 
> (ahemm  - please note that i don't actually name my methods like this)
> getListAndRecordCountFromGivenCriteria (Criteria crit)
> {
> ThisPeer.doSelect(crit);
> [...]
> crit.addSelectColumn("Count(*)");
> [...]
> 
> fails because all the column names are written into the SELECT-clause as soon
> as ThisPeer.doSelect(Criteria) is called.
> so, i get a SQL-statement like:
> SELECT myTable.ID, myTable.Name, Count(*) FROM myTable;
> 
> i could get this whole thing working if there was a way to remove
> SelectColumns.

Can you not build the criteria in two parts (i.e. everything but the desired
columns) and clone it prior to adding the desired columns?

> 
>> Where colName is the name of some small column in the table (can't remember
>> why, but "*" doesn't work when the query is done this way).
> 
> ok, thanks for that hint!
> 
>> BTW: Have you looked at LargeSelect?
> 
> no. but i will.

LargeSelect may obviate the need to do the count(*) as it provides an
indication of the length of the result set as the query progresses, e.g. it
might say that it is displaying page 1 of > 25 indicating that there are
more than 25 pages of data available.

> 
> thanks,
> 
> rick


Cheers,

Scott
-- 
Scott Eade
Backstage Technologies Pty. Ltd.
http://www.backstagetech.com.au
.Mac Chat/AIM: seade at mac dot com


Mime
View raw message