From 7416c30c9c2963b495f9d0be43410706637cf52e Mon Sep 17 00:00:00 2001 From: Gukhwan Cho Date: Wed, 9 Sep 2015 17:29:23 +0900 Subject: [PATCH] change query to find condition of person name Change-Id: I26e510c9b2ffd82a6f551d31dcf948a2208a5978 Signed-off-by: Gukhwan Cho --- server/db/ctsvc_db_query.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/server/db/ctsvc_db_query.c b/server/db/ctsvc_db_query.c index 18dba19..60add16 100644 --- a/server/db/ctsvc_db_query.c +++ b/server/db/ctsvc_db_query.c @@ -2185,6 +2185,7 @@ static inline int __ctsvc_db_search_records_with_query_exec(ctsvc_query_s *s_que int ret; int i; int type; + bool person_contact_query = false; GSList *cursor; cts_stmt stmt = NULL; contacts_list_h list = NULL; @@ -2222,12 +2223,15 @@ static inline int __ctsvc_db_search_records_with_query_exec(ctsvc_query_s *s_que || STRING_EQUAL == strcmp(s_query->view_uri, CTSVC_VIEW_URI_READ_ONLY_PERSON_GROUP_NOT_ASSIGNED)) { temp_len = SAFE_SNPRINTF(&query, &query_size, len, table); if (0 <= temp_len) len+= temp_len; - temp_len = SAFE_SNPRINTF(&query, &query_size, len, " WHERE "); + temp_len = SAFE_SNPRINTF(&query, &query_size, len, " WHERE person_id IN "); if (0 <= temp_len) len+= temp_len; - temp_len = SAFE_SNPRINTF(&query, &query_size, len, table); + temp_len = SAFE_SNPRINTF(&query, &query_size, len, " ( SELECT person_id FROM "); if (0 <= temp_len) len+= temp_len; - temp_len = SAFE_SNPRINTF(&query, &query_size, len, ".contact_id IN "); + temp_len = SAFE_SNPRINTF(&query, &query_size, len, CTS_TABLE_CONTACTS); if (0 <= temp_len) len+= temp_len; + temp_len = SAFE_SNPRINTF(&query, &query_size, len, " WHERE deleted = 0 AND contact_id IN "); + if (0 <= temp_len) len+= temp_len; + person_contact_query = true; } else if (STRING_EQUAL == strcmp(s_query->view_uri, CTSVC_VIEW_URI_READ_ONLY_PERSON_NUMBER) || STRING_EQUAL == strcmp(s_query->view_uri, CTSVC_VIEW_URI_READ_ONLY_PERSON_EMAIL)) { @@ -2253,9 +2257,26 @@ static inline int __ctsvc_db_search_records_with_query_exec(ctsvc_query_s *s_que temp_len = __ctsvc_db_append_search_query(keyword, &query, &query_size, len, range); if (0 <= temp_len) len = temp_len; - if (condition && *condition) { - temp_len = SAFE_SNPRINTF(&query, &query_size, len, " AND ("); + if (person_contact_query) { + temp_len = SAFE_SNPRINTF(&query, &query_size, len, " ) "); if (0 <= temp_len) len+= temp_len; + } + + if (condition && *condition) { + if (person_contact_query) { + temp_len = SAFE_SNPRINTF(&query, &query_size, len, " AND contact_id IN ("); + if (0 <= temp_len) len+= temp_len; + temp_len = SAFE_SNPRINTF(&query, &query_size, len, " SELECT contact_id FROM "); + if (0 <= temp_len) len+= temp_len; + temp_len = SAFE_SNPRINTF(&query, &query_size, len, table); + if (0 <= temp_len) len+= temp_len; + temp_len = SAFE_SNPRINTF(&query, &query_size, len, " WHERE "); + if (0 <= temp_len) len+= temp_len; + } + else { + temp_len = SAFE_SNPRINTF(&query, &query_size, len, " AND ("); + if (0 <= temp_len) len+= temp_len; + } temp_len = SAFE_SNPRINTF(&query, &query_size, len, condition); if (0 <= temp_len) len+= temp_len; temp_len = SAFE_SNPRINTF(&query, &query_size, len, ")"); -- 2.7.4