4 * Copyright (c) 2010 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Dohyung Jin <dh.jin@samsung.com>
7 * Jongwon Lee <gogosing.lee@samsung.com>
8 * Donghee Ye <donghee.ye@samsung.com>
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
25 #include "ctsvc_internal.h"
26 #include "ctsvc_client_handle.h"
27 #include "ctsvc_client_db_helper.h"
29 API int contacts_db_insert_record(contacts_record_h record, int *id)
32 contacts_h contact = NULL;
34 ret = ctsvc_client_handle_get_p(&contact);
35 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
37 ret = ctsvc_client_db_insert_record(contact, record, id);
42 API int contacts_db_get_record(const char* view_uri, int id, contacts_record_h* out_record)
45 contacts_h contact = NULL;
47 ret = ctsvc_client_handle_get_p(&contact);
48 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
50 ret = ctsvc_client_db_get_record(contact, view_uri, id, out_record);
55 API int contacts_db_update_record(contacts_record_h record)
58 contacts_h contact = NULL;
60 ret = ctsvc_client_handle_get_p(&contact);
61 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
63 ret = ctsvc_client_db_update_record(contact, record);
68 API int contacts_db_delete_record(const char* view_uri, int id)
71 contacts_h contact = NULL;
73 ret = ctsvc_client_handle_get_p(&contact);
74 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
76 ret = ctsvc_client_db_delete_record(contact, view_uri, id);
81 API int contacts_db_replace_record(contacts_record_h record, int id)
84 contacts_h contact = NULL;
86 ret = ctsvc_client_handle_get_p(&contact);
87 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
89 ret = ctsvc_client_db_replace_record(contact, record, id);
95 API int contacts_db_get_all_records(const char* view_uri, int offset, int limit, contacts_list_h* out_list)
98 contacts_h contact = NULL;
100 ret = ctsvc_client_handle_get_p(&contact);
101 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
103 ret = ctsvc_client_db_get_all_records(contact, view_uri, offset, limit, out_list);
108 API int contacts_db_get_records_with_query(contacts_query_h query, int offset, int limit, contacts_list_h* out_list)
111 contacts_h contact = NULL;
113 ret = ctsvc_client_handle_get_p(&contact);
114 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
116 ret = ctsvc_client_db_get_records_with_query(contact, query, offset, limit, out_list);
122 API int contacts_db_get_count(const char* view_uri, int *out_count)
125 contacts_h contact = NULL;
127 ret = ctsvc_client_handle_get_p(&contact);
128 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
130 ret = ctsvc_client_db_get_count(contact, view_uri, out_count);
135 API int contacts_db_get_count_with_query(contacts_query_h query, int *out_count)
138 contacts_h contact = NULL;
140 ret = ctsvc_client_handle_get_p(&contact);
141 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
143 ret = ctsvc_client_db_get_count_with_query(contact, query, out_count);
148 API int contacts_db_insert_records(contacts_list_h list, int **ids, int *count)
151 contacts_h contact = NULL;
153 ret = ctsvc_client_handle_get_p(&contact);
154 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
156 ret = ctsvc_client_db_insert_records(contact, list, ids, count);
161 API int contacts_db_update_records(contacts_list_h list)
164 contacts_h contact = NULL;
166 ret = ctsvc_client_handle_get_p(&contact);
167 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
169 ret = ctsvc_client_db_update_records(contact, list);
174 API int contacts_db_delete_records(const char* view_uri, int ids[], int count)
177 contacts_h contact = NULL;
179 ret = ctsvc_client_handle_get_p(&contact);
180 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
182 ret = ctsvc_client_db_delete_records(contact, view_uri, ids, count);
187 API int contacts_db_replace_records(contacts_list_h list, int ids[], int count)
190 contacts_h contact = NULL;
192 ret = ctsvc_client_handle_get_p(&contact);
193 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
195 ret = ctsvc_client_db_replace_records(contact, list, ids, count);
200 API int contacts_db_get_changes_by_version(const char* view_uri, int addressbook_id,
201 int contacts_db_version, contacts_list_h* record_list, int* current_contacts_db_version)
204 contacts_h contact = NULL;
206 ret = ctsvc_client_handle_get_p(&contact);
207 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
209 ret = ctsvc_client_db_get_changes_by_version(contact, view_uri, addressbook_id, contacts_db_version, record_list, current_contacts_db_version);
214 API int contacts_db_get_current_version(int* contacts_db_version)
217 contacts_h contact = NULL;
219 ret = ctsvc_client_handle_get_p(&contact);
220 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
222 ret = ctsvc_client_db_get_current_version(contact, contacts_db_version);
228 API int contacts_db_search_records(const char* view_uri, const char *keyword,
229 int offset, int limit, contacts_list_h* out_list)
232 contacts_h contact = NULL;
234 ret = ctsvc_client_handle_get_p(&contact);
235 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
237 ret = ctsvc_client_db_search_records(contact, view_uri, keyword, offset, limit, out_list);
242 API int contacts_db_search_records_with_range(const char* view_uri, const char *keyword,
243 int offset, int limit, int range, contacts_list_h* out_list)
246 contacts_h contact = NULL;
248 ret = ctsvc_client_handle_get_p(&contact);
249 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
251 ret = ctsvc_client_db_search_records_with_range(contact, view_uri, keyword, offset, limit, range, out_list);
256 API int contacts_db_search_records_with_query(contacts_query_h query, const char *keyword,
257 int offset, int limit, contacts_list_h* out_list)
260 contacts_h contact = NULL;
262 ret = ctsvc_client_handle_get_p(&contact);
263 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
265 ret = ctsvc_client_db_search_records_with_query(contact, query, keyword, offset, limit, out_list);
270 API int contacts_db_get_last_change_version(int* last_version)
273 contacts_h contact = NULL;
275 ret = ctsvc_client_handle_get_p(&contact);
276 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
278 ret = ctsvc_client_db_get_last_change_version(contact, last_version);
283 API int contacts_db_get_status(contacts_db_status_e *status)
286 contacts_h contact = NULL;
288 ret = ctsvc_client_handle_get_p(&contact);
289 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
291 ret = ctsvc_client_db_get_status(contact, status);
296 API int contacts_db_add_status_changed_cb(
297 contacts_db_status_changed_cb cb, void* user_data)
300 contacts_h contact = NULL;
302 ret = ctsvc_client_handle_get_p(&contact);
303 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
305 ret = ctsvc_client_db_add_status_changed_cb(contact, cb, user_data);
310 API int contacts_db_remove_status_changed_cb(
311 contacts_db_status_changed_cb cb, void* user_data)
314 contacts_h contact = NULL;
316 ret = ctsvc_client_handle_get_p(&contact);
317 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
319 ret = ctsvc_client_db_remove_status_changed_cb(contact, cb, user_data);