Graham Borland
Graham Borland

Reputation: 60681

Android: Custom collation in SQLite

Is there a way of getting SQLite on Android to use a custom collation routine?

I'm aware of SQLite's C interface to do this, so I guess I could do it by writing C code for building with the NDK, but I'd really prefer a way to do it at a higher level.

I need to arrange things so that the text B-9 is sorted before B-29, for example. The default alphabetical sort gets them the wrong way round.

Upvotes: 3

Views: 1171

Answers (1)

Mikael Vandmo
Mikael Vandmo

Reputation: 945

I am pretty sure that there is no way to do this in Android.

My suggestion would be to have a custom column used for ordering where you insert the value in a modified way that gets sorted as you wish.

In your case you could insert B-9 as B-09 or B-00....09 depending on the max value.

Upvotes: 5

Related Questions