From 44cd984db9877b2a1aac3321744f7d0415f2f2e9 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 19 Jan 2025 00:37:31 +0100 Subject: Sort cinemas and DKDM recipients correctly using the collator (#2950). --- src/lib/sqlite_database.cc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/lib/sqlite_database.cc') diff --git a/src/lib/sqlite_database.cc b/src/lib/sqlite_database.cc index f0270129b..e1ad15143 100644 --- a/src/lib/sqlite_database.cc +++ b/src/lib/sqlite_database.cc @@ -24,6 +24,20 @@ #include +using std::string; + + +static +int collator_compare(void* context, int length_a, const void* string_a, int length_b, const void* string_b) +{ + auto collator = reinterpret_cast(context); + return collator->compare( + string(reinterpret_cast(string_a), length_a), + string(reinterpret_cast(string_b), length_b) + ); +} + + SQLiteDatabase::SQLiteDatabase(boost::filesystem::path path) { #ifdef DCPOMATIC_WINDOWS @@ -36,6 +50,11 @@ SQLiteDatabase::SQLiteDatabase(boost::filesystem::path path) } sqlite3_busy_timeout(_db, 500); + + rc = sqlite3_create_collation(_db, "unicode", SQLITE_UTF8, &_collator, collator_compare); + if (rc != SQLITE_OK) { + throw std::runtime_error("Could not set SQLite database collation"); + } } -- cgit v1.2.3