You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by Michael Burschik <Bu...@lotto-berlin.de> on 2003/10/23 11:30:34 UTC

Problems with Criteria and ORDER BY

The BasePeer.createQuery method checks whether the order by column contains
a "." and throws an exception if it does not. This is not a very good idea.
First of all, it does not catch non-existent column names that happen to
include a ".". And secondly, it does not allow for the perfectly legal use
of a column alias in the order by statement, e.g. "select somecolumn,
count(*) as count from mytable order by count". Is there another way to get
this, apart from the obvious solution of building the statement manually?

Regards

Michael Burschik


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


AW: Problems with Criteria and ORDER BY

Posted by Michael Burschik <Bu...@lotto-berlin.de>.

> -----Ursprüngliche Nachricht-----
> Von: Maurice Wijtten [mailto:mwi@lucka.nl]
> Gesendet: Donnerstag, 23. Oktober 2003 12:43
> An: Apache Torque Users List
> Betreff: Re: Problems with Criteria and ORDER BY
>
>
> Why don't just use       criteria.addSelectColumn("count(" +
> PeerName.fieldconstant + ")");
> The field constants usually include the tablename. (usually you'll be
> able to find a column as
> a substitute for the * sign).
>
> Maurice Wijtten

The difficult part is the "order by" part. I want to order the result set
according to the "count(whatever)" column.

Regards

Michael Burschik


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


Re: Problems with Criteria and ORDER BY

Posted by Maurice Wijtten <mw...@lucka.nl>.
Why don't just use       criteria.addSelectColumn("count(" + 
PeerName.fieldconstant + ")");
The field constants usually include the tablename. (usually you'll be 
able to find a column as
a substitute for the * sign).

Maurice Wijtten


Amit Rana wrote:

>Use criteria.addSelectColumn("count(*)"); to add count(*)
>Use tablePeer. doSelectVillageRecords(criteria) to retrieve records
>
>then you can fetch the value from the list.
>
>HTH
>
>  
>
>>-----Original Message-----
>>From: Michael Burschik [mailto:Burschik@lotto-berlin.de]
>>Sent: Thursday, October 23, 2003 6:31 PM
>>To: torque-user@db.apache.org
>>Subject: Problems with Criteria and ORDER BY
>>
>>The BasePeer.createQuery method checks whether the order by column
>>    
>>
>contains
>  
>
>>a "." and throws an exception if it does not. This is not a very good
>>    
>>
>idea.
>  
>
>>First of all, it does not catch non-existent column names that happen
>>    
>>
>to
>  
>
>>include a ".". And secondly, it does not allow for the perfectly legal
>>    
>>
>use
>  
>
>>of a column alias in the order by statement, e.g. "select somecolumn,
>>count(*) as count from mytable order by count". Is there another way
>>    
>>
>to get
>  
>
>>this, apart from the obvious solution of building the statement
>>    
>>
>manually?
>  
>
>>Regards
>>
>>Michael Burschik
>>
>>
>>---------------------------------------------------------------------
>>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


RE: Problems with Criteria and ORDER BY

Posted by Amit Rana <ra...@solis.jp>.
Use criteria.addSelectColumn("count(*)"); to add count(*)
Use tablePeer. doSelectVillageRecords(criteria) to retrieve records

then you can fetch the value from the list.

HTH

> -----Original Message-----
> From: Michael Burschik [mailto:Burschik@lotto-berlin.de]
> Sent: Thursday, October 23, 2003 6:31 PM
> To: torque-user@db.apache.org
> Subject: Problems with Criteria and ORDER BY
> 
> The BasePeer.createQuery method checks whether the order by column
contains
> a "." and throws an exception if it does not. This is not a very good
idea.
> First of all, it does not catch non-existent column names that happen
to
> include a ".". And secondly, it does not allow for the perfectly legal
use
> of a column alias in the order by statement, e.g. "select somecolumn,
> count(*) as count from mytable order by count". Is there another way
to get
> this, apart from the obvious solution of building the statement
manually?
> 
> Regards
> 
> Michael Burschik
> 
> 
> ---------------------------------------------------------------------
> 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


Re: Problems with Criteria and ORDER BY

Posted by Tulsi Das <qu...@yahoo.com>.
I had the exact same problem, and someone on the list solved it. You
will need to patch BasePeer and rebuild Torque.

As in my 3.0.2 dist:

(line aprox 1230)
if (aliases.containsKey(alias)) {
  orderByClause.add(orderByColumn);
}
else {
if (orderByColumn.indexOf('.') == -1) {
  throwMalformedColumnNameException(
  .
  .
  .
}

e-mail and I can send you the patched jar (remind it is v 3.0.2)


 --- Michael Burschik <Bu...@lotto-berlin.de> escribió: 
> The BasePeer.createQuery method checks whether the order by column
> contains
> a "." and throws an exception if it does not. This is not a very good
> idea.
> First of all, it does not catch non-existent column names that happen
> to
> include a ".". And secondly, it does not allow for the perfectly
> legal use
> of a column alias in the order by statement, e.g. "select somecolumn,
> count(*) as count from mytable order by count". Is there another way
> to get
> this, apart from the obvious solution of building the statement
> manually?
> 
> Regards
> 
> Michael Burschik
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>  

------------
Internet GRATIS es Yahoo! Conexión
4004-1010 desde Buenos Aires. Usuario: yahoo; contraseña: yahoo
Más ciudades: http://conexion.yahoo.com.ar

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