db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Fischer <fisc...@seitenbau.net>
Subject RE: select max(column)
Date Wed, 06 Apr 2005 08:21:59 GMT




Well, the reason why one cannot use XXXPeer.doSelect() to find out the
maximum value of a colum is that the XXX Object has not got a place to hold
the value of MAX(someColumn), at least not a place that Torque knows of.
This is independent of the type of the column. So one ends up using the
BasePeer.doSelectVillageRecords() methods.

The difference between criteria.and and Criteria.add is that Criteria.add()
never keeps a order of precedence of operators (such like (conditon1 and
(condition2 and condition3))), but Criteria.and does, if there exists
another condition for the specified column. But most of the time, they are
the same (see criteria Source code appended below).
I have never used Criteria.and myself. If you do not have a reason for
doing otherwise, use Criteria.add().

    /**
     * This method adds a prepared Criterion object to the Criteria.
     * You can get a new, empty Criterion object with the
     * getNewCriterion() method. If a criterion for the requested column
     * already exists, it is &quot;AND&quot;ed to the existing criterion.
     * This is used as follows:
     *
     * <p>
     * <code>
     * Criteria crit = new Criteria();
     * Criteria.Criterion c = crit.getNewCriterion(BasePeer.ID, new
Integer(5),
     *         Criteria.LESS_THAN);
     * crit.and(c);
     * </code>
     *
     * @param c A Criterion object
     * @return A modified Criteria object.
     */
    public Criteria and(Criterion c)
    {
        Criterion oc = getCriterion(c.getTable() + '.' + c.getColumn());

        if (oc == null)
        {
            add(c);
        }
        else
        {
            oc.and(c);
        }
        return this;
    }


"jill han" <jhan@bynum.com> schrieb am 05.04.2005 23:08:14:

> I tried to get a max value of a column with type date.
> The codes are like:
>
> Criteria crit = new Criteria();
> crit.add(XXXXPeer.String, Object, Criteria.EQUAL);
> crit.addSelectColumn("MAX(" + XXXXPeer.aDate + ")");
> crit.add(XXXXPeer.String, Object, Criteria.EQUAL);
> List result = XXXXPeer.doSelect(crit);
>
> But it is not working.
> The exception says:
> Error: org.apache.torque.TorqueException: Illegal conversion:
> com.workingdogs.village.DataSetException: Invalid type for Integer
>
> Does it mean it is type related?
> Another question, what is the key difference between Criteria.add and
> Criteria.and?
>
> Thanks in advance.
>
> Jill
>
>
>
> -----Original Message-----
> From: Thomas Fischer [mailto:fischer@seitenbau.net]
> Sent: Tuesday, March 29, 2005 2:01 AM
> To: Apache Torque Users List
> Subject: RE: select max(column)
>
>
>
>
>
> Look in the wiki. Ther it is described how to select count(*) from a
> table.
> The same procedure can be used to find out "max(" + SomePeer.COLUMN_NAME
> +")";
>
> http://wiki.apache.org/db-torque/FrequentlyAskedQuestions#head-9317e897d
> 07dbd597993796d47bfbbe2443bc5bf
>
>     Thomas
>
>
> "Kintzel Levente" <kintzel.levente@softech.ro> schrieb am 24.03.2005
> 14:19:30:
>
> >
> >    Hi!
> >
> > I want to determine the max value of a column with Torque. How can I
> do
> > this? Thanx!
> >
> >          Levi Kintzel
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> > For additional commands, e-mail: torque-user-help@db.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>


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


Mime
View raw message