Add natural collate 87/321087/1 accepted/tizen/unified/20250317.142115 accepted/tizen/unified/20250317.143617 accepted/tizen/unified/x/20250318.035655
authorMinje Ahn <minje.ahn@samsung.com>
Thu, 13 Mar 2025 22:48:24 +0000 (07:48 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Thu, 13 Mar 2025 22:48:24 +0000 (07:48 +0900)
A natural collate type was added under the name 'MIXED'.
Since 'NATURAL' is a reserved word, we will use 'MIXED'.

Change-Id: I5da7b073eaf49e105fd74b552aa3d2cd6061cd50
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
lib/media-util-db.c
packaging/media-server.spec

index a1b6a7b080573a90dad0097d8dbf0c6db009d0e7..1790ef721a99aec466f0269ed031ba7c50ba6006 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <unistd.h>
 #include <dlfcn.h>
+#include <glib.h>
 
 #include <unicode/utypes.h>
 #include <unicode/ucol.h>
@@ -62,9 +63,17 @@ static int __media_db_collate_icu_8(void *ucol, int str1_len, const void *str1,
        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;
@@ -113,8 +122,12 @@ static void __media_db_collation_cb(void* pArg, sqlite3* handle, int charset, co
                } 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");
        }
 }
 
index 5eac75ce9bc69d11ab77785a6d018ca1eebdd3f5..1b134ed89fce3b9293f01ccdf658a46ba6d87c9a 100644 (file)
@@ -1,7 +1,7 @@
 Name:       media-server
 Summary:    A server for media content management
-Version:    0.6.15
-Release:    1
+Version:    0.6.16
+Release:    0
 Group:      Multimedia/Service
 License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz