Discussion:
[Erp5-dev] ZSQLCatalog sort-on parameter
Sebastien Robin
2005-09-29 08:28:27 UTC
Permalink
Hi all,

As a reminder, it is possible to use the sort-on parameter to get an
ordered list when we call searchFolder or portal_catalog, like this:

portal_catalog(portal_type='resource',sort-on=[('reference','ascending')])

Let's say you have 3 references ('1','2','15'), you will have objects
sorted with the following references :

['1','15','2']

In this case, the reference is like a text in mysql so, it will probably
not in the order expected. So I added one more parameter (it is optional)
to sort-on, and if your references are only numbers, you can use this :

portal_catalog(portal_type='resource',sort-on=[('reference','ascending','int')])

This use the following thing in mysql :

ORDER BY CAST(reference AS SIGNED)

Then the order will be like this :

['1','2','15']

It is working very fast with MySQL (I tried with a lot of data), and it
does not fails if there some string instead of numbers.

This is also working with related keys, and ZSQLCatalog.

Seb.
--
Sebastien Robin, Nexedi Technical Director
Nexedi: Consulting and Development of Free / Open Source Software
http://www.nexedi.com
ERP5: Free / Open Source ERP Software for small and medium companies
http://www.erp5.org
Storever: OpenBrick, WiFi infrastructure, notebooks and servers
http://www.storever.com
Loading...