2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @file query-utility.h
19 * @author JihwaPark (82-32-3016262, jh7979.park@samsung.com)
20 * @version 1.0(2010.10.05)
21 * @brief This file is internal header file for own module
24 #ifndef __QUERY_UTILITY_H__
25 #define __QUERY_UTILITY_H__
27 #include "query-service.h"
31 #endif /* __cplusplus */
35 #define QUERY_DB_PATH "/opt/dbspace/.contacts-svc.db"
59 FIELD_PERSON_CONTACT_ID,
61 FIELD_CONTACT_ID_FOR_NAME,
62 FIELD_CONTACT_ID_FOR_PHOTO,
63 FIELD_CONTACT_ID_FOR_RINGTONE,
64 FIELD_PERSON_PREFIX_NAME,
65 FIELD_PERSON_FIRST_NAME,
66 FIELD_PERSON_MIDDLE_NAME,
67 FIELD_PERSON_LAST_NAME,
68 FIELD_PERSON_PHONETIC_NAME,
69 FIELD_PERSON_DISPLAY_NAME = 10,
70 FIELD_PERSON_PHOTO_URI,
71 FIELD_PERSON_LAST_UPDATED_TIME,
72 FIELD_PERSON_IS_FAVORITE,
73 FIELD_PERSON_SEND_TO_VOICEMAIL,
74 FIELD_PERSON_RINGTONE,
76 FIELD_CONTACT_PERSON_ID,
77 FIELD_CONTACT_CONTACT_ID,
78 FIELD_CONTACT_ACCOUNT_ID,
87 FIELD_DATA_CONTACT_ID,
88 FIELD_DATA_DATATYPE_ID,
100 FIELD_PRESENCE_CONTACT_ID,
101 FIELD_PRESENCE_STATE,
102 FIELD_PRESENCE_MESSAGE,
103 FIELD_PRESENCE_ICON_URI,
104 FIELD_PRESENCE_CAPABILITY,
108 static char* field_key[FIELD_MAX] =
110 "person.person_id", //0
112 "person.contact_id_for_name",
113 "person.contact_id_for_photo",
114 "person.contactid_for_ringtone",
117 "person.middle_name",
119 "person.phonetic_name",
120 "person.display_name", //10
122 "person.last_updated_timestamp",
123 "person.is_favorite",
124 "person.send_to_voicemail",
126 "contacts.person_id",
127 "contacts.contact_id",
128 "contacts.addrbook_id",
129 "contacts.changed_time",
130 "contacts.is_favorite",
149 "presence.contact_id",
153 "presence.capability"
156 static char* condition_field_key[FIELD_MAX] =
160 "contact_id_for_name",
161 "contact_id_for_photo",
162 "contactid_for_ringtone",
170 "last_updated_timestamp",
206 FIELD_GROUP_INVALID = -1,
209 FIELD_GROUP_RINGTONE,
213 static char* group_field_key[FIELD_GROUP_MAX] =
222 FIELD_GROUP_RELATION_INVALID = -1,
223 FIELD_GROUP_RELATION_GROUP_ID,
224 FIELD_GROUP_RELATION_CONTACT_ID,
225 FIELD_GROUP_RELATION_MAX,
228 static char* relation_field_key[FIELD_GROUP_RELATION_MAX] =
236 FIELD_X_INVALID = -1,
250 static char* x_field_key[FIELD_X_MAX] =
264 static char* condition_x_field_key[FIELD_X_MAX] =
278 static char* alias_key[27] =
309 static char* condition_key[CONDITION_MAX] =
322 static char* table_key[TABLE_MAX] =
332 static char* condition_type_key[CONDITION_TYPE_MAX] =
340 clock_t _get_clock();
342 void _print_time(clock_t begin, clock_t finish, const char* function_name);
344 query_error _contact_db_init();
346 query_error _contact_db_finish();
348 query_error _trans_begin(void);
350 query_error _trans_end(int is_success);
352 query_error _contact_exec_query(char* query);
354 int _contact_query_step(stmt pStmt);
356 void _ct_query_finalize(stmt pStmt);
358 int _ct_query_column_int(stmt pStmt, int pos);
360 char* _ct_query_column_text(stmt pStmt, int pos);
362 int _contact_query_bind_int(stmt pStmt, int pos, int num);
364 int _contact_query_bind_double(stmt pStmt, int pos, double num);
366 int _contact_query_bind_text(stmt pStmt, int pos, char* str);
368 void _contact_query_stmt_reset(stmt stmt);
370 double _contact_query_column_double(stmt pStmt, int pos);
372 stmt _contact_query_prepare(char *query);
374 int _convert_person_attribute_to_mimetype_id(contact_attribute_e attribute);
376 predefine_datatype _convert_attribute_to_mimetype_id(contact_attribute_e attribute);
378 char* _convert_person_attribute_to_column_name(contact_attribute_e attribute);
380 char* _convert_person_attribute_to_condition_column_name(contact_attribute_e attribute);
382 char* _convert_attribute_to_condition_normalize_column(contact_attribute_e attribute);
384 char* _convert_attribute_to_normalize_column(contact_attribute_e attribute);
386 char* _convert_attribute_to_condition_column_name(contact_attribute_e attribute);
388 primitive_type _convert_check_attribute_primitive_type(contact_attribute_e attribute);
390 char* _convert_x_attribute_to_condition_column_name(contact_x_attribute_e attribute);
392 char* _convert_attribute_to_column_name(contact_attribute_e attribute);
394 char* _convert_x_attribute_to_column_name(contact_x_attribute_e attribute);
396 tables_e _contact_table_name_to_table_type(char* table_name);
398 char* _convert_person_attribute_to_table_name(contact_attribute_e attribute);
400 char* _convert_attribute_to_table_name(contact_attribute_e attribute);
402 char* _convert_x_attribute_to_table_name(contact_x_attribute_e attribute);
404 char* _convert_condition_type_to_string(condition_type_e type);
406 void _query_get_count(const char* table_name, query_type_e query_type, int* count);
408 void __free_datatype_list(gpointer data, gpointer user_data);
410 void _free_handle_info(advanced_handle_t* handle);
412 int _free_for_limit_iter(advanced_handle_t* handle);
414 void _free_name_info(name_t* name_info);
416 void _free_num_info(number_t* num_info);
418 void _free_email_info(email_t* email_info);
420 void _free_url_info(url_t* url_info);
422 void _free_nick_info(nick_name_t* nick_info);
424 void _free_anniversary_info(event_info_t* event_info);
426 void _free_organization_info(organization_t* organization_info);
428 void _free_address_info(address_t* address_info);
430 void _free_x_info(x_info_t* x_info);
432 void _free_projection_list(gpointer data, gpointer user_data);
434 db_datatype _convert_datatype_to_db_type(predefine_datatype datatype);
436 query_error _set_datatype_list(advanced_handle_t* q_handle, contact_attribute_e attribute);
438 query_error _set_datatype_list_by_x_attribute(advanced_handle_t* q_handle, int datatype_id, contact_x_attribute_e attribute);
440 char* _convert_condition_to_string(condition_e condition);
442 query_error _normalize_str(const char* src, char* dest, int dest_size);
444 query_error _remove_invalid_chars(char *src, char* desc);
446 int _convert_type_string_to_int(contact_attribute_e attribute, const char* value);
448 int _is_type_bitwise_int(contact_attribute_e attribute);
452 #endif /* __cplusplus */
454 #endif // __QUERY_UTILITY_H__