#include <unistd.h>
#include <dlfcn.h>
+#include <glib.h>
#include <unicode/utypes.h>
#include <unicode/ucol.h>
return result;
}
-static void __media_db_collation_cb(void* pArg, sqlite3* handle, int charset, const char* name)
+static int __media_db_collate_natural(void *pArg, int str1_len, const void *str1, int str2_len, const void *str2)
{
- int ret = MS_MEDIA_ERR_NONE;
+ g_autofree gchar *str1_key = g_utf8_collate_key_for_filename(str1, str1_len);
+ g_autofree gchar *str2_key = g_utf8_collate_key_for_filename(str2, str2_len);
+
+ return g_strcmp0(str1_key, str2_key);
+}
+
+static void __media_db_collation_cb(void *pArg, sqlite3 *handle, int charset, const char *name)
+{
+ int ret = SQLITE_OK;
UErrorCode status = U_ZERO_ERROR;
const char* locale = NULL;
char *lang = NULL;
} else {
MSAPI_DBG("sqlite3_create_collation_v2 success");
}
- } else {
- MSAPI_DBG_ERR("No matching collator for %s", name);
+ } else if (charset == SQLITE_UTF8 && !sqlite3_stricmp(name, "MIXED")) {
+ ret = sqlite3_create_collation_v2(handle, name, SQLITE_UTF8, NULL, __media_db_collate_natural, NULL);
+ if (ret != SQLITE_OK)
+ MSAPI_DBG_ERR("sqlite3_create_collation_v2 fail : %d", ret);
+ else
+ MSAPI_DBG("sqlite3_create_collation_v2 success");
}
}