ctsvc_db_phone_number_equal_callback, NULL, NULL);
RETVM_IF(SQLITE_OK != ret, CONTACTS_ERROR_DB,
"sqlite3_create_function() Fail(%d)", ret);
+ ret = sqlite3_create_collation(server_db, "_NAME_SORT_", SQLITE_UTF8, (void *)SQLITE_UTF8,
+ ctsvc_db_group_name_sort_callback);
+ RETVM_IF(SQLITE_OK != ret, CONTACTS_ERROR_DB,
+ "sqlite3_create_collation() Fail(%d)", ret);
}
if (db)
*db = server_db;
#include "ctsvc_db_utils.h"
#include "ctsvc_db_plugin_group_helper.h"
#include "ctsvc_notify.h"
+#include "ctsvc_normalize.h"
+#include "ctsvc_server_setting.h"
+#include "ctsvc_localize.h"
/*
* Whenever deleting group, this function will be called
return;
}
+static int _ctsvc_db_group_name_collation_str(const char *str1, const char *str2)
+{
+ int ret;
+ int len1, len2;
+ char *str_dest1 = NULL;
+ char *str_dest2 = NULL;
+
+ ctsvc_collation_str((char *)str1, &str_dest1);
+ ctsvc_collation_str((char *)str2, &str_dest2);
+
+ len1 = strlen(str_dest1);
+ len2 = strlen(str_dest2);
+ if (len1 < len2)
+ ret = strncmp(str_dest1, str_dest2, len1);
+ else
+ ret = strncmp(str_dest1, str_dest2, len2);
+
+ free(str_dest1);
+ free(str_dest2);
+ return ret;
+}
+
+int ctsvc_db_group_name_sort_callback(void *context, int str1_len, const void *str1, int str2_len, const void *str2)
+{
+ int ret;
+ int str1_sort_type;
+ int str2_sort_type;
+ char str_src1[CTSVC_STR_SHORT_LEN] = {0};
+ char str_src2[CTSVC_STR_SHORT_LEN] = {0};
+ int prim_sort = ctsvc_get_primary_sort();
+
+ strncpy(str_src1, str1, str1_len);
+ strncpy(str_src2, str2, str2_len);
+ str1_sort_type = ctsvc_get_name_sort_type(str_src1);
+ str2_sort_type = ctsvc_get_name_sort_type(str_src2);
+
+ switch (str1_sort_type) {
+ case CTSVC_SORT_NUMBER:
+ if (CTSVC_SORT_OTHERS == str2_sort_type)
+ ret = 1;
+ else if (CTSVC_SORT_NUMBER == str2_sort_type)
+ ret = _ctsvc_db_group_name_collation_str(str_src1, str_src2);
+ else
+ ret = -1;
+ break;
+
+ case CTSVC_SORT_OTHERS:
+ if (CTSVC_SORT_OTHERS == str2_sort_type)
+ ret = _ctsvc_db_group_name_collation_str(str_src1, str_src2);
+ else
+ ret = -1;
+ break;
+
+ default:
+ if (CTSVC_SORT_NUMBER >= str2_sort_type) {
+ ret = 1;
+ }
+ else {
+ if (str1_sort_type != str2_sort_type) {
+ if (str1_sort_type == prim_sort)
+ ret = -1;
+ else if (str2_sort_type == prim_sort)
+ ret = 1;
+ else
+ ret = _ctsvc_db_group_name_collation_str(str_src1, str_src2);
+ }
+ else {
+ ret = _ctsvc_db_group_name_collation_str(str_src1, str_src2);
+ }
+ }
+ break;
+ }
+
+ return ret;
+}
temp_len = SAFE_SNPRINTF(&query, &query_size, len, field_name);
if (0 <= temp_len) len+= temp_len;
+ if (CTSVC_PROPERTY_GROUP_NAME == s_query->sort_property_id) {
+ temp_len = SAFE_SNPRINTF(&query, &query_size, len, " COLLATE _NAME_SORT_ ");
+ if (0 <= temp_len) len+= temp_len;
+ }
+
if (false == s_query->sort_asc) {
temp_len = SAFE_SNPRINTF(&query, &query_size, len, " DESC ");
if (0 <= temp_len) len+= temp_len;
ctsvc_db_phone_number_equal_callback, NULL, NULL);
RETVM_IF(SQLITE_OK != ret, CONTACTS_ERROR_DB,
"sqlite3_create_function() Fail(%d)", ret);
+ ret = sqlite3_create_collation(ctsvc_db, "_NAME_SORT_", SQLITE_UTF8, (void *)SQLITE_UTF8,
+ ctsvc_db_group_name_sort_callback);
+ RETVM_IF(SQLITE_OK != ret, CONTACTS_ERROR_DB,
+ "sqlite3_create_collation() Fail(%d)", ret);
}
return CONTACTS_ERROR_NONE /*CTS_SUCCESS*/;