err = plg->addMessage(pMsg, pSendOptInfo, pFileData);
- if (err != MSG_SUCCESS)
+ if (err != MSG_SUCCESS) {
return MSG_ERR_STORAGE_ERROR;
+ }
if (pMsg->msgType.subType == MSG_SENDREQ_MMS) {
MSG_DEBUG("pMsg->msgText: %s, pMsg->thumbPath: %s ", pMsg->msgText, pMsg->thumbPath);
err = MsgStoUpdateMMSMessage(pMsg);
- if (err != MSG_SUCCESS)
+ if (err != MSG_SUCCESS) {
return MSG_ERR_STORAGE_ERROR;
-
+ }
}
}
}
msg_error_t MsgStoDeleteMessageByList(msg_id_list_s *pMsgIdList)
{
MSG_BEGIN();
+
msg_error_t err = MSG_SUCCESS;
+ if (pMsgIdList->nCount < 1) {
+ MSG_DEBUG("pMsgIdList->nCount < 1");
+ return err;
+ }
+
+ MSG_DEBUG("pMsgIdList->nCount [%d]", pMsgIdList->nCount);
char sqlQuery[MAX_QUERY_LEN+1];
- char whereQuery[MAX_QUERY_LEN+1];
- char sqlQuerySubset[(MAX_QUERY_LEN/5)+1];
queue<msg_thread_id_t> threadList;
int listCnt = sizeof(tableList)/sizeof(char *);
int rowCnt = 0;
- memset(whereQuery, 0x00, sizeof(whereQuery));
-
- if (pMsgIdList->nCount < 1) {
- return MSG_SUCCESS;
- } else {
- for (int i=0; i < pMsgIdList->nCount; i++) {
- memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
- if (i==0)
- snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "(MSG_ID = %d ", pMsgIdList->msgIdList[i]);
- else
- snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "OR MSG_ID = %d ", pMsgIdList->msgIdList[i]);
- strncat(whereQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(whereQuery));
- }
+ // Clear tmp table
+ memset(sqlQuery, 0x00, sizeof(sqlQuery));
+ snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s;", MSGFW_TMP_MSGID_TABLE_NAME);
+ err = dbHandle.execQuery(sqlQuery);
+ if (err != MSG_SUCCESS) {
+ MSG_DEBUG("Fail to execQuery().");
+ return err;
+ }
+ // Insert tmp msg ids to delete.
+ dbHandle.beginTrans();
+ for (int i = 0; i < pMsgIdList->nCount; i++)
+ {
+ memset(sqlQuery, 0x00, sizeof(sqlQuery));
+ snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d);",
+ MSGFW_TMP_MSGID_TABLE_NAME, pMsgIdList->msgIdList[i]);
+ err = dbHandle.execQuery(sqlQuery);
+ if (err != MSG_SUCCESS) MSG_DEBUG("Fail to execQuery().");
+ }
+ err = dbHandle.endTrans(true);
+ if (err != MSG_SUCCESS) {
+ MSG_DEBUG("Fail to endTrans(true).");
+ dbHandle.endTrans(false);
+ return err;
}
- strncat(whereQuery, ");", MAX_QUERY_LEN-strlen(whereQuery));
// Get conversation ID from Folder
memset(sqlQuery, 0x00, sizeof(sqlQuery));
- snprintf(sqlQuery, sizeof(sqlQuery), "SELECT DISTINCT(CONV_ID) FROM %s WHERE ", MSGFW_MESSAGE_TABLE_NAME);
- strncat(sqlQuery, whereQuery, MAX_QUERY_LEN-strlen(sqlQuery));
+ snprintf(sqlQuery, sizeof(sqlQuery), "SELECT DISTINCT(CONV_ID) FROM %s WHERE MSG_ID IN (SELECT MSG_ID FROM %s);",
+ MSGFW_MESSAGE_TABLE_NAME, MSGFW_TMP_MSGID_TABLE_NAME);
err = dbHandle.getTable(sqlQuery, &rowCnt);
if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
- MSG_DEBUG("sql query is %s.", sqlQuery);
+ MSG_DEBUG("Fail to getTable().");
dbHandle.freeTable();
return err;
}
- if (rowCnt <= 0) {
+ MSG_DEBUG("rowCnt [%d]", rowCnt);
+
+ if (rowCnt < 1) {
dbHandle.freeTable();
return MSG_SUCCESS;
}
MSG_DEBUG("thread ID : %d", dbHandle.getColumnToInt(i));
threadList.push((msg_thread_id_t)dbHandle.getColumnToInt(i));
}
-
dbHandle.freeTable();
/*** Delete Sim Message In Folder **/
memset(sqlQuery, 0x00, sizeof(sqlQuery));
- snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE STORAGE_ID = %d AND ", MSGFW_MESSAGE_TABLE_NAME, MSG_STORAGE_SIM);
- strncat(sqlQuery, whereQuery, MAX_QUERY_LEN-strlen(sqlQuery));
+ snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE STORAGE_ID = %d AND MSG_ID IN (SELECT MSG_ID FROM %s);",
+ MSGFW_MESSAGE_TABLE_NAME, MSG_STORAGE_SIM, MSGFW_TMP_MSGID_TABLE_NAME);
rowCnt = 0;
err = dbHandle.getTable(sqlQuery, &rowCnt);
if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
- MSG_DEBUG("sql query is %s.", sqlQuery);
+ MSG_DEBUG("Fail to getTable().");
dbHandle.freeTable();
- return err;
+ rowCnt = 0;
}
for (int i = 1; i <= rowCnt; i++) {
err = MsgStoDeleteMessage(dbHandle.getColumnToInt(i), false);
-
if (err != MSG_SUCCESS) {
MSG_DEBUG("MsgStoDeleteMessage() Error!!!");
- dbHandle.freeTable();
- return err;
}
}
-
dbHandle.freeTable();
/*** **/
dbHandle.beginTrans();
-
for (int i = 0; i < listCnt; i++) {
if (!strcmp(tableList[i], MMS_PLUGIN_MESSAGE_TABLE_NAME)) {
- int rowCnt = 0;
+ char filePath[MSG_FILEPATH_LEN_MAX];
+ char dirPath[MSG_FILEPATH_LEN_MAX];
- char filePath[MSG_FILEPATH_LEN_MAX] = {0,};
- char dirPath[MSG_FILEPATH_LEN_MAX] = {0,};
-// char thumbnailPath[MSG_FILEPATH_LEN_MAX] = {0,};
+ rowCnt = 0;
- //get mms msg id list
+ // MMS file path to delete.
memset(sqlQuery, 0x00, sizeof(sqlQuery));
- snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s WHERE ", MMS_PLUGIN_MESSAGE_TABLE_NAME);
- strncat(sqlQuery, whereQuery, MAX_QUERY_LEN-strlen(sqlQuery));
+ snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s WHERE MSG_ID IN (SELECT MSG_ID FROM %s);",
+ MMS_PLUGIN_MESSAGE_TABLE_NAME, MSGFW_TMP_MSGID_TABLE_NAME);
err = dbHandle.getTable(sqlQuery, &rowCnt);
- MSG_DEBUG("rowCnt %d", rowCnt);
if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
- MSG_DEBUG("sqlQuery [%s]", sqlQuery);
- dbHandle.freeTable();
- dbHandle.endTrans(false);
- return err;
+ MSG_DEBUG("Fail to getTable().");
+ rowCnt = 0;
}
+ MSG_DEBUG("rowCnt %d", rowCnt);
+
for (int i = 1; i <= rowCnt; i++) {
memset(filePath, 0x00, sizeof(filePath));
+ memset(dirPath, 0x00, sizeof(dirPath));
dbHandle.getColumnToString(i, MSG_FILEPATH_LEN_MAX, filePath);
MSG_DEBUG("filePath [%s]", filePath);
- //delete raw file
+ // Delete raw file.
snprintf(dirPath, sizeof(dirPath), "%s.dir", filePath);
if (remove(filePath) == -1)
rmdir(dirPath);
}
-
dbHandle.freeTable();
+
} else if (!strcmp(tableList[i], MSGFW_MMS_PREVIEW_TABLE_NAME)) {
+
char filePath[MSG_FILEPATH_LEN_MAX] = {0,};
+
+ rowCnt = 0;
+
memset(sqlQuery, 0x00, sizeof(sqlQuery));
snprintf(sqlQuery, sizeof(sqlQuery),
"SELECT VALUE FROM %s "
"WHERE (TYPE=%d OR TYPE=%d) "
- "AND ",
- MSGFW_MMS_PREVIEW_TABLE_NAME, MSG_MMS_ITEM_TYPE_IMG, MSG_MMS_ITEM_TYPE_VIDEO);
+ "AND MSG_ID IN (SELECT MSG_ID FROM %s);",
+ MSGFW_MMS_PREVIEW_TABLE_NAME,
+ MSG_MMS_ITEM_TYPE_IMG, MSG_MMS_ITEM_TYPE_VIDEO,
+ MSGFW_TMP_MSGID_TABLE_NAME);
- strncat(sqlQuery, whereQuery, MAX_QUERY_LEN-strlen(sqlQuery));
+ err = dbHandle.getTable(sqlQuery, &rowCnt);
- if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS) {
- dbHandle.endTrans(false);
- return MSG_ERR_DB_PREPARE;
+ if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
+ MSG_DEBUG("Fail to getTable().");
+ rowCnt = 0;
}
- while (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
- memset(filePath, 0x00, sizeof(filePath));
+ MSG_DEBUG("rowCnt %d", rowCnt);
- strncpy(filePath, (char *)dbHandle.columnText(0), MSG_FILEPATH_LEN_MAX);
+ for (int i = 1; i <= rowCnt; i++) {
+ memset(filePath, 0x00, sizeof(filePath));
+ dbHandle.getColumnToString(i, MSG_FILEPATH_LEN_MAX, filePath);
if (remove(filePath) == -1)
MSG_DEBUG("Fail to delete file [%s]", filePath);
else
MSG_DEBUG("Success to delete file [%s]", filePath);
}
-
- dbHandle.finalizeQuery();
+ dbHandle.freeTable();
}
memset(sqlQuery, 0x00, sizeof(sqlQuery));
-
- snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE ", tableList[i]);
- strncat(sqlQuery, whereQuery, MAX_QUERY_LEN-strlen(sqlQuery));
+ snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID IN (SELECT MSG_ID FROM %s);",
+ tableList[i], MSGFW_TMP_MSGID_TABLE_NAME);
// Delete Message in specific folder from table
err = dbHandle.execQuery(sqlQuery);
if (err != MSG_SUCCESS) {
- MSG_DEBUG("sqlQuery [%s]", sqlQuery);
- dbHandle.endTrans(false);
- return err;
+ MSG_DEBUG("Fail to execQuery().");
}
}
// Clear Conversation table
err = MsgStoClearConversationTable(&dbHandle);
- if (err != MSG_SUCCESS) {
- dbHandle.endTrans(false);
- return err;
- }
+ if (err != MSG_SUCCESS) MSG_DEBUG("Fail to MsgStoClearConversationTable().");
// Update Address
while (!threadList.empty()) {
err = MsgStoUpdateConversation(&dbHandle, threadList.front());
-
+ if (err != MSG_SUCCESS) MSG_DEBUG("Fail to MsgStoUpdateConversation().");
threadList.pop();
-
- if (err != MSG_SUCCESS) {
- dbHandle.endTrans(false);
- return err;
- }
}
-
- dbHandle.endTrans(true);
+ err = dbHandle.endTrans(true);
+ if (err != MSG_SUCCESS) {
+ MSG_DEBUG("Fail to endTrans(true).");
+ dbHandle.endTrans(false);
+ return err;
+ }
int smsCnt = 0;
int mmsCnt = 0;
MsgSettingSetIndicator(smsCnt, mmsCnt);
-#if 0
-/*** Create thread for noti and phone log delete. **/
- if (pMsgIdList->nCount > 0) {
- msg_id_list_s *pToDeleteMsgIdListCpy = NULL;
- pToDeleteMsgIdListCpy = (msg_id_list_s *)new char[sizeof(msg_id_list_s)];
- memset(pToDeleteMsgIdListCpy, 0x00, sizeof(msg_id_list_s));
- pToDeleteMsgIdListCpy->nCount = pMsgIdList->nCount;
- pToDeleteMsgIdListCpy->msgIdList = (msg_message_id_t *)new char[sizeof(msg_message_id_t)*pMsgIdList->nCount];
- memcpy(pToDeleteMsgIdListCpy->msgIdList, pMsgIdList->msgIdList, sizeof(msg_message_id_t)*pMsgIdList->nCount);
-
- if (g_idle_add(startToDeletePhoneLog, (void *)pToDeleteMsgIdListCpy) == 0) {
- MSG_DEBUG("startToDeletePhoneLog not invoked: %s", strerror(errno));
- // memory free
- if (pToDeleteMsgIdListCpy != NULL) {
- //free peer info list
- if (pToDeleteMsgIdListCpy->msgIdList != NULL)
- delete [] pToDeleteMsgIdListCpy->msgIdList;
-
- delete [] pToDeleteMsgIdListCpy;
- }
- err = MSG_ERR_UNKNOWN;
- }
- }
-/*** **/
-#endif
-
MsgRefreshNoti(false);
+ // Clear tmp table
+ memset(sqlQuery, 0x00, sizeof(sqlQuery));
+ snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s;", MSGFW_TMP_MSGID_TABLE_NAME);
+ err = dbHandle.execQuery(sqlQuery);
+ if (err != MSG_SUCCESS) MSG_DEBUG("Fail to execQuery().");
+
MSG_END();
return MSG_SUCCESS;
}