Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom COLLATE #4974

Open
githubuser181226 opened this issue Apr 28, 2024 · 4 comments
Open

custom COLLATE #4974

githubuser181226 opened this issue Apr 28, 2024 · 4 comments

Comments

@githubuser181226
Copy link

githubuser181226 commented Apr 28, 2024

Hi.

By default SQLite sorting doesn't account for accented letters (ie. Polish letters: Ł, Ś, Ź..,) and if a string begins with one, ORDER BY ASC clause always puts those at the very end, which is a game breaker for me.

Is it possible to create a custom function to account for accented letters to use it as a COLLATE method and with the custom sorting functionality of the UI (ie. double-clicking on column header)?

So far I've only managed to create a simple javascript function which replaces all the accented letters in a string with ASCII non-accented equivalents, which then I can use in ORDER BY clause, but although it is somewhat helpful (values starting with accented letters are no longer at the end of the sorted list), it is far from optimal, because sorting still isn't correct and I tried using the function in the COLLATE clause, but it doesn't work.

And I can't find any documentation showing how to create javascript custom collate methods, or if that is even possible.

I'm using SQLiteStudio in Windows as a standalone DB manager for storing and managing data.

Perhaps there is an extension already to fix my issue.
Thank you in advance.

@tuffnatty
Copy link
Contributor

Have you already tried the icu extension and the Collation editor menu option?

@githubuser181226
Copy link
Author

githubuser181226 commented Apr 29, 2024

Have you already tried the icu extension and the Collation editor menu option?

Hi. Thank you for you reply.

I have ICU extension installed and and have Collation Editor in the menus.
I tried it but haven't been able to figure out how. The documenation lacks explanation on how to use it, and shows no working example. In the end I gave up.

Thankfully I then went to sqlite documentation, specifically to ICU readme file, and found out about icu_load_collation command, so I started SQL editor and ran:

SELECT icu_load_collation('pl_PL', 'POLSKI');

which created collation named POLSKI, which I then used in my tables, and voila - I now have proper sorting. Exactly what I wanted.

However, as I restarted the program it told me no such collation: POLSKI forcing me to re-run above SQL command.

Is there a way to make a collation created with icu_load_collation persistent or to auto-execute SQL commands on program startup?

Please, advise.
Thank you.

@tuffnatty
Copy link
Contributor

Is there a way to make a collation created with icu_load_collation persistent

No.

or to auto-execute SQL commands on program startup?

I don't think it's supported.

Probably in your simple case a simple JavaScript collation definition would be enough (but probably much slower than ICU):

return arguments[0].localeCompare(arguments[1], 'pl')

@pawelsalawa
Copy link
Owner

I think you may try using WxSQLite3 plugin for the database connection and then add the SELECT icu_load_collation('pl_PL', 'POLSKI'); to initialization/configuration SQL, while keeping the "password" empty, to avoid encrypting with WxSQLite3, somthing like this:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants