Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 848
Graham Borland Avatar asked Feb 05 '26 07:02

Graham Borland


1 Answers

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.

like image 174
Mikael Vandmo Avatar answered Feb 07 '26 21:02

Mikael Vandmo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!