3 * Copyright (c) 2000-2012 Samsung Electronics Co., Ltd. All Rights Reserved.
5 * This file is part of msg-service.
7 * Contact: Jaeyun Jeong <jyjeong@samsung.com>
8 * Sangkoo Kim <sangkoo.kim@samsung.com>
9 * Seunghwan Lee <sh.cat.lee@samsung.com>
10 * SoonMin Jung <sm0415.jung@samsung.com>
11 * Jae-Young Lee <jy4710.lee@samsung.com>
12 * KeeBum Kim <keebum.kim@samsung.com>
14 * PROPRIETARY/CONFIDENTIAL
16 * This software is the confidential and proprietary information of
17 * SAMSUNG ELECTRONICS ("Confidential Information"). You shall not
18 * disclose such Confidential Information and shall use it only in
19 * accordance with the terms of the license agreement you entered
20 * into with SAMSUNG ELECTRONICS.
22 * SAMSUNG make no representations or warranties about the suitability
23 * of the software, either express or implied, including but not limited
24 * to the implied warranties of merchantability, fitness for a particular
25 * purpose, or non-infringement. SAMSUNG shall not be liable for any
26 * damages suffered by licensee as a result of using, modifying or
27 * distributing this software or its derivatives.
32 #include "MsgUtilStorage.h"
33 #include "MsgSqliteWrapper.h"
34 #include "MsgStorageHandler.h"
37 /*==================================================================================================
39 ==================================================================================================*/
40 extern MsgDbHandler dbHandle;
43 /*==================================================================================================
44 FUNCTION IMPLEMENTATION
45 ==================================================================================================*/
46 MSG_ERROR_T MsgStoAddFolder(const MSG_FOLDER_INFO_S *pFolderInfo)
48 MSG_ERROR_T err = MSG_SUCCESS;
50 unsigned int rowId = 0;
52 char sqlQuery[MAX_QUERY_LEN+1];
54 err = dbHandle.getRowId(MSGFW_FOLDER_TABLE_NAME, &rowId);
56 if (err != MSG_SUCCESS)
60 memset(sqlQuery, 0x00, sizeof(sqlQuery));
61 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, '%s', %d);",
62 MSGFW_FOLDER_TABLE_NAME, rowId, pFolderInfo->folderName, pFolderInfo->folderType);
64 if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
65 return MSG_ERR_DB_EXEC;
71 MSG_ERROR_T MsgStoUpdateFolder(const MSG_FOLDER_INFO_S *pFolderInfo)
73 char sqlQuery[MAX_QUERY_LEN+1];
76 memset(sqlQuery, 0x00, sizeof(sqlQuery));
77 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET FOLDER_NAME = '%s', FOLDER_TYPE = %d WHERE FOLDER_ID = %d;",
78 MSGFW_FOLDER_TABLE_NAME, pFolderInfo->folderName, pFolderInfo->folderType, pFolderInfo->folderId);
80 if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
81 return MSG_ERR_DB_EXEC;
87 MSG_ERROR_T MsgStoDeleteFolder(const MSG_FOLDER_ID_T FolderId)
89 char sqlQuery[MAX_QUERY_LEN+1];
91 dbHandle.beginTrans();
93 memset(sqlQuery, 0x00, sizeof(sqlQuery));
94 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE FOLDER_ID = %d;",
95 MSGFW_MESSAGE_TABLE_NAME, FolderId);
97 // Delete Message in the folder from msg table
98 if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
100 dbHandle.endTrans(false);
101 return MSG_ERR_DB_EXEC;
104 memset(sqlQuery, 0x00, sizeof(sqlQuery));
105 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE FOLDER_ID = %d;",
106 MSGFW_FOLDER_TABLE_NAME, FolderId);
108 // Delete Message in the folder from msg table
109 if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
111 dbHandle.endTrans(false);
112 return MSG_ERR_DB_EXEC;
115 // Clear Address table
116 if (MsgStoClearAddressTable(&dbHandle) != MSG_SUCCESS)
118 dbHandle.endTrans(false);
119 return MSG_ERR_DB_EXEC;
122 dbHandle.endTrans(true);
128 MSG_ERROR_T MsgStoGetFolderList(MSG_FOLDER_LIST_S *pFolderList)
130 if (pFolderList == NULL)
132 MSG_DEBUG("pFolderList is NULL");
133 return MSG_ERR_NULL_POINTER;
139 char sqlQuery[MAX_QUERY_LEN+1];
141 memset(sqlQuery, 0x00, sizeof(sqlQuery));
142 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FOLDER_ID, FOLDER_TYPE, FOLDER_NAME FROM %s;",
143 MSGFW_FOLDER_TABLE_NAME);
145 if (dbHandle.getTable(sqlQuery, &rowCnt) != MSG_SUCCESS)
147 dbHandle.freeTable();
148 return MSG_ERR_DB_GETTABLE;
151 pFolderList->nCount = rowCnt;
153 MSG_DEBUG("pFolderList->nCount [%d]", pFolderList->nCount);
155 pFolderList->folderInfo = (MSG_FOLDER_INFO_S*)new char[sizeof(MSG_FOLDER_INFO_S)*rowCnt];
157 MSG_FOLDER_INFO_S* pTmp = pFolderList->folderInfo;
159 for (int i = 0; i < rowCnt; i++)
161 pTmp->folderId = dbHandle.getColumnToInt(index++);
163 pTmp->folderType = dbHandle.getColumnToInt(index++);
165 memset(pTmp->folderName, 0x00, sizeof(pTmp->folderName));
166 dbHandle.getColumnToString(index++, MAX_FOLDER_NAME_SIZE, pTmp->folderName);
171 dbHandle.freeTable();