4 * Copyright (c) 2010 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include "ctsvc_internal.h"
23 #include "ctsvc_client_handle.h"
24 #include "ctsvc_client_db_helper.h"
26 API int contacts_db_insert_record(contacts_record_h record, int *id)
29 contacts_h contact = NULL;
31 ret = ctsvc_client_handle_get_p(&contact);
32 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
34 ret = ctsvc_client_db_insert_record(contact, record, id);
39 API int contacts_db_get_record(const char *view_uri, int id, contacts_record_h *out_record)
42 contacts_h contact = NULL;
44 ret = ctsvc_client_handle_get_p(&contact);
45 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
47 ret = ctsvc_client_db_get_record(contact, view_uri, id, out_record);
52 API int contacts_db_update_record(contacts_record_h record)
55 contacts_h contact = NULL;
57 ret = ctsvc_client_handle_get_p(&contact);
58 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
60 ret = ctsvc_client_db_update_record(contact, record);
65 API int contacts_db_delete_record(const char *view_uri, int id)
68 contacts_h contact = NULL;
70 ret = ctsvc_client_handle_get_p(&contact);
71 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
73 ret = ctsvc_client_db_delete_record(contact, view_uri, id);
78 API int contacts_db_replace_record(contacts_record_h record, int id)
81 contacts_h contact = NULL;
83 ret = ctsvc_client_handle_get_p(&contact);
84 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
86 ret = ctsvc_client_db_replace_record(contact, record, id);
92 API int contacts_db_get_all_records(const char *view_uri, int offset, int limit, contacts_list_h *out_list)
95 contacts_h contact = NULL;
97 ret = ctsvc_client_handle_get_p(&contact);
98 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
100 ret = ctsvc_client_db_get_all_records(contact, view_uri, offset, limit, out_list);
105 API int contacts_db_get_records_with_query(contacts_query_h query, int offset, int limit, contacts_list_h *out_list)
108 contacts_h contact = NULL;
110 ret = ctsvc_client_handle_get_p(&contact);
111 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
113 ret = ctsvc_client_db_get_records_with_query(contact, query, offset, limit, out_list);
119 API int contacts_db_get_count(const char *view_uri, int *out_count)
122 contacts_h contact = NULL;
124 ret = ctsvc_client_handle_get_p(&contact);
125 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
127 ret = ctsvc_client_db_get_count(contact, view_uri, out_count);
132 API int contacts_db_get_count_with_query(contacts_query_h query, int *out_count)
135 contacts_h contact = NULL;
137 ret = ctsvc_client_handle_get_p(&contact);
138 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
140 ret = ctsvc_client_db_get_count_with_query(contact, query, out_count);
145 API int contacts_db_insert_records(contacts_list_h list, int **ids, int *count)
148 contacts_h contact = NULL;
150 ret = ctsvc_client_handle_get_p(&contact);
151 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
153 ret = ctsvc_client_db_insert_records(contact, list, ids, count);
158 API int contacts_db_update_records(contacts_list_h list)
161 contacts_h contact = NULL;
163 ret = ctsvc_client_handle_get_p(&contact);
164 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
166 ret = ctsvc_client_db_update_records(contact, list);
171 API int contacts_db_delete_records(const char *view_uri, int ids[], int count)
174 contacts_h contact = NULL;
176 ret = ctsvc_client_handle_get_p(&contact);
177 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
179 ret = ctsvc_client_db_delete_records(contact, view_uri, ids, count);
184 API int contacts_db_replace_records(contacts_list_h list, int ids[], int count)
187 contacts_h contact = NULL;
189 ret = ctsvc_client_handle_get_p(&contact);
190 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
192 ret = ctsvc_client_db_replace_records(contact, list, ids, count);
197 API int contacts_db_get_changes_by_version(const char *view_uri, int addressbook_id,
198 int contacts_db_version, contacts_list_h *record_list, int *current_contacts_db_version)
201 contacts_h contact = NULL;
203 ret = ctsvc_client_handle_get_p(&contact);
204 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
206 ret = ctsvc_client_db_get_changes_by_version(contact, view_uri, addressbook_id, contacts_db_version, record_list, current_contacts_db_version);
211 API int contacts_db_get_current_version(int *contacts_db_version)
214 contacts_h contact = NULL;
216 ret = ctsvc_client_handle_get_p(&contact);
217 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
219 ret = ctsvc_client_db_get_current_version(contact, contacts_db_version);
225 API int contacts_db_search_records(const char *view_uri, const char *keyword,
226 int offset, int limit, contacts_list_h *out_list)
229 contacts_h contact = NULL;
231 ret = ctsvc_client_handle_get_p(&contact);
232 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
234 ret = ctsvc_client_db_search_records(contact, view_uri, keyword, offset, limit, out_list);
239 API int contacts_db_search_records_with_range(const char *view_uri, const char *keyword,
240 int offset, int limit, int range, contacts_list_h *out_list)
243 contacts_h contact = NULL;
245 ret = ctsvc_client_handle_get_p(&contact);
246 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
248 ret = ctsvc_client_db_search_records_with_range(contact, view_uri, keyword, offset, limit, range, out_list);
253 API int contacts_db_search_records_with_query(contacts_query_h query, const char *keyword,
254 int offset, int limit, contacts_list_h *out_list)
257 contacts_h contact = NULL;
259 ret = ctsvc_client_handle_get_p(&contact);
260 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
262 ret = ctsvc_client_db_search_records_with_query(contact, query, keyword, offset, limit, out_list);
267 API int contacts_db_search_records_for_snippet(const char *view_uri,
271 const char *start_match,
272 const char *end_match,
274 contacts_list_h *out_list)
277 contacts_h contact = NULL;
279 ret = ctsvc_client_handle_get_p(&contact);
280 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
282 ret = ctsvc_client_db_search_records_for_snippet(contact, view_uri, keyword,
283 offset, limit, start_match, end_match, token_number, out_list);
288 API int contacts_db_search_records_with_range_for_snippet(const char *view_uri,
293 const char *start_match,
294 const char *end_match,
296 contacts_list_h *out_list)
299 contacts_h contact = NULL;
301 ret = ctsvc_client_handle_get_p(&contact);
302 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
304 ret = ctsvc_client_db_search_records_with_range_for_snippet(contact, view_uri,
305 keyword, offset, limit, range, start_match, end_match, token_number, out_list);
310 API int contacts_db_search_records_with_query_for_snippet(contacts_query_h query,
314 const char *start_match,
315 const char *end_match,
317 contacts_list_h *out_list)
320 contacts_h contact = NULL;
322 ret = ctsvc_client_handle_get_p(&contact);
323 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
325 ret = ctsvc_client_db_search_records_with_query_for_snippet(contact, query, keyword,
326 offset, limit, start_match, end_match, token_number, out_list);
331 API int contacts_db_get_last_change_version(int *last_version)
334 contacts_h contact = NULL;
336 ret = ctsvc_client_handle_get_p(&contact);
337 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
339 ret = ctsvc_client_db_get_last_change_version(contact, last_version);
344 API int contacts_db_get_status(contacts_db_status_e *status)
347 contacts_h contact = NULL;
349 ret = ctsvc_client_handle_get_p(&contact);
350 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
352 ret = ctsvc_client_db_get_status(contact, status);
357 API int contacts_db_add_status_changed_cb(
358 contacts_db_status_changed_cb cb, void *user_data)
361 contacts_h contact = NULL;
363 ret = ctsvc_client_handle_get_p(&contact);
364 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
366 ret = ctsvc_client_db_add_status_changed_cb(contact, cb, user_data);
371 API int contacts_db_remove_status_changed_cb(
372 contacts_db_status_changed_cb cb, void *user_data)
375 contacts_h contact = NULL;
377 ret = ctsvc_client_handle_get_p(&contact);
378 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p() Fail(%d)", ret);
380 ret = ctsvc_client_db_remove_status_changed_cb(contact, cb, user_data);