2 * Copyright (c) 2014 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.
17 #ifndef MSG_SQLITE_WRAPPER_H
18 #define MSG_SQLITE_WRAPPER_H
20 /*==================================================================================================
22 ==================================================================================================*/
27 /*==================================================================================================
29 ==================================================================================================*/
30 #define MSGFW_DB_NAME TZ_SYS_DB_PATH"/.msg_service.db"
32 #define MSGFW_MESSAGE_TABLE_NAME "MSG_MESSAGE_TABLE"
33 #define MSGFW_FOLDER_TABLE_NAME "MSG_FOLDER_TABLE"
34 #define MSGFW_ADDRESS_TABLE_NAME "MSG_ADDRESS_TABLE"
35 #define MSGFW_CONVERSATION_TABLE_NAME "MSG_CONVERSATION_TABLE"
36 #define MSGFW_SIM_MSG_TABLE_NAME "MSG_SIM_TABLE"
37 #define MSGFW_FILTER_TABLE_NAME "MSG_FILTER_TABLE"
38 #define MSGFW_PUSH_MSG_TABLE_NAME "MSG_PUSH_TABLE"
39 #define MSGFW_CB_MSG_TABLE_NAME "MSG_CBMSG_TABLE"
40 #define MMS_PLUGIN_MESSAGE_TABLE_NAME "MSG_MMS_MESSAGE_TABLE"
41 #define MSGFW_SYNCML_MSG_TABLE_NAME "MSG_SYNCML_TABLE"
44 #define MSGFW_RECEIVED_CB_MSG_TABLE_NAME "MSG_CB_MESSAGE_TABLE"
47 #define MSGFW_CB_CHANNEL_INFO_TABLE_NAME "MSG_CB_CHANNEL_INFO_TABLE"
48 #ifdef FEATURE_SMS_CDMA
49 #define MSGFW_CDMA_CB_CHANNEL_INFO_TABLE_NAME "MSG_CDMA_CB_CHANNEL_INFO_TABLE"
52 #define MSGFW_SMS_SENDOPT_TABLE_NAME "MSG_SMS_SENDOPT_TABLE"
53 #define MSGFW_SMS_REPORT_TABLE_NAME "MSG_SMS_REPORT_TABLE"
54 #define MSGFW_REPORT_TABLE_NAME "MSG_REPORT_TABLE"
55 #define MSGFW_PUSH_CONFIG_TABLE_NAME "MSG_PUSHCFG_TABLE"
56 #define MSGFW_MMS_PREVIEW_TABLE_NAME "MSG_MMS_PREVIEW_INFO_TABLE"
57 #define MSGFW_MMS_MULTIPART_TABLE_NAME "MSG_MULTIPART_TABLE"
59 #ifdef FEATURE_SMS_CDMA
60 #define MSGFW_UNIQUENESS_INFO_TABLE_NAME "MSG_UNIQUENESS_INFO_TABLE"
63 #define MSGFW_TMP_MSGID_TABLE_NAME "MSG_TMP_MSGID_TABLE"
65 #define MSGFW_ADDRESS_TEMP_TABLE_NAME "MSG_ADDRESS_TEMP_TABLE"
67 #define MAX_QUERY_LEN 3072
68 #define MAX_FOLDER_NAME_LEN 20
69 #define MAX_ACCOUNT_NAME_LEN 51
71 #define MSGFW_DB_ESCAPE_CHAR '\\'
73 #define SHM_FILE_FOR_DB_LOCK "/.msg_shm_db_lock"
75 /*==================================================================================================
77 ==================================================================================================*/
78 void MsgReleaseMemoryDB();
79 msg_error_t MsgConvertStrWithEscape(const char *input, char **output);
82 /*==================================================================================================
84 ==================================================================================================*/
91 msg_error_t connect();
92 msg_error_t connectReadOnly();
93 msg_error_t disconnect();
95 bool checkTableExist(const char *pTableName);
96 msg_error_t execQuery(const char *pQuery);
97 msg_error_t getTable(const char *pQuery, int *pRowCnt, int *pColumnCnt);
98 msg_error_t getTableWithResult(const char *pQuery, char ***res, int *pRowCnt, int *pColumnCnt);
100 void freeTable(char **db_res);
101 msg_error_t bindText(const char *pBindStr, int index);
102 msg_error_t bindInt(const int pBindint, int index);
103 msg_error_t bindBlob(const void * pBindBlob, int size, int index);
104 msg_error_t prepareQuery(const char *pQuery);
105 msg_error_t stepQuery();
107 void finalizeQuery();
108 int columnInt(int ColumnIndex);
109 const unsigned char* columnText(int ColumnIndex);
110 const void* columnBlob(int ColumnIndex);
111 msg_error_t beginTrans();
112 msg_error_t endTrans(bool Success);
113 int getColumnToInt(int RowIndex);
114 char getColumnToChar(int RowIndex);
115 char* getColumnToString(int RowIndex);
116 void getColumnToString(int RowIndex, int Length, char *pString);
117 msg_error_t getRowId(const char *pTableName, unsigned int *pRowId);
118 void getMmapMutex(const char *shm_file_name);
119 void shm_mutex_timedlock(int sec);
120 void shm_mutex_unlock();
126 pthread_mutex_t *mmapMx;
132 MsgDbHandler *getDbHandle();
133 void removeDbHandle();
134 #endif /* MSG_SQLITE_WRAPPER_H */