summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSangkoo Kim <sangkoo.kim@samsung.com>2016-03-21 16:20:07 +0900
committerSangkoo Kim <sangkoo.kim@samsung.com>2016-03-21 16:42:02 +0900
commitc4b86c231d4846564eeb216404d91233fa1b636b (patch)
treed843439673f033348487d5b84e429c5b8b676a2b
parent2c3899fc3623d5018279387d8d2429f23b999884 (diff)
downloadmsg-service-c4b86c231d4846564eeb216404d91233fa1b636b.tar.gz
msg-service-c4b86c231d4846564eeb216404d91233fa1b636b.tar.bz2
msg-service-c4b86c231d4846564eeb216404d91233fa1b636b.zip
Add MAPI - select with query
Change-Id: I4232534c407e79b46fe11653b0dc9a476a79e661 Signed-off-by: Sangkoo Kim <sangkoo.kim@samsung.com>
-rwxr-xr-xinclude/mapi/msg_storage.h57
-rwxr-xr-xinclude/proxy/MsgHandle.h4
-rwxr-xr-xinclude/utils/MsgSqliteWrapper.h2
-rwxr-xr-xinclude/utils/MsgUtilStorage.h3
-rwxr-xr-xmapi/msg_storage.cpp43
-rwxr-xr-xproxy/MsgHandleStorage.cpp22
-rwxr-xr-xutils/MsgSqliteWrapper.cpp43
-rwxr-xr-xutils/MsgUtilStorage.cpp46
8 files changed, 218 insertions, 2 deletions
diff --git a/include/mapi/msg_storage.h b/include/mapi/msg_storage.h
index 2cd864f..9967137 100755
--- a/include/mapi/msg_storage.h
+++ b/include/mapi/msg_storage.h
@@ -737,7 +737,7 @@ int msg_get_mem_size(msg_handle_t handle, unsigned int* memsize);
* @retval MSG_ERR_NOT_SUPPORTED Not supported
*/
-int msg_backup_message(msg_handle_t handle, msg_message_backup_type_t type, const char *backup_filepath);
+int msg_backup_message(msg_handle_t handle, msg_message_backup_type_t type, const char *backup_filepath) DEPRECATED;
/**
@@ -760,7 +760,7 @@ int msg_backup_message(msg_handle_t handle, msg_message_backup_type_t type, cons
* @retval MSG_ERR_NOT_SUPPORTED Not supported
*/
-int msg_restore_message(msg_handle_t handle, const char *backup_filepath);
+int msg_restore_message(msg_handle_t handle, const char *backup_filepath) DEPRECATED;
/**
@@ -1124,6 +1124,59 @@ int msg_delete_msgs_by_list(msg_handle_t handle, msg_id_list_s *msg_id_list);
*/
int msg_set_conversation_to_read(msg_handle_t handle, msg_thread_id_t thread_id);
+
+
+/**
+ * @brief Gets a DB records with specified query.
+ *
+ * @since_tizen 3.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
+ *
+ * @remarks You must release @a db_res using msg_db_free().
+ * @remarks You should set @a query with SQL query string after 'SELECT'.
+ *
+ * @param[in] handle The Message handle
+ * @param[in] query The SQL SELECT query
+ * @param[out] db_res The result of SQL SELECT query
+ * @param[out] row_count The row count of result
+ * @param[out] col_count The column count of result
+ *
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR Storage error
+ * @retval MSG_ERR_DB_BUSY DB operation is busy
+ * @retval MSG_ERR_DB_GETTABLE DB get table operation is failed
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ * @retval MSG_ERR_NOT_SUPPORTED Not supported
+ *
+ * @see msg_db_free()
+ */
+int msg_db_select_with_query(msg_handle_t handle, const char *query, char ***db_res, int *row_count, int *col_count);
+
+/**
+ * @brief Release memory for result of SQL query.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] handle The Message handle
+ * @param[in] db_res The result of SQL SELECT query
+ *
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ * @retval MSG_ERR_NOT_SUPPORTED Not supported
+ *
+ * @see msg_db_select_with_query()
+ */
+int msg_db_free(msg_handle_t handle, char **db_res);
/**
* @}
*/
diff --git a/include/proxy/MsgHandle.h b/include/proxy/MsgHandle.h
index 4764f6e..edd472f 100755
--- a/include/proxy/MsgHandle.h
+++ b/include/proxy/MsgHandle.h
@@ -129,6 +129,10 @@ class MsgHandle
/* ETC */
msg_error_t searchMessage(const char *pSearchString, msg_struct_list_s *pThreadViewList);
+
+ msg_error_t dbSelectWithQuery(const char *query, char ***db_res, int *row_count, int *col_count);
+ void dbFree(char **db_res);
+
msg_error_t getRejectMsgList(const char *pNumber, msg_struct_list_s *pRejectMsgList);
msg_error_t regStorageChangeCallback(msg_storage_change_cb onStorageChange, void *pUserParam);
msg_error_t getReportStatus(msg_message_id_t msg_id, msg_struct_list_s *report_list);
diff --git a/include/utils/MsgSqliteWrapper.h b/include/utils/MsgSqliteWrapper.h
index a9696da..27a05f2 100755
--- a/include/utils/MsgSqliteWrapper.h
+++ b/include/utils/MsgSqliteWrapper.h
@@ -95,7 +95,9 @@ public:
bool checkTableExist(const char *pTableName);
msg_error_t execQuery(const char *pQuery);
msg_error_t getTable(const char *pQuery, int *pRowCnt, int *pColumnCnt);
+ msg_error_t getTableWithResult(const char *pQuery, char ***res, int *pRowCnt, int *pColumnCnt);
void freeTable();
+ void freeTable(char **db_res);
msg_error_t bindText(const char *pBindStr, int index);
msg_error_t bindInt(const int pBindint, int index);
msg_error_t bindBlob(const void * pBindBlob, int size, int index);
diff --git a/include/utils/MsgUtilStorage.h b/include/utils/MsgUtilStorage.h
index 4255fd9..07ed625 100755
--- a/include/utils/MsgUtilStorage.h
+++ b/include/utils/MsgUtilStorage.h
@@ -81,6 +81,9 @@ msg_error_t MsgStoGetAddressList(const msg_thread_id_t threadId, msg_struct_list
msg_error_t MsgStoGetMessageList(const MSG_LIST_CONDITION_S *pListCond, msg_struct_list_s *pMsgList, int contactCount);
msg_error_t MsgStoGetMediaList(const msg_thread_id_t threadId, msg_list_handle_t *pMediaList);
+msg_error_t MsgStoDbSelectWithQuery(const char *query, char ***db_res, int *row_count, int *col_count);
+void MsgStoDbFree(char **db_res);
+
#ifdef FEATURE_SMS_CDMA
msg_error_t MsgStoClearUniquenessTable();
#endif
diff --git a/mapi/msg_storage.cpp b/mapi/msg_storage.cpp
index b289a8e..4017d3a 100755
--- a/mapi/msg_storage.cpp
+++ b/mapi/msg_storage.cpp
@@ -861,6 +861,49 @@ EXPORT_API int msg_search_message_for_thread_view(msg_handle_t handle, const cha
return err;
}
+
+EXPORT_API int msg_db_select_with_query(msg_handle_t handle, const char *query, char ***db_res, int *row_count, int *col_count)
+{
+ CHECK_MSG_SUPPORTED(MSG_TELEPHONY_SMS_FEATURE);
+ msg_error_t err = MSG_SUCCESS;
+
+ if (handle == NULL || query == NULL)
+ return MSG_ERR_INVALID_PARAMETER;
+
+ MsgHandle* pHandle = (MsgHandle*)handle;
+
+ try {
+ err = pHandle->dbSelectWithQuery(query, db_res, row_count, col_count);
+ } catch (MsgException& e) {
+ MSG_FATAL("%s", e.what());
+ return MSG_ERR_STORAGE_ERROR;
+ }
+
+ return err;
+}
+
+
+EXPORT_API int msg_db_free(msg_handle_t handle, char **db_res)
+{
+ CHECK_MSG_SUPPORTED(MSG_TELEPHONY_SMS_FEATURE);
+
+ if (handle == NULL || db_res == NULL)
+ return MSG_ERR_INVALID_PARAMETER;
+
+ MsgHandle* pHandle = (MsgHandle*)handle;
+
+ try {
+ pHandle->dbFree(db_res);
+ } catch (MsgException& e) {
+ MSG_FATAL("%s", e.what());
+ return MSG_ERR_STORAGE_ERROR;
+ }
+
+ return MSG_SUCCESS;
+}
+
+
+
EXPORT_API int msg_get_reject_msg_list(msg_handle_t handle, const char *phone_num, msg_struct_list_s *msg_reject_msg_list)
{
CHECK_MSG_SUPPORTED(MSG_TELEPHONY_SMS_FEATURE);
diff --git a/proxy/MsgHandleStorage.cpp b/proxy/MsgHandleStorage.cpp
index 3602578..85ec53c 100755
--- a/proxy/MsgHandleStorage.cpp
+++ b/proxy/MsgHandleStorage.cpp
@@ -1883,3 +1883,25 @@ msg_error_t MsgHandle::getVobject(msg_message_id_t MsgId, void** encodedData)
return MSG_SUCCESS;
}
+
+
+msg_error_t MsgHandle::dbSelectWithQuery(const char *query, char ***db_res, int *row_count, int *col_count)
+{
+ msg_error_t err = MSG_SUCCESS;
+
+ err = MsgStoDbSelectWithQuery(query, db_res, row_count, col_count);
+
+ if (err != MSG_SUCCESS)
+ return err;
+
+ MSG_END();
+
+ return err;
+}
+
+
+void MsgHandle::dbFree(char **db_res)
+{
+ MsgStoDbFree(db_res);
+ MSG_END();
+}
diff --git a/utils/MsgSqliteWrapper.cpp b/utils/MsgSqliteWrapper.cpp
index 9143e35..2cd4206 100755
--- a/utils/MsgSqliteWrapper.cpp
+++ b/utils/MsgSqliteWrapper.cpp
@@ -78,6 +78,9 @@ msg_error_t MsgDbHandler::connect()
if (ret == SQLITE_OK) {
MSG_DEBUG("DB Connect Success : [%p]", handle);
return MSG_SUCCESS;
+ } else if (ret == SQLITE_PERM){
+ MSG_DEBUG("DB Connect Fail [%d]", ret);
+ return MSG_ERR_PERMISSION_DENIED;
} else {
MSG_DEBUG("DB Connect Fail [%d]", ret);
return MSG_ERR_DB_CONNECT;
@@ -106,6 +109,9 @@ msg_error_t MsgDbHandler::connectReadOnly()
if (ret == SQLITE_OK) {
MSG_DEBUG("DB Connect Success : [%p]", handle);
return MSG_SUCCESS;
+ } else if (ret == SQLITE_PERM){
+ MSG_DEBUG("DB Connect Fail [%d]", ret);
+ return MSG_ERR_PERMISSION_DENIED;
} else {
MSG_DEBUG("DB Connect Fail [%d]", ret);
return MSG_ERR_DB_CONNECT;
@@ -225,6 +231,36 @@ msg_error_t MsgDbHandler::getTable(const char *pQuery, int *pRowCnt, int *pColum
}
+msg_error_t MsgDbHandler::getTableWithResult(const char *pQuery, char ***res, int *pRowCnt, int *pColumnCnt)
+{
+ int ret = 0;
+
+ *pRowCnt = 0;
+ if (pColumnCnt)
+ *pColumnCnt = 0;
+
+ MSG_DEBUG("[%s]", pQuery);
+ ret = sqlite3_get_table(handle, pQuery, res, pRowCnt, pColumnCnt, NULL);
+
+ if (ret == SQLITE_OK) {
+ if (*pRowCnt == 0) { /* when the no record return 'MSG_ERR_DB_NORECORD' */
+ MSG_DEBUG("No Query Result");
+ return MSG_ERR_DB_NORECORD;
+ }
+
+ MSG_DEBUG("Get Table Success");
+ return MSG_SUCCESS;
+ } else if (ret == SQLITE_BUSY) {
+ MSG_DEBUG("The database file is locked [%d]", ret);
+ return MSG_ERR_DB_BUSY;
+ } else {
+ MSG_DEBUG("Get Table Fail [%d]", ret);
+ return MSG_ERR_DB_GETTABLE;
+ }
+
+ return MSG_SUCCESS;
+}
+
void MsgDbHandler::freeTable()
{
if (result) {
@@ -233,6 +269,13 @@ void MsgDbHandler::freeTable()
}
}
+void MsgDbHandler::freeTable(char **db_res)
+{
+ if (db_res) {
+ sqlite3_free_table(db_res);
+ db_res = NULL;
+ }
+}
msg_error_t MsgDbHandler::bindText(const char *pBindStr, int index)
{
diff --git a/utils/MsgUtilStorage.cpp b/utils/MsgUtilStorage.cpp
index f56820e..ad2e9ae 100755
--- a/utils/MsgUtilStorage.cpp
+++ b/utils/MsgUtilStorage.cpp
@@ -28,6 +28,7 @@
#include "MsgGconfWrapper.h"
#include "MsgUtilFunction.h"
#include "MsgUtilStorage.h"
+#include "MsgException.h"
#include <storage.h>
@@ -2864,6 +2865,51 @@ msg_error_t MsgStoGetMediaList(const msg_thread_id_t threadId, msg_list_handle_t
return MSG_SUCCESS;
}
+
+msg_error_t MsgStoDbSelectWithQuery(const char *szQuery, char ***db_res, int *row_count, int *col_count)
+{
+ MSG_BEGIN();
+
+ msg_error_t err = MSG_SUCCESS;
+
+ MsgDbHandler *dbHandle = getDbHandle();
+ err = dbHandle->connectReadOnly();
+ if (err != MSG_SUCCESS) {
+ MSG_ERR("db connect (read only) is failed [%d]", err);
+ return err;
+ }
+
+ char *zSQL = sqlite3_mprintf("SELECT %q;", szQuery);
+
+ if (zSQL) {
+ err = dbHandle->getTableWithResult((const char *)zSQL, db_res, row_count, col_count);
+ sqlite3_free(zSQL);
+ zSQL = NULL;
+ } else {
+ THROW(MsgException::INVALID_RESULT, "sqlite3_mprintf() is failed");
+ }
+
+ MSG_DEBUG("getTableWithResult :: row_count=[%d], col_count=[%d]", *row_count, *col_count);
+
+ if (err == MSG_ERR_DB_NORECORD) {
+ dbHandle->freeTable(*db_res);
+ err = MSG_SUCCESS;
+ } else if (err != MSG_SUCCESS) {
+ MSG_DEBUG("Fail to getTable().");
+ dbHandle->freeTable(*db_res);
+ }
+
+ return err;
+}
+
+
+void MsgStoDbFree(char **db_res)
+{
+ MsgDbHandler *dbHandle = getDbHandle();
+ dbHandle->freeTable(db_res);
+}
+
+
#ifdef FEATURE_SMS_CDMA
msg_error_t MsgStoClearUniquenessTable()
{