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,
86 FIELD_DATA_CONTACT_ID,
87 FIELD_DATA_DATATYPE_ID,
99 FIELD_PRESENCE_CONTACT_ID,
100 FIELD_PRESENCE_STATE,
101 FIELD_PRESENCE_MESSAGE,
102 FIELD_PRESENCE_ICON_URI,
103 FIELD_PRESENCE_CAPABILITY,
107 static char* field_key[FIELD_MAX] =
109 "person.person_id", //0
111 "person.contact_id_for_name",
112 "person.contact_id_for_photo",
113 "person.contactid_for_ringtone",
116 "person.middle_name",
118 "person.phonetic_name",
119 "person.display_name", //10
121 "person.last_updated_timestamp",
122 "person.is_favorite",
123 "person.send_to_voicemail",
125 "contacts.person_id",
126 "contacts.contact_id",
127 "contacts.addrbook_id",
128 "contacts.changed_time",
129 "contacts.is_favorite",
130 "contacts.image_thumbnail_path",
131 "contacts.ringtone_path",
147 "presence.contact_id",
151 "presence.capability"
154 static char* condition_field_key[FIELD_MAX] =
158 "contact_id_for_name",
159 "contact_id_for_photo",
160 "contactid_for_ringtone",
168 "last_updated_timestamp",
177 "image_thumbnail_path",
203 FIELD_GROUP_INVALID = -1,
206 FIELD_GROUP_RINGTONE,
210 static char* group_field_key[FIELD_GROUP_MAX] =
219 FIELD_GROUP_RELATION_INVALID = -1,
220 FIELD_GROUP_RELATION_GROUP_ID,
221 FIELD_GROUP_RELATION_CONTACT_ID,
222 FIELD_GROUP_RELATION_MAX,
225 static char* relation_field_key[FIELD_GROUP_RELATION_MAX] =
233 FIELD_X_INVALID = -1,
247 static char* x_field_key[FIELD_X_MAX] =
261 static char* condition_x_field_key[FIELD_X_MAX] =
275 static char* alias_key[27] =
306 static char* condition_key[CONDITION_MAX] =
319 static char* table_key[TABLE_MAX] =
329 static char* condition_type_key[CONDITION_TYPE_MAX] =
337 clock_t _get_clock();
339 void _print_time(clock_t begin, clock_t finish, const char* function_name);
341 query_error _contact_db_init();
343 query_error _contact_db_finish();
345 query_error _trans_begin(void);
347 query_error _trans_end(int is_success);
349 query_error _contact_exec_query(char* query);
351 int _contact_query_step(stmt pStmt);
353 void _ct_query_finalize(stmt pStmt);
355 int _ct_query_column_int(stmt pStmt, int pos);
357 char* _ct_query_column_text(stmt pStmt, int pos);
359 int _contact_query_bind_int(stmt pStmt, int pos, int num);
361 int _contact_query_bind_double(stmt pStmt, int pos, double num);
363 int _contact_query_bind_text(stmt pStmt, int pos, char* str);
365 void _contact_query_stmt_reset(stmt stmt);
367 double _contact_query_column_double(stmt pStmt, int pos);
369 stmt _contact_query_prepare(char *query);
371 int _convert_person_attribute_to_mimetype_id(contact_attribute_e attribute);
373 predefine_datatype _convert_attribute_to_mimetype_id(contact_attribute_e attribute);
375 char* _convert_person_attribute_to_column_name(contact_attribute_e attribute);
377 char* _convert_person_attribute_to_condition_column_name(contact_attribute_e attribute);
379 char* _convert_attribute_to_condition_normalize_column(contact_attribute_e attribute);
381 char* _convert_attribute_to_normalize_column(contact_attribute_e attribute);
383 char* _convert_attribute_to_condition_column_name(contact_attribute_e attribute);
385 primitive_type _convert_check_attribute_primitive_type(contact_attribute_e attribute);
387 char* _convert_x_attribute_to_condition_column_name(contact_x_attribute_e attribute);
389 char* _convert_attribute_to_column_name(contact_attribute_e attribute);
391 char* _convert_x_attribute_to_column_name(contact_x_attribute_e attribute);
393 tables_e _contact_table_name_to_table_type(char* table_name);
395 char* _convert_person_attribute_to_table_name(contact_attribute_e attribute);
397 char* _convert_attribute_to_table_name(contact_attribute_e attribute);
399 char* _convert_x_attribute_to_table_name(contact_x_attribute_e attribute);
401 char* _convert_condition_type_to_string(condition_type_e type);
403 void _query_get_count(const char* table_name, query_type_e query_type, int* count);
405 void __free_datatype_list(gpointer data, gpointer user_data);
407 void _free_handle_info(advanced_handle_t* handle);
409 int _free_for_limit_iter(advanced_handle_t* handle);
411 void _free_name_info(name_t* name_info);
413 void _free_num_info(number_t* num_info);
415 void _free_email_info(email_t* email_info);
417 void _free_url_info(url_t* url_info);
419 void _free_nick_info(nick_name_t* nick_info);
421 void _free_anniversary_info(event_info_t* event_info);
423 void _free_organization_info(organization_t* organization_info);
425 void _free_address_info(address_t* address_info);
427 void _free_x_info(x_info_t* x_info);
429 void _free_projection_list(gpointer data, gpointer user_data);
431 db_datatype _convert_datatype_to_db_type(predefine_datatype datatype);
433 query_error _set_datatype_list(advanced_handle_t* q_handle, contact_attribute_e attribute);
435 query_error _set_datatype_list_by_x_attribute(advanced_handle_t* q_handle, int datatype_id, contact_x_attribute_e attribute);
437 char* _convert_condition_to_string(condition_e condition);
439 query_error _normalize_str(const char* src, char* dest, int dest_size);
441 query_error _remove_invalid_chars(char *src, char* desc);
443 int _convert_type_string_to_int(contact_attribute_e attribute, const char* value);
445 int _is_type_bitwise_int(contact_attribute_e attribute);
449 #endif /* __cplusplus */
451 #endif // __QUERY_UTILITY_H__