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