db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Greg Monroe" <Greg.Mon...@DukeCE.com>
Subject RE: count rows in a table
Date Tue, 30 Aug 2005 23:47:49 GMT
Quick solution might be to use MyTablePeer.DATA_BASENAME for the helper
criteria.

You can also do this with the following kind of clugdy code:

Criteria c = new Criteria();
c.addAsColumn("recCount","Count ("+MyTablePeer.ID+")");
c.add(MyTablePeer.ID, 4, SqlEnum.EQUALS);  // Need at least one where
clause to be valid.
List results =
MyTablePeer.executeQuery(MyTablePeer.createQueryString(c);
Record rec = results.get(0);  // Needs check for null!
int count = (Value) rec.getValue("recCount").getInt();  // Needs some
checking code.

But this uses some of the Village objects that are being slowly removed
from Torque.

As to how this might be implimented in in the future as an
SQLFunction...

Currently, xxxPeer.doSelect(Criteria) does not work for these because it
adds all the
table fields to the select by default.  This is done so that all the
info is available 
to populate record objects.  But if you use an aggregate function like
Count() or Avg(),
then the query fails because SQL only allows GROUP BY items to be
selected and the
resulting query has all fields.

A quick first pass at a solution for this in the function framework I
laid out would be
to use something like "type of AggregateFunction" or a value returned by
getType() to
determine if all fields would be appended to the query in
doSelectVillageRecords(..) and
if populateObjects was called or just the raw records list was returned.


Hmm, not sure I like variable object return types here.. Maybe just
forcing aggregate
functions to only work with doSelectVillageRecords() is better.  Or
*GASP* add a
doAggregateSelect() method to the BasePeer class...

Greg

> -----Original Message-----
> From: Thomas Fischer [mailto:tfischer@apache.org] 
> Sent: Tuesday, August 30, 2005 5:52 PM
> To: torque-dev@db.apache.org
> Subject: Re: count rows in a table
> 
> 
> Hi,
> 
> At the moment, this possibility does not exist. It would be 
> possible to put 
> that into the Peer classes, but the problem is that the peer 
> classes have too 
> many methodts already, and this would add new ones.
> 
> Clearing up the stuffed classes in one way or another is on 
> my list for Torque 
> 3.3, and though I see your point that a count method would be 
> useful in a Peer 
> class, I would rather not add a method in one release and 
> already remove it in 
> the next release.
> 
> Any other developers care to comment on this ?
> 
>          Thomas
> 
> On Sun, 28 Aug 2005, barak wrote:
> 
> > Hi,
> > 
> > I wanted to know if there is a way in the new version of 
> torque to use 
> > "count *" (or any other count) from a peer. I saw there is 
> an option 
> > using CountHelper like this: new CountHelper().count(new 
> > Criteria("MyDatabase").add( some_kind_of_criterion ))
> > 
> > Is there a way to use something like this from the peer so I won't 
> > have to insert my database name each peer?
> > 
> > Thanks
> > Barak
> > 
> > <http://www.fetchbook.info/> www.FetchBook.Info
> > Find the lowest price - Compare more than a hundred book 
> stores in a 
> > click
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-dev-help@db.apache.org
> 
> 

Duke CE Privacy Statement
Please be advised that this e-mail and any files transmitted with it are confidential communication
or may otherwise be privileged or confidential and are intended solely for the individual
or entity to whom they are addressed.  If you are not the intended recipient you may not rely
on the contents of this email or any attachments, and we ask that you  please not read, copy
or retransmit this communication, but reply to the sender and destroy the email, its contents,
and all copies thereof immediately.  Any unauthorized dissemination, distribution or copying
of this communication is strictly prohibited.



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Mime
View raw message