sync with 2.4
[platform/core/pim/contacts-service.git] / native / ctsvc_db_plugin_phonelog.c
1 /*
2  * Contacts Service
3  *
4  * Copyright (c) 2010 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19 #include <stdio.h>
20
21 #include "contacts.h"
22 #include "ctsvc_internal.h"
23 #include "ctsvc_schema.h"
24 #include "ctsvc_sqlite.h"
25 #include "ctsvc_normalize.h"
26 #include "ctsvc_number_utils.h"
27 #include "ctsvc_utils.h"
28 #include "ctsvc_list.h"
29 #include "ctsvc_record.h"
30 #include "ctsvc_db_query.h"
31 #include "ctsvc_db_init.h"
32 #include "ctsvc_notification.h"
33 #include "ctsvc_setting.h"
34 #include "ctsvc_db_access_control.h"
35 #include "ctsvc_localize_utils.h"
36 #include "ctsvc_phonelog.h"
37
38 #ifdef _CONTACTS_IPC_SERVER
39 #include "ctsvc_server_change_subject.h"
40 #ifdef ENABLE_SIM_FEATURE
41 #include "ctsvc_server_sim.h"
42 #endif // ENABLE_SIM_FEATURE
43 #endif
44
45 static int __ctsvc_db_phonelog_insert_record( contacts_record_h record, int *id );
46 static int __ctsvc_db_phonelog_get_record( int id, contacts_record_h* out_record );
47 static int __ctsvc_db_phonelog_update_record( contacts_record_h record );
48 static int __ctsvc_db_phonelog_delete_record( int id );
49 static int __ctsvc_db_phonelog_get_all_records( int offset, int limit, contacts_list_h* out_list );
50 static int __ctsvc_db_phonelog_get_records_with_query( contacts_query_h query, int offset, int limit, contacts_list_h* out_list );
51 //static int __ctsvc_db_phonelog_insert_records(const contacts_list_h in_list, int **ids);
52 //static int __ctsvc_db_phonelog_update_records(const contacts_list_h in_list);
53 //static int __ctsvc_db_phonelog_delete_records( int ids[], int count);
54
55 ctsvc_db_plugin_info_s ctsvc_db_plugin_phonelog = {
56         .is_query_only = false,
57         .insert_record = __ctsvc_db_phonelog_insert_record,
58         .get_record = __ctsvc_db_phonelog_get_record,
59         .update_record = __ctsvc_db_phonelog_update_record,
60         .delete_record = __ctsvc_db_phonelog_delete_record,
61         .get_all_records = __ctsvc_db_phonelog_get_all_records,
62         .get_records_with_query = __ctsvc_db_phonelog_get_records_with_query,
63         .insert_records = NULL,//__ctsvc_db_phonelog_insert_records,
64         .update_records = NULL,//__ctsvc_db_phonelog_update_records,
65         .delete_records = NULL,//__ctsvc_db_phonelog_delete_records
66         .get_count = NULL,
67         .get_count_with_query = NULL,
68         .replace_record = NULL,
69         .replace_records = NULL,
70 };
71
72 static int __ctsvc_db_phonelog_value_set(cts_stmt stmt, contacts_record_h *record)
73 {
74         int i;
75         int ret;
76         char *temp;
77         ctsvc_phonelog_s *phonelog;
78
79         ret = contacts_record_create(_contacts_phone_log._uri, record);
80         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "contacts_record_create is failed(%d)", ret);
81         phonelog = (ctsvc_phonelog_s*)*record;
82
83         i = 0;
84         phonelog->id = ctsvc_stmt_get_int(stmt, i++);
85         temp = ctsvc_stmt_get_text(stmt, i++);
86         phonelog->address = SAFE_STRDUP(temp);
87         phonelog->person_id = ctsvc_stmt_get_int(stmt, i++);
88         phonelog->log_type = ctsvc_stmt_get_int(stmt, i++);
89         phonelog->log_time = ctsvc_stmt_get_int(stmt, i++);
90         phonelog->extra_data1 = ctsvc_stmt_get_int(stmt, i++);
91         temp = ctsvc_stmt_get_text(stmt, i++);
92         phonelog->extra_data2 = SAFE_STRDUP(temp);
93 #ifdef _CONTACTS_IPC_SERVER
94 #ifdef ENABLE_SIM_FEATURE
95         phonelog->sim_slot_no = ctsvc_server_sim_get_sim_slot_no_by_info_id(ctsvc_stmt_get_int(stmt, i++));
96 #endif // ENABLE_SIM_FEATURE
97 #endif
98         return CONTACTS_ERROR_NONE;
99 }
100
101 static int __ctsvc_db_phonelog_get_record( int id, contacts_record_h* out_record )
102 {
103         int ret;
104         cts_stmt stmt = NULL;
105         char query[CTS_SQL_MAX_LEN] = {0};
106         contacts_record_h record;
107
108         RETV_IF(NULL == out_record, CONTACTS_ERROR_INVALID_PARAMETER);
109         *out_record = NULL;
110
111         snprintf(query, sizeof(query),
112                         "SELECT id, number, person_id, log_type, log_time, data1, data2, sim_id "
113                         "FROM "CTS_TABLE_PHONELOGS" WHERE id = %d", id);
114
115         ret = ctsvc_query_prepare(query, &stmt);
116         RETVM_IF(NULL == stmt, ret, "DB error : ctsvc_query_prepare() Failed(%d)", ret);
117
118         ret = ctsvc_stmt_step(stmt);
119         if (1 /*CTS_TRUE*/ != ret) {
120                 CTS_ERR("ctsvc_stmt_step() Failed(%d)", ret);
121                 ctsvc_stmt_finalize(stmt);
122                 if (CONTACTS_ERROR_NONE == ret)
123                         return CONTACTS_ERROR_NO_DATA;
124                 else
125                         return ret;
126         }
127
128         ret = __ctsvc_db_phonelog_value_set(stmt, &record);
129
130         ctsvc_stmt_finalize(stmt);
131         if (CONTACTS_ERROR_NONE != ret) {
132                 CTS_ERR("__ctsvc_db_phonelog_value_set(ALL) Failed(%d)", ret);
133                 return ret;
134         }
135
136         *out_record = record;
137
138         return CONTACTS_ERROR_NONE;
139 }
140
141 static int __ctsvc_db_phonelog_update_record( contacts_record_h record )
142 {
143         int phonelog_id;
144         char query[CTS_SQL_MIN_LEN] = {0};
145         ctsvc_phonelog_s *phonelog = (ctsvc_phonelog_s *)record;
146         int ret = CONTACTS_ERROR_NONE;
147         char* set = NULL;
148         GSList *bind_text = NULL;
149         GSList *cursor = NULL;
150
151         RETVM_IF(NULL == record, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter : record is null");
152         RETVM_IF(phonelog->id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,
153                         "Invalid parameter : The phone_log has ID(%d)", phonelog->id);
154         RETVM_IF(phonelog->log_type != CONTACTS_PLOG_TYPE_VOICE_INCOMMING_SEEN &&
155                         phonelog->log_type != CONTACTS_PLOG_TYPE_VIDEO_INCOMMING_SEEN, CONTACTS_ERROR_INVALID_PARAMETER,
156                         "Invalid parameter : the type is can not updated(%d)", phonelog->log_type);
157         RETVM_IF(CTSVC_PROPERTY_FLAG_DIRTY != (phonelog->base.property_flag & CTSVC_PROPERTY_FLAG_DIRTY), CONTACTS_ERROR_NONE, "No update");
158
159         ret = ctsvc_begin_trans();
160         RETVM_IF(ret, ret, "ctsvc_begin_trans() Failed(%d)", ret);
161
162         snprintf(query, sizeof(query),
163                         "SELECT id FROM "CTS_TABLE_PHONELOGS" WHERE id = %d", phonelog->id);
164         ret = ctsvc_query_get_first_int_result(query, &phonelog_id);
165         if (ret != CONTACTS_ERROR_NONE) {
166                 CTS_ERR("ctsvc_query_get_first_int_result Fail(%d)", ret);
167                 ctsvc_end_trans(false);
168                 return ret;
169         }
170
171         do {
172                 if (CONTACTS_ERROR_NONE != (ret = ctsvc_db_create_set_query(record, &set, &bind_text))) break;
173                 if (CONTACTS_ERROR_NONE != (ret = ctsvc_db_update_record_with_set_query(set, bind_text, CTS_TABLE_PHONELOGS, phonelog->id))) break;
174
175                 if (ctsvc_db_change()) {
176                         ctsvc_set_phonelog_noti();
177
178 #ifdef _CONTACTS_IPC_SERVER
179                         ctsvc_change_subject_add_changed_phone_log_id(CONTACTS_CHANGE_UPDATED, phonelog->id);
180 #endif
181                 }
182         } while (0);
183
184         CTSVC_RECORD_RESET_PROPERTY_FLAGS((ctsvc_record_s *)record);
185         CONTACTS_FREE(set);
186         if (bind_text) {
187                 for (cursor=bind_text;cursor;cursor=cursor->next)
188                         CONTACTS_FREE(cursor->data);
189                 g_slist_free(bind_text);
190         }
191
192         ret = ctsvc_end_trans(true);
193         RETVM_IF(ret < CONTACTS_ERROR_NONE, ret, "DB error : ctsvc_end_trans() Failed(%d)", ret);
194
195         return CONTACTS_ERROR_NONE;
196 }
197
198 static int __ctsvc_db_phonelog_delete_record( int id )
199 {
200         int ret;
201         int phonelog_id;
202         char query[CTS_SQL_MAX_LEN] = {0};
203
204         ret = ctsvc_begin_trans();
205         RETVM_IF(ret, ret, "ctsvc_begin_trans() Failed(%d)", ret);
206
207         snprintf(query, sizeof(query),
208                         "SELECT id FROM "CTS_TABLE_PHONELOGS" WHERE id = %d", id);
209         ret = ctsvc_query_get_first_int_result(query, &phonelog_id);
210         if (ret != CONTACTS_ERROR_NONE) {
211                 CTS_ERR("ctsvc_query_get_first_int_result Fail(%d)", ret);
212                 ctsvc_end_trans(false);
213                 return ret;
214         }
215
216         snprintf(query, sizeof(query), "DELETE FROM %s WHERE id = %d",
217                         CTS_TABLE_PHONELOGS, id);
218
219         ret = ctsvc_query_exec(query);
220         if (CONTACTS_ERROR_NONE != ret) {
221                 CTS_ERR("ctsvc_query_exec() Failed(%d)", ret);
222                 ctsvc_end_trans(false);
223                 return ret;
224         }
225
226         ctsvc_set_phonelog_noti();
227
228         ret = ctsvc_end_trans(true);
229         if (ret < CONTACTS_ERROR_NONE)
230         {
231                 CTS_ERR("DB error : ctsvc_end_trans() Failed(%d)", ret);
232                 return ret;
233         }
234         else
235                 return CONTACTS_ERROR_NONE;
236 }
237
238 static int __ctsvc_db_phonelog_get_all_records( int offset, int limit,
239                 contacts_list_h* out_list )
240 {
241         int ret;
242         int len;
243         cts_stmt stmt;
244         char query[CTS_SQL_MAX_LEN] = {0};
245         contacts_list_h list;
246
247         len = snprintf(query, sizeof(query),
248                         "SELECT id, number, person_id, log_type, log_time, data1, data2, sim_id "
249                                         "FROM "CTS_TABLE_PHONELOGS);
250
251         if (0 != limit) {
252                 len += snprintf(query+len, sizeof(query)-len, " LIMIT %d", limit);
253                 if (0 < offset)
254                         len += snprintf(query+len, sizeof(query)-len, " OFFSET %d", offset);
255         }
256
257         ret = ctsvc_query_prepare(query, &stmt);
258         RETVM_IF(NULL == stmt, ret, "DB error : ctsvc_query_prepare() Failed(%d)", ret);
259
260         contacts_list_create(&list);
261         while ((ret = ctsvc_stmt_step(stmt))) {
262                 contacts_record_h record;
263                 if (1 != ret) {
264                         CTS_ERR("DB error : ctsvc_stmt_step() Failed(%d)", ret);
265                         ctsvc_stmt_finalize(stmt);
266                         contacts_list_destroy(list, true);
267                         return ret;
268                 }
269                 __ctsvc_db_phonelog_value_set(stmt, &record);
270
271                 ctsvc_list_prepend(list, record);
272         }
273         ctsvc_stmt_finalize(stmt);
274         ctsvc_list_reverse(list);
275
276         *out_list = (contacts_list_h)list;
277         return CONTACTS_ERROR_NONE;
278 }
279
280 static int __ctsvc_db_phonelog_get_records_with_query( contacts_query_h query, int offset,
281                 int limit, contacts_list_h* out_list )
282 {
283         int ret;
284         int i;
285         int field_count;
286         ctsvc_query_s *s_query;
287         cts_stmt stmt;
288         contacts_list_h list;
289         ctsvc_phonelog_s *phonelog;
290
291         RETV_IF(NULL == query, CONTACTS_ERROR_INVALID_PARAMETER);
292         s_query = (ctsvc_query_s *)query;
293
294         ret = ctsvc_db_make_get_records_query_stmt(s_query, offset, limit, &stmt);
295         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_db_make_get_records_query_stmt fail(%d)", ret);
296
297         contacts_list_create(&list);
298         while ((ret = ctsvc_stmt_step(stmt))) {
299                 contacts_record_h record;
300                 if (1 != ret) {
301                         CTS_ERR("DB error : ctsvc_stmt_step() Failed(%d)", ret);
302                         ctsvc_stmt_finalize(stmt);
303                         contacts_list_destroy(list, true);
304                         return ret;
305                 }
306
307                 contacts_record_create(_contacts_phone_log._uri, &record);
308                 phonelog = (ctsvc_phonelog_s*)record;
309                 if (0 == s_query->projection_count)
310                         field_count = s_query->property_count;
311                 else
312                 {
313                         field_count = s_query->projection_count;
314
315                         if( CONTACTS_ERROR_NONE != ctsvc_record_set_projection_flags(record, s_query->projection, s_query->projection_count, s_query->property_count) )
316                         {
317                                 ASSERT_NOT_REACHED("To set projection is failed.\n");
318                         }
319                 }
320
321                 for(i=0;i<field_count;i++) {
322                         char *temp;
323                         int property_id;
324                         if (0 == s_query->projection_count)
325                                 property_id = s_query->properties[i].property_id;
326                         else
327                                 property_id = s_query->projection[i];
328
329                         switch(property_id) {
330                         case CTSVC_PROPERTY_PHONELOG_ID:
331                                 phonelog->id = ctsvc_stmt_get_int(stmt, i);
332                                 break;
333                         case CTSVC_PROPERTY_PHONELOG_PERSON_ID:
334                                 phonelog->person_id = ctsvc_stmt_get_int(stmt, i);
335                                 break;
336                         case CTSVC_PROPERTY_PHONELOG_ADDRESS:
337                                 temp = ctsvc_stmt_get_text(stmt, i);
338                                 phonelog->address = SAFE_STRDUP(temp);
339                                 break;
340                         case CTSVC_PROPERTY_PHONELOG_LOG_TIME:
341                                 phonelog->log_time = ctsvc_stmt_get_int(stmt, i);
342                                 break;
343                         case CTSVC_PROPERTY_PHONELOG_LOG_TYPE:
344                                 phonelog->log_type = ctsvc_stmt_get_int(stmt, i);
345                                 break;
346                         case CTSVC_PROPERTY_PHONELOG_EXTRA_DATA1:
347                                 phonelog->extra_data1 = ctsvc_stmt_get_int(stmt, i);
348                                 break;
349                         case CTSVC_PROPERTY_PHONELOG_EXTRA_DATA2:
350                                 temp = ctsvc_stmt_get_text(stmt, i);
351                                 phonelog->extra_data2 = SAFE_STRDUP(temp);
352                                 break;
353 #ifdef ENABLE_SIM_FEATURE
354                         case CTSVC_PROPERTY_PHONELOG_SIM_SLOT_NO:
355                                 phonelog->sim_slot_no = ctsvc_server_sim_get_sim_slot_no_by_info_id(ctsvc_stmt_get_int(stmt, i));
356                                 break;
357 #endif // ENABLE_SIM_FEATURE
358                         default:
359                                 break;
360                         }
361                 }
362                 ctsvc_list_prepend(list, record);
363         }
364
365         ctsvc_stmt_finalize(stmt);
366         ctsvc_list_reverse(list);
367
368         *out_list = list;
369
370         return CONTACTS_ERROR_NONE;
371 }
372 //static int __ctsvc_db_phonelog_insert_records(const contacts_list_h in_list, int **ids) { return CONTACTS_ERROR_NONE; }
373 //static int __ctsvc_db_phonelog_update_records(const contacts_list_h in_list) { return CONTACTS_ERROR_NONE; }
374 //static int __ctsvc_db_phonelog_delete_records( int ids[], int count) { return CONTACTS_ERROR_NONE; }
375
376 static int __ctsvc_db_phonelog_increase_outgoing_count(ctsvc_phonelog_s *phonelog)
377 {
378         int ret;
379         int id;
380         int type = CONTACTS_USAGE_STAT_TYPE_NONE;
381         char query[CTS_SQL_MIN_LEN] = {0};
382
383         if (phonelog->log_type == CONTACTS_PLOG_TYPE_VOICE_OUTGOING ||
384                 phonelog->log_type == CONTACTS_PLOG_TYPE_VIDEO_OUTGOING)
385                 type = CONTACTS_USAGE_STAT_TYPE_OUTGOING_CALL;
386         else if (phonelog->log_type == CONTACTS_PLOG_TYPE_MMS_OUTGOING ||
387                 phonelog->log_type == CONTACTS_PLOG_TYPE_SMS_OUTGOING)
388                 type = CONTACTS_USAGE_STAT_TYPE_OUTGOING_MSG;
389         else
390                 return CONTACTS_ERROR_NONE;
391
392         snprintf(query, sizeof(query),
393                         "SELECT person_id FROM %s WHERE person_id = %d and usage_type = %d ",
394                         CTS_TABLE_CONTACT_STAT, phonelog->person_id, type);
395
396         ret = ctsvc_query_get_first_int_result(query, &id);
397         if (CONTACTS_ERROR_NO_DATA == ret) {
398                 snprintf(query, sizeof(query),
399                                 "INSERT INTO %s(person_id, usage_type, times_used) VALUES(%d, %d, 1)",
400                                 CTS_TABLE_CONTACT_STAT, phonelog->person_id, type);
401         }
402         else {
403                 snprintf(query, sizeof(query),
404                                 "UPDATE %s SET times_used = times_used + 1 WHERE person_id = %d and usage_type = %d",
405                                 CTS_TABLE_CONTACT_STAT, phonelog->person_id, type);
406         }
407
408         ret = ctsvc_query_exec(query);
409         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "DB error : ctsvc_query_exec() Failed(%d)", ret);
410
411         return CONTACTS_ERROR_NONE;
412 }
413
414 static int  __ctsvc_db_phonelog_insert(ctsvc_phonelog_s *phonelog, int *id)
415 {
416         int ret;
417         cts_stmt stmt = NULL;
418         char query[CTS_SQL_MAX_LEN] = {0};
419
420         RETVM_IF((phonelog->log_type < CONTACTS_PLOG_TYPE_NONE
421                         || CONTACTS_PLOG_TYPE_EMAIL_SENT < phonelog->log_type)
422                         , CONTACTS_ERROR_INVALID_PARAMETER, "phonelog type(%d) is invaid", phonelog->log_type);
423
424         snprintf(query, sizeof(query), "INSERT INTO "CTS_TABLE_PHONELOGS"("
425                         "number, normal_num, minmatch, clean_num, person_id, log_type,log_time, data1, data2, sim_id) "
426                         "VALUES(?, ?, ?, ?, ?, %d, %d, %d, ?, ?)",
427                         phonelog->log_type, phonelog->log_time, phonelog->extra_data1);
428
429         ret = ctsvc_query_prepare(query, &stmt);
430         RETVM_IF(NULL == stmt, ret, "DB error : ctsvc_query_prepare() Failed(%d)", ret);
431
432         if (phonelog->address) {
433                 ctsvc_stmt_bind_text(stmt, 1, phonelog->address);
434                 if (phonelog->log_type < CONTACTS_PLOG_TYPE_EMAIL_RECEIVED) {
435                         char clean_num[strlen(phonelog->address) + 1];
436                         ret = ctsvc_clean_number(phonelog->address, clean_num, sizeof(clean_num), true);
437                         if (0 < ret) {
438                                 char normal_num[sizeof(clean_num) + 20];
439                                 ctsvc_stmt_bind_copy_text(stmt, 4, clean_num, strlen(clean_num));
440                                 ret = ctsvc_normalize_number(clean_num, normal_num, sizeof(normal_num), true);
441                                 if (0 < ret) {
442                                         char minmatch[sizeof(normal_num) + 1];
443                                         ctsvc_stmt_bind_copy_text(stmt, 2, normal_num, strlen(normal_num));
444                                         ret = ctsvc_get_minmatch_number(normal_num, minmatch, sizeof(minmatch), ctsvc_get_phonenumber_min_match_digit());
445                                         ctsvc_stmt_bind_copy_text(stmt, 3, minmatch, strlen(minmatch));
446                                 }
447                         }
448                 }
449         }
450
451         if (0 < phonelog->person_id)
452                 ctsvc_stmt_bind_int(stmt, 5, phonelog->person_id);
453
454         if (phonelog->extra_data2)
455                 ctsvc_stmt_bind_text(stmt, 6, phonelog->extra_data2);
456
457 #ifdef ENABLE_SIM_FEATURE
458         if (phonelog->sim_slot_no >= 0) {
459                 int sim_info_id;
460                 sim_info_id = ctsvc_server_sim_get_info_id_by_sim_slot_no(phonelog->sim_slot_no);
461                 if (sim_info_id > 0)
462                         ctsvc_stmt_bind_int(stmt, 7, sim_info_id);
463         }
464         else
465 #endif // ENABLE_SIM_FEATURE
466                 ctsvc_stmt_bind_int(stmt, 7, -1);
467
468         ret = ctsvc_stmt_step(stmt);
469         if (CONTACTS_ERROR_NONE != ret) {
470                 CTS_ERR("ctsvc_stmt_step() Failed(%d)", ret);
471                 ctsvc_stmt_finalize(stmt);
472                 return ret;
473         }
474         if (id)
475                 *id = ctsvc_db_get_last_insert_id();
476         ctsvc_stmt_finalize(stmt);
477
478         // update phonelog
479         ctsvc_db_phone_log_update_person_id(phonelog->address, phonelog->person_id, -1, false);
480
481         ctsvc_set_phonelog_noti();
482         return CONTACTS_ERROR_NONE;
483 }
484
485 static int __ctsvc_db_phonelog_insert_record( contacts_record_h record, int *id )
486 {
487         int ret;
488         ctsvc_phonelog_s *phonelog = (ctsvc_phonelog_s *)record;
489
490         RETVM_IF(NULL == record, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter : record is null");
491         RETVM_IF(phonelog->id, CONTACTS_ERROR_INVALID_PARAMETER,
492                         "Invalid parameter : The phone_log has ID(%d)", phonelog->id);
493
494         ret = ctsvc_begin_trans();
495         RETVM_IF(ret, ret, "ctsvc_begin_trans() Failed(%d)", ret);
496
497         ret = __ctsvc_db_phonelog_insert(phonelog, id);
498         if (CONTACTS_ERROR_NONE != ret) {
499                 CTS_ERR("__ctsvc_db_phonelog_insert() Failed(%d)", ret);
500                 ctsvc_end_trans(false);
501                 return ret;
502         }
503
504         if (0 < phonelog->person_id) {
505                 ret = __ctsvc_db_phonelog_increase_outgoing_count(phonelog);
506                 WARN_IF(CONTACTS_ERROR_NONE != ret, "__ctsvc_db_phonelog_increase_outgoing_count() Failed(%d)", ret);
507         }
508
509 #ifdef _CONTACTS_IPC_SERVER
510         // add id for subscribe
511         ctsvc_change_subject_add_changed_phone_log_id(CONTACTS_CHANGE_INSERTED, *id);
512 #endif
513
514         ret = ctsvc_end_trans(true);
515         if (ret < CONTACTS_ERROR_NONE) {
516                 CTS_ERR("DB error : ctsvc_end_trans() Failed(%d)", ret);
517                 return ret;
518         }
519         return CONTACTS_ERROR_NONE;
520 }
521