You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by barak <ba...@fetchbook.info> on 2005/08/28 08:58:12 UTC
count rows in a table
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
Re: count rows in a table
Posted by Thomas Fischer <fi...@seitenbau.net>.
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 <th...@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
Re: count rows in a table
Posted by Thomas Vandahl <th...@tewisoft.de>.
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