2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.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.tizenopensource.org/license
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 #include "MsgUtilStorage.h"
19 #include "MsgSqliteWrapper.h"
20 #include "MsgStorageHandler.h"
23 /*==================================================================================================
25 ==================================================================================================*/
26 extern MsgDbHandler dbHandle;
29 /*==================================================================================================
30 FUNCTION IMPLEMENTATION
31 ==================================================================================================*/
32 MSG_ERROR_T MsgStoAddFolder(const MSG_FOLDER_INFO_S *pFolderInfo)
34 MSG_ERROR_T err = MSG_SUCCESS;
36 unsigned int rowId = 0;
38 char sqlQuery[MAX_QUERY_LEN+1];
40 err = dbHandle.getRowId(MSGFW_FOLDER_TABLE_NAME, &rowId);
42 if (err != MSG_SUCCESS)
46 memset(sqlQuery, 0x00, sizeof(sqlQuery));
47 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, '%s', %d);",
48 MSGFW_FOLDER_TABLE_NAME, rowId, pFolderInfo->folderName, pFolderInfo->folderType);
50 if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
51 return MSG_ERR_DB_EXEC;
57 MSG_ERROR_T MsgStoUpdateFolder(const MSG_FOLDER_INFO_S *pFolderInfo)
59 char sqlQuery[MAX_QUERY_LEN+1];
62 memset(sqlQuery, 0x00, sizeof(sqlQuery));
63 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET FOLDER_NAME = '%s', FOLDER_TYPE = %d WHERE FOLDER_ID = %d;",
64 MSGFW_FOLDER_TABLE_NAME, pFolderInfo->folderName, pFolderInfo->folderType, pFolderInfo->folderId);
66 if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
67 return MSG_ERR_DB_EXEC;
73 MSG_ERROR_T MsgStoDeleteFolder(const MSG_FOLDER_ID_T FolderId)
75 char sqlQuery[MAX_QUERY_LEN+1];
77 dbHandle.beginTrans();
79 memset(sqlQuery, 0x00, sizeof(sqlQuery));
80 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE FOLDER_ID = %d;",
81 MSGFW_MESSAGE_TABLE_NAME, FolderId);
83 // Delete Message in the folder from msg table
84 if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
86 dbHandle.endTrans(false);
87 return MSG_ERR_DB_EXEC;
90 memset(sqlQuery, 0x00, sizeof(sqlQuery));
91 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE FOLDER_ID = %d;",
92 MSGFW_FOLDER_TABLE_NAME, FolderId);
94 // Delete Message in the folder from msg table
95 if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
97 dbHandle.endTrans(false);
98 return MSG_ERR_DB_EXEC;
101 // Clear Address table
102 if (MsgStoClearAddressTable(&dbHandle) != MSG_SUCCESS)
104 dbHandle.endTrans(false);
105 return MSG_ERR_DB_EXEC;
108 dbHandle.endTrans(true);
114 MSG_ERROR_T MsgStoGetFolderList(MSG_FOLDER_LIST_S *pFolderList)
116 if (pFolderList == NULL)
118 MSG_DEBUG("pFolderList is NULL");
119 return MSG_ERR_NULL_POINTER;
125 char sqlQuery[MAX_QUERY_LEN+1];
127 memset(sqlQuery, 0x00, sizeof(sqlQuery));
128 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FOLDER_ID, FOLDER_TYPE, FOLDER_NAME FROM %s;",
129 MSGFW_FOLDER_TABLE_NAME);
131 if (dbHandle.getTable(sqlQuery, &rowCnt) != MSG_SUCCESS)
133 dbHandle.freeTable();
134 return MSG_ERR_DB_GETTABLE;
137 pFolderList->nCount = rowCnt;
139 MSG_DEBUG("pFolderList->nCount [%d]", pFolderList->nCount);
141 pFolderList->folderInfo = (MSG_FOLDER_INFO_S*)new char[sizeof(MSG_FOLDER_INFO_S)*rowCnt];
143 MSG_FOLDER_INFO_S* pTmp = pFolderList->folderInfo;
145 for (int i = 0; i < rowCnt; i++)
147 pTmp->folderId = dbHandle.getColumnToInt(index++);
149 pTmp->folderType = dbHandle.getColumnToInt(index++);
151 memset(pTmp->folderName, 0x00, sizeof(pTmp->folderName));
152 dbHandle.getColumnToString(index++, MAX_FOLDER_NAME_SIZE, pTmp->folderName);
157 dbHandle.freeTable();