a9870db5534b4171f7a4da58d7ddd748bde43c1e
[framework/web/wrt-plugins-tizen.git] / src / Messaging / messageDB / MessageStorageReader.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 #include "MessageStorageReader.h"
19 #include "MsgSqliteWrapper.h"
20
21 #include <dpl/log/log.h>
22 #include <glib.h>
23
24 #define MAX_THREAD_ADDR_LEN     40
25 #define MAX_THREAD_NAME_LEN     195
26 #define MAX_THREAD_DATA_LEN     128
27
28 namespace{
29 //TODO copied from MsgInternalTypes.h
30         typedef unsigned char MSG_MAIN_TYPE_T;
31         typedef unsigned char MSG_SUB_TYPE_T;
32         typedef unsigned char MSG_CLASS_TYPE_T;
33
34         typedef struct
35         {
36                 msg_address_type_t              addressType;                                                                                                    /**< The type of an address in case of an Email or a mobile phone */
37                 msg_recipient_type_t    recipientType;                                                                                                  /**< The type of recipient address in case of To, Cc, and Bcc */
38                 msg_contact_id_t                        contactId;                                                                                                                      /**< The contact ID of address */
39                 char                                                                            addressVal[MAX_ADDRESS_VAL_LEN+1];              /**< The actual value of an address */
40                 char                                                                            displayName[MAX_DISPLAY_NAME_LEN+1];    /**< The display name of an address */
41         } MSG_ADDRESS_INFO_S;
42
43         typedef struct _msg_struct{
44                 int type;
45                 void *data;
46         }msg_struct_s;
47
48         typedef struct
49         {
50                 msg_message_id_t                msgId;                                                                  /**< Indicates the message ID of this message. */
51                 msg_thread_id_t                 threadId;                                                               /**< Indicates the thread ID. */
52                 msg_folder_id_t                 folderId;                                                               /**< Indicates the folder ID. see enum _MSG_FOLDER_TYPE_E */
53                 MSG_MAIN_TYPE_T                 mainType;                                                               /**< Message main type. See enum _MSG_MAIN_TYPE_E */
54                 MSG_SUB_TYPE_T                  subType;                                                                /**< Message sub type. See enum _MSG_SUB_TYPE_E */
55                 MSG_CLASS_TYPE_T                classType;                                                              /**< Message class type. See enum _MSG_CLASS_TYPE_E */
56                 msg_storage_id_t                storageId;                                                              /**< Indicates where the message is saved. see enum _MSG_FOLDER_TYPE_E*/
57                 msg_struct_list_s               *addr_list;
58                 char                                    replyAddress[MAX_PHONE_NUMBER_LEN+1];   /**< Indicates the reply address. */
59                 char                                    subject[MAX_SUBJECT_LEN+1];                                     /**< Indicates the message subject. */
60                 time_t                                  displayTime;                                                                                                    /**< Indicates the display time related to the specific operation. */
61                 msg_network_status_t    networkStatus;                                                  /**< Indicates the network status of the message. */
62                 msg_encode_type_t               encodeType;                                                     /**< Indicates the string encoding type. */
63                 bool                                    bRead;                                                                                                                          /**< Indicates whether the message is read or not. */
64                 bool                                    bProtected;                                                                                                     /**< Indicates whether the message is protected or not. */
65                 bool                                    bBackup;                                                                                                                        /**< Indicates whether the message was restored from PC. */
66                 msg_priority_type_t     priority;                                                               /**< Indicates the priority of the message. */
67                 msg_direction_type_t    direction;                                                              /**< Indicates whether the message is MO or MT, affecting address. */
68                 bool                                    bPortValid;                                                             /**< Indicates whether port information is used or not. */
69                 unsigned short                  dstPort;                                                                /**< Recipient port number, not greater than 16 bit */
70                 unsigned short                  srcPort;                                                                /**< Sender port number, not greater than 16 bit */
71                 int                                     attachCount;                                                                                                    /**< Indicates the count of attached files in mms. */
72                 char                                    thumbPath[MSG_FILEPATH_LEN_MAX+1];
73                 size_t                                  dataSize;                                                                                                                       /**< Indicates the data size. The unit is byte. */
74                 void                                    *pData;                                                                                                                         /**< Indicates the message payload information as a body. default character encoding is UTF-8*/
75                 void                                    *pMmsData;                                                                                                              /**< Indicates the message payload information as a body. default character encoding is UTF-8*/
76         } MSG_MESSAGE_HIDDEN_S;
77
78
79         /**
80          *      @brief  Represents message information for thread view.
81          */
82         typedef struct
83         {
84                 msg_thread_id_t                 threadId;                                                                                                                       /**< Indicates the thread ID of this peer. */
85                 char                                    threadName[MAX_THREAD_NAME_LEN+1];              /**< Indicates the name of this peer. > */
86                 MSG_MAIN_TYPE_T                 mainType;                                                               /**< Indicates the latest msg main type. */
87                 MSG_SUB_TYPE_T                  subType;                                                                /**< Indicates the latest msg sub type. */
88                 char                                    threadData[MAX_THREAD_DATA_LEN+1];              /**< Indicates the latest msg data. */
89                 time_t                                  threadTime;                                                                                                     /**< Indicates the latest msg time. */
90                 msg_direction_type_t    direction;                                                                                                                      /**< Indicates whether the message is MO or MT (affecting address). */
91                 int                                     unreadCnt;                                                                                                              /**< Indicates the unread messages from the Peer. */
92                 int                                     smsCnt;                                                                                                                 /**< Indicates the SMS messages from the Peer. */
93                 int                                     mmsCnt;                                                                                                                 /**< Indicates the MMS messages from the Peer. */
94                 bool                                    bProtected;                                                                                                     /**< Indicates whether the thread includes protected messages.  */
95         } MSG_THREAD_VIEW_S;
96
97         enum _MSG_MAIN_TYPE_E
98         {
99                 MSG_UNKNOWN_TYPE = 0,           /**< Unknown main type */
100                 MSG_SMS_TYPE,                           /**< SMS */
101                 MSG_MMS_TYPE,                           /**< MMS */
102         };
103
104 }//namespace
105
106 enum _MSG_SUB_TYPE_E
107 {
108         /* SMS Specific Message Type */
109         MSG_NORMAL_SMS = 0,                     /**< Text SMS message */
110         MSG_CB_SMS,                                     /**< Cell Broadcasting  message */
111         MSG_JAVACB_SMS,                         /**< JAVA Cell Broadcasting  message */
112         MSG_TYPE0_SMS,                                  /**< Short Message Type 0 */
113         MSG_REPLACE_TYPE1_SMS,          /**< Replace Short Message Type 1 */
114         MSG_REPLACE_TYPE2_SMS,          /**< Replace Short Message Type 2 */
115         MSG_REPLACE_TYPE3_SMS,          /**< Replace Short Message Type 3 */
116         MSG_REPLACE_TYPE4_SMS,          /**< Replace Short Message Type 4 */
117         MSG_REPLACE_TYPE5_SMS,          /**< Replace Short Message Type 5 */
118         MSG_REPLACE_TYPE6_SMS,          /**< Replace Short Message Type 6 */
119         MSG_REPLACE_TYPE7_SMS,          /**< Replace Short Message Type 7 */
120         MSG_WAP_SI_SMS,                         /**< WAP Push Message SI */
121         MSG_WAP_SL_SMS,                         /**< WAP Push Message SL */
122         MSG_WAP_CO_SMS,                         /**< WAP Push Message CO */
123         MSG_MWI_VOICE_SMS,                      /**< MWI Message Voice */
124         MSG_MWI_FAX_SMS,                                /**< MWI Message Fax */
125         MSG_MWI_EMAIL_SMS,                      /**< MWI Message Email */
126         MSG_MWI_OTHER_SMS,                      /**< MWI Message Other */
127         MSG_STATUS_REPORT_SMS,          /**< SMS-STATUS-REPORT */
128         MSG_SYNCML_CP,                          /**< SyncML Message CP */
129         MSG_LBS_SMS,                                    /**< LBS Message */
130         MSG_REJECT_SMS,                         /**< Reject Message */
131         MSG_CONCAT_SIM_SMS,                     /**< Concatenated Message in SIM */
132
133         /* MMS Specific Message Type */
134         MSG_SENDREQ_MMS = 24,                                   /**< MMS Send Request message */
135         MSG_SENDCONF_MMS,                               /**< MMS Send Confirm message */
136         MSG_NOTIFICATIONIND_MMS,                        /**< MMS Notification Indication message */
137         MSG_GET_MMS,                                            /**< MMS GET MMS message */
138         MSG_NOTIFYRESPIND_MMS,                  /**< MMS Notify Response Indication message */
139         MSG_RETRIEVE_MMS,                                       /**< MMS Retrive MMS message */
140         MSG_RETRIEVE_AUTOCONF_MMS,              /**< MMS Retrieve Confirm message by auto retrieving*/
141         MSG_RETRIEVE_MANUALCONF_MMS,    /**< MMS Retrieve Confirm message by manual retrieving*/
142         MSG_ACKNOWLEGEIND_MMS,                  /**< MMS Acknowledge Indication message */
143         MSG_DELIVERYIND_MMS,                            /**< MMS Delivery Indication message */
144         MSG_READRECIND_MMS,                             /**< MMS Read Receive Indication message */
145         MSG_READORGIND_MMS,                             /**< MMS Read Origin Indication message */
146         MSG_FORWARD_MMS,                                        /**< MMS Forward message */
147         MSG_FORWARDREQ_MMS,                             /**< MMS Forward Request message */
148         MSG_FORWARDCONF_MMS,                    /**< MMS Forward Confirm message */
149         MSG_READREPLY_MMS,                              /**< MMS Read Reply message */
150         MSG_SENDREQ_JAVA_MMS,                   /**< MMS Send Request message for JAVA MMS */
151
152         MSG_ETWS_SMS,
153 };
154
155
156
157 MessageStorageReader::MessageStorageReader() {
158         // TODO Auto-generated constructor stub
159
160 }
161
162 MessageStorageReader::~MessageStorageReader() {
163         // TODO Auto-generated destructor stub
164 }
165
166 msg_error_t MessageStorageReader::MsgStoConnectDB(){
167         return MSG_SUCCESS;
168 }
169
170 msg_error_t MessageStorageReader::MsgStoDisconnectDB(){
171         if (dbHandle.disconnect() != MSG_SUCCESS){
172                 LogError(">>>[ERROR] DB Disconnect Fail");
173                 return MSG_ERR_DB_DISCONNECT;
174         }
175
176         LogDebug(">>>");
177
178         return MSG_SUCCESS;
179 }
180
181
182 // MsgStoSearchMessage(const MSG_SEARCH_CONDITION_S *pSearchCon, int offset, int limit, msg_struct_list_s *pMsgList)
183 int MessageStorageReader::queryMessage(const std::string& whereClause, const std::string& orderLimit, /*out*/msg_struct_list_s *pMsgList){
184         LogDebug("<<< whereClause:[" << whereClause << "]");
185
186         // Clear Out Parameter
187         pMsgList->nCount = 0;
188         pMsgList->msg_struct_info = NULL;
189
190         int rowCnt = 0;
191         int index = 26; // numbers of index
192
193         char firstName[MAX_DISPLAY_NAME_LEN+1], lastName[MAX_DISPLAY_NAME_LEN+1];
194         char displayName[MAX_DISPLAY_NAME_LEN+1];
195
196         std::ostringstream oStream;
197         std::string stringSqlQuery;
198         std::string tmpWhereClause;     
199
200         // Get Name Order
201 //      int order = MsgGetContactNameOrder();
202         int order = 0;
203
204                 oStream << "SELECT A.MSG_ID, A.CONV_ID, A.FOLDER_ID, A.STORAGE_ID, A.MAIN_TYPE, A.SUB_TYPE, \
205 A.DISPLAY_TIME, A.DATA_SIZE, A.NETWORK_STATUS, A.READ_STATUS, A.PROTECTED, A.BACKUP, A.PRIORITY, \
206 A.MSG_DIRECTION, A.SCHEDULED_TIME, A.SUBJECT, A.MSG_TEXT, B.ADDRESS_TYPE, B.RECIPIENT_TYPE, \
207 B.CONTACT_ID, B.ADDRESS_VAL, B.DISPLAY_NAME, B.FIRST_NAME, B.LAST_NAME, A.ATTACHMENT_COUNT, A.THUMB_PATH \
208 FROM " << MSGFW_MESSAGE_TABLE_NAME << " A, " << MSGFW_ADDRESS_TABLE_NAME << " B ";
209
210
211         if(whereClause.length()==0){
212                 tmpWhereClause.append("WHERE ");
213         }else{
214                 tmpWhereClause.append(whereClause);
215                 tmpWhereClause.append(" ");
216                 tmpWhereClause.append("AND ");
217         }
218
219         tmpWhereClause.append("(A.CONV_ID = B.CONV_ID AND B.ADDRESS_ID <> 0) ");
220
221         if(orderLimit.length() == 0)
222         {
223                 LogDebug("<<< tmpWhereClause:[" << tmpWhereClause << "]");
224         }
225         else
226         {
227                 tmpWhereClause.append(orderLimit);
228                 LogDebug("<<< tmpWhereClause:[" << tmpWhereClause << "]");
229         }
230         LogDebug("<<< tmpWhereClause:[" << tmpWhereClause << "]");
231
232
233         oStream << tmpWhereClause;
234         stringSqlQuery = oStream.str();
235
236         LogDebug("stringSqlQuery:[" << stringSqlQuery << "]");
237         msg_error_t err = dbHandle.getTable(stringSqlQuery.c_str(), &rowCnt);
238
239         if (err == MSG_ERR_DB_NORECORD) {
240                 LogDebug("MSG_ERR_DB_NORECORD");                
241                 dbHandle.freeTable();
242
243                 return MSG_SUCCESS;
244         } else if (err != MSG_SUCCESS) {
245                 LogDebug("Get table fail. "<< stringSqlQuery);
246
247                 dbHandle.freeTable();
248
249                 return err;
250         }
251         
252         pMsgList->nCount = rowCnt;
253
254         LogDebug("pMsgList->nCount ="<<  pMsgList->nCount);
255
256         pMsgList->msg_struct_info = (msg_struct_t *)new char[sizeof(msg_struct_t) * rowCnt];
257
258         MSG_MESSAGE_HIDDEN_S *pTmp = NULL;
259         msg_struct_s *msg = NULL;
260
261         for (int i = 0; i < rowCnt; i++) {
262                 pMsgList->msg_struct_info[i] = (msg_struct_t)new msg_struct_s;
263
264                 msg = (msg_struct_s *)pMsgList->msg_struct_info[i];
265
266                 msg->type = MSG_STRUCT_MESSAGE_INFO;
267                 msg->data = (int *)new char[sizeof(MSG_MESSAGE_HIDDEN_S)];
268
269                 pTmp = (MSG_MESSAGE_HIDDEN_S *)msg->data;
270
271                 memset(pTmp, 0x00, sizeof(MSG_MESSAGE_HIDDEN_S));
272
273                 pTmp->pData = NULL;
274                 pTmp->pMmsData = NULL;
275
276                 pTmp->msgId = dbHandle.getColumnToInt(index++);
277                 pTmp->threadId = dbHandle.getColumnToInt(index++);
278                 pTmp->folderId = dbHandle.getColumnToInt(index++);
279                 pTmp->storageId = dbHandle.getColumnToInt(index++);
280                 pTmp->mainType = dbHandle.getColumnToInt(index++);
281                 pTmp->subType = dbHandle.getColumnToInt(index++);
282                 pTmp->displayTime = (time_t)dbHandle.getColumnToInt(index++);
283                 pTmp->dataSize = dbHandle.getColumnToInt(index++);
284                 pTmp->networkStatus = dbHandle.getColumnToInt(index++);
285                 pTmp->bRead = dbHandle.getColumnToInt(index++);
286                 pTmp->bProtected = dbHandle.getColumnToInt(index++);
287                 pTmp->bBackup = dbHandle.getColumnToInt(index++);
288                 pTmp->priority = dbHandle.getColumnToInt(index++);
289                 pTmp->direction= dbHandle.getColumnToInt(index++);
290                 index++; // This field is reserved.
291
292                 dbHandle.getColumnToString(index++, MAX_SUBJECT_LEN, pTmp->subject);
293
294                 if (pTmp->mainType == MSG_MMS_TYPE &&
295                         (pTmp->networkStatus == MSG_NETWORK_RETRIEVING || pTmp->networkStatus == MSG_NETWORK_RETRIEVE_FAIL || pTmp->subType == MSG_NOTIFICATIONIND_MMS)) {
296                         pTmp->pData = NULL;
297                         index++;
298                 } else {
299                         LogDebug("pTmp->dataSize = "<< pTmp->dataSize);
300                         pTmp->pData = (void *)new char[pTmp->dataSize + 2];
301                         memset(pTmp->pData, 0x00, pTmp->dataSize + 2);
302
303                         dbHandle.getColumnToString(index++, pTmp->dataSize+1, (char *)pTmp->pData);
304                 }
305
306                 msg_struct_list_s *addr_list = (msg_struct_list_s *)new msg_struct_list_s;
307                 msg_struct_s *addr_info = NULL;
308                 MSG_ADDRESS_INFO_S *address = NULL;
309
310                 addr_list->nCount = 1;
311                 addr_list->msg_struct_info = (msg_struct_t *)new char[sizeof(msg_struct_t *)*MAX_TO_ADDRESS_CNT];
312
313                 msg_struct_s *pTmpAddr = NULL;
314
315                 for (int i = 0; i < MAX_TO_ADDRESS_CNT; i++) {
316                         addr_list->msg_struct_info[i] = (msg_struct_t)new char[sizeof(msg_struct_s)];
317                         pTmpAddr = (msg_struct_s *)addr_list->msg_struct_info[i];
318                         pTmpAddr->type = MSG_STRUCT_ADDRESS_INFO;
319                         pTmpAddr->data = new MSG_ADDRESS_INFO_S;
320                         memset(pTmpAddr->data, 0x00, sizeof(MSG_ADDRESS_INFO_S));
321
322                         addr_list->msg_struct_info[i] = (msg_struct_t)pTmpAddr;
323                 }
324
325                 addr_info = (msg_struct_s *)addr_list->msg_struct_info[0];
326                 address = (MSG_ADDRESS_INFO_S *)addr_info->data;
327                 address->addressType = dbHandle.getColumnToInt(index++);
328                 address->recipientType = dbHandle.getColumnToInt(index++);
329                 address->contactId = dbHandle.getColumnToInt(index++);
330
331                 dbHandle.getColumnToString(index++, MAX_ADDRESS_VAL_LEN, address->addressVal);
332
333                 memset(displayName, 0x00, sizeof(displayName));
334                 dbHandle.getColumnToString(index++, MAX_DISPLAY_NAME_LEN, displayName);
335
336                 memset(firstName, 0x00, sizeof(firstName));
337                 dbHandle.getColumnToString(index++, MAX_DISPLAY_NAME_LEN, firstName);
338
339                 memset(lastName, 0x00, sizeof(lastName));
340                 dbHandle.getColumnToString(index++, MAX_DISPLAY_NAME_LEN, lastName);
341
342                 if (strlen(displayName) <= 0) {
343                         if (order == 0) {
344                                 if (firstName[0] != '\0') {
345                                         strncpy(displayName, firstName, MAX_DISPLAY_NAME_LEN);
346                                 }
347
348                                 if (lastName[0] != '\0') {
349                                         strncat(displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(displayName));
350                                         strncat(displayName, lastName, MAX_DISPLAY_NAME_LEN-strlen(displayName));
351                                 }
352                         }
353 /*
354                         else if (order == 1) {
355                                 if (lastName[0] != '\0') {
356                                         strncpy(displayName, lastName, MAX_DISPLAY_NAME_LEN);
357                                         strncat(displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(displayName));
358                                 }
359
360                                 if (firstName[0] != '\0') {
361                                         strncat(displayName, firstName, MAX_DISPLAY_NAME_LEN-strlen(displayName));
362                                 }
363                         }
364 */
365                 }
366
367                 strncpy(address->displayName, displayName, MAX_DISPLAY_NAME_LEN);
368
369                 pTmp->addr_list = addr_list;
370
371                 pTmp->attachCount = dbHandle.getColumnToInt(index++);
372
373                 dbHandle.getColumnToString(index++, MSG_FILEPATH_LEN_MAX, pTmp->thumbPath);
374
375         }
376         dbHandle.freeTable();
377
378         LogDebug(">>>");
379         return MSG_SUCCESS;
380 }
381
382 //msg_error_t MsgStoGetThreadViewList(const MSG_SORT_RULE_S *pSortRule, msg_struct_list_s *pThreadViewList)
383 int MessageStorageReader::queryConversation(const std::string& whereClause, const std::string& orderLimit,
384         msg_struct_list_s *pThreadViewList){
385
386         pThreadViewList->nCount = 0;
387         pThreadViewList->msg_struct_info = NULL;
388
389         int rowCnt = 0;
390         int index = 10; // numbers of index
391
392         std::ostringstream oStream;
393         std::string stringSqlQuery;
394
395         std::string tmpWhereClause;
396         LogDebug("<<< whereClause:[" << whereClause << "]");
397         if(whereClause.length()==0){
398                 LogDebug("<<< tmpWhereClause:[" << tmpWhereClause << "]");              
399                 tmpWhereClause.append("WHERE (B.SMS_CNT > 0 OR B.MMS_CNT > 0) AND A.CONV_ID = B.CONV_ID ");
400                 LogDebug("<<< tmpWhereClause:[" << tmpWhereClause << "]");                      
401         }else{
402                 LogDebug("<<< tmpWhereClause:[" << tmpWhereClause << "]");      
403                 tmpWhereClause.append(whereClause);
404                 LogDebug("<<< tmpWhereClause:[" << tmpWhereClause << "]");      
405         }
406
407         if(orderLimit.length() == 0)
408         {
409                 LogDebug("<<< tmpWhereClause:[" << tmpWhereClause << "]");
410         }
411         else
412         {
413                 tmpWhereClause.append(orderLimit);
414                 LogDebug("<<< tmpWhereClause:[" << tmpWhereClause << "]");
415         }
416
417         oStream << "SELECT B.CONV_ID, B.UNREAD_CNT, B.SMS_CNT, B.MMS_CNT, \
418 B.MAIN_TYPE, B.SUB_TYPE, B.MSG_DIRECTION, B.DISPLAY_TIME, B.DISPLAY_NAME, B.MSG_TEXT \
419 FROM " << MSGFW_ADDRESS_TABLE_NAME << " A, "  << MSGFW_CONVERSATION_TABLE_NAME  << " B ";
420
421         oStream << tmpWhereClause;
422         stringSqlQuery = oStream.str();
423         LogDebug("stringSqlQuery:[" << stringSqlQuery << "]");
424
425         msg_error_t err = dbHandle.getTable(stringSqlQuery.c_str(), &rowCnt);
426
427         if (err == MSG_ERR_DB_NORECORD) {
428                 dbHandle.freeTable();
429                 return MSG_SUCCESS;
430         } else if (err != MSG_SUCCESS) {
431                 LogDebug("stringSqlQuery:[" << stringSqlQuery << "]");
432                 dbHandle.freeTable();
433                 return err;
434         }
435
436         if (rowCnt < 1) {
437                 LogDebug("rowCnt is %d"<< rowCnt);
438                 dbHandle.freeTable();
439                 return err;
440         }
441
442         pThreadViewList->nCount = rowCnt;
443
444         LogDebug("pThreadViewList->nCount [" << pThreadViewList->nCount << "]");
445
446         pThreadViewList->msg_struct_info = (msg_struct_t *)new char[sizeof(msg_struct_t)*rowCnt];
447
448         MSG_THREAD_VIEW_S *pTmp = NULL;
449         msg_struct_s *thread_t = NULL;
450
451         for (int i = 0; i < rowCnt; i++) {
452                 thread_t = (msg_struct_s *)new msg_struct_s;
453                 pThreadViewList->msg_struct_info[i] = (msg_struct_t)thread_t;
454
455                 thread_t->type = MSG_STRUCT_THREAD_INFO;
456                 thread_t->data = new MSG_THREAD_VIEW_S;
457
458                 pTmp = (MSG_THREAD_VIEW_S *)thread_t->data;
459                 memset(pTmp, 0x00, sizeof(MSG_THREAD_VIEW_S));
460
461                 pTmp->threadId = dbHandle.getColumnToInt(index++);
462
463                 pTmp->unreadCnt = dbHandle.getColumnToInt(index++);
464                 pTmp->smsCnt = dbHandle.getColumnToInt(index++);
465                 pTmp->mmsCnt = dbHandle.getColumnToInt(index++);
466
467                 pTmp->mainType = dbHandle.getColumnToInt(index++);
468                 pTmp->subType = dbHandle.getColumnToInt(index++);
469
470                 pTmp->direction = dbHandle.getColumnToInt(index++);
471                 pTmp->threadTime = (time_t)dbHandle.getColumnToInt(index++);
472
473                 memset(pTmp->threadName, 0x00, sizeof(pTmp->threadName));
474                 dbHandle.getColumnToString(index++, MAX_THREAD_NAME_LEN, pTmp->threadName);
475
476                 memset(pTmp->threadData, 0x00, sizeof(pTmp->threadData));
477                 dbHandle.getColumnToString(index++, MAX_THREAD_DATA_LEN, pTmp->threadData);
478         }
479
480         dbHandle.freeTable();
481
482         return MSG_SUCCESS;
483 }
484