cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aristedes Maniatis <...@maniatis.org>
Subject Re: String-with-number sort and insert order preservation
Date Wed, 03 Feb 2010 01:06:49 GMT
On 3/02/10 11:45 AM, Marek Ĺ abo wrote:
> Hi all,
>
> I would like to ask you two questions:
>
> 1) Is there any way to sort varchar fields which happen to numbers, more
> precisely ipv4s?
> query.addOrdering(Ip4Address.IP_ADDRESS_PROPERTY, SortOrder.ASCENDING);
> This of course sets the hundreds as first in line, any tips on some
> custom sorting?

I doubt any database is going to be able to cope with that sorting, so you are going to have
to do that in memory after you have fetched all your data.


> Is there any way how to override this mechanism in order to preserve
> order of inserted rows?

Meaningful primary keys are usually considered evil when using an ORM (and even if you aren't).
You are far better off adding another sortOrder field (could be int or perhaps a datetime)
which is under your control and let the primary key be used only as a primary key.

Ari



-- 
-------------------------->
Aristedes Maniatis
GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A

Mime
View raw message