[prev in list] [next in list] [prev in thread] [next in thread] 

List:       turbine-torque-dev
Subject:    Re: count rows in a table
From:       Thomas Fischer <fischer () seitenbau ! net>
Date:       2005-08-31 8:07:24
Message-ID: OFB1801295.64B84329-ONC125706E.002A5E0C-C125706E.002CA05C () seitenbau ! net
[Download RAW message or body]





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

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic