db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Fischer <fisc...@seitenbau.net>
Subject Re: count rows in a table
Date Wed, 31 Aug 2005 08:07:24 GMT




Hi,

Thomas, you code certainly works. But as Barak wrote, the more convenient
way in 3.2-RC1 is the CountHelper Class which already does do the
processing (count = ((Record)result.get(0)).getValue(1).asInt()) and also
handles criteria.setDistinct().

The problem (or rather the inconvenience) in the countHelper class is is
that it does not handle the default database for the specific table. Like
you have many databases defined and mytable is in DB1, it would be
convenient if countHelper would use the DB1 connection for counts in
mytable (and not the default connection, as it is now). But as CountHelper
does not know anything about the count being only for mytable, and
therefore it also does not know it should use DB1 for the select.

In your code, you handle it also by hand (new Criteria("MyDatabase")).

    Thomas

Thomas Vandahl <thomas.vandahl@tewisoft.de> schrieb am 31.08.2005 08:19:28:

> 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?
>
> I used to use something like the following for counting rows:
>
>    Criteria criteria = new Criteria();
>    criteria.addSelectColumn("COUNT(" + MytablePeer.ID + ")");
>
>    // add where conditions here ...
>
>    List result = BasePeer.doSelect(criteria);
>    int count = ((Record)result.get(0)).getValue(1).asInt();
>
> Hope it helps
>
> Bye, Thomas.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-dev-help@db.apache.org
>


---------------------------------------------------------------------
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