Fix svace defect
[platform/core/messaging/msg-service.git] / plugin / sms_plugin / SmsPluginStorage.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
3  *
4  * Licensed under the Apache License, Version 2.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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15 */
16
17 #include <errno.h>
18
19 #include "MsgDebug.h"
20 #include "MsgCppTypes.h"
21 #include "MsgException.h"
22 #include "MsgContact.h"
23 #include "MsgUtilFile.h"
24 #include "MsgUtilStorage.h"
25 #include "MsgUtilFunction.h"
26 #include "MsgGconfWrapper.h"
27 #include "MsgNotificationWrapper.h"
28 #include "SmsPluginMain.h"
29 #include "SmsPluginSimMsg.h"
30 #include "SmsPluginStorage.h"
31
32
33 /*==================================================================================================
34                                      IMPLEMENTATION OF SmsPluginStorage - Member Functions
35 ==================================================================================================*/
36 SmsPluginStorage* SmsPluginStorage::pInstance = NULL;
37
38
39 SmsPluginStorage::SmsPluginStorage()
40 {
41         memset(&msgInfo, 0x00, sizeof(msgInfo));
42         memset(&addrInfo, 0x00, sizeof(addrInfo));
43 }
44
45
46 SmsPluginStorage::~SmsPluginStorage()
47 {
48 }
49
50
51 SmsPluginStorage* SmsPluginStorage::instance()
52 {
53         if (!pInstance) {
54                 MSG_DEBUG("pInstance is NULL. Now creating instance.");
55                 pInstance = new SmsPluginStorage();
56         }
57
58         return pInstance;
59 }
60
61
62 msg_error_t SmsPluginStorage::insertMsgRef(MSG_MESSAGE_INFO_S *pMsg, unsigned char msgRef, int index)
63 {
64         MSG_BEGIN();
65
66         time_t curTime = time(NULL);
67
68         MsgDbHandler *dbHandle = getDbHandle();
69
70         char sqlQuery[MAX_QUERY_LEN+1];
71         char *normalNum = NULL;
72
73         memset(sqlQuery, 0x00, sizeof(sqlQuery));
74
75         normalNum = msg_normalize_number(pMsg->addressList[index].addressVal);
76
77         MSG_SEC_DEBUG("Insert MsgID=[%d], Address=[%s], MsgRef=[%d], Time=[%d]", \
78                         pMsg->msgId, normalNum, (int)msgRef, (int)curTime);
79
80         snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %s, %d, 0, -1, %d);",
81                         MSGFW_SMS_REPORT_TABLE_NAME, pMsg->msgId, normalNum, (int)msgRef, (int)curTime);
82
83         if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
84                 MSG_DEBUG("MsgExecQuery() : [%s]", sqlQuery);
85                 return MSG_ERR_DB_EXEC;
86         }
87
88         MSG_END();
89
90         return MSG_SUCCESS;
91 }
92
93
94 msg_error_t SmsPluginStorage::updateMsgDeliverStatus(MSG_MESSAGE_INFO_S *pMsgInfo, unsigned char msgRef)
95 {
96         MSG_BEGIN();
97
98         MsgDbHandler *dbHandle = getDbHandle();
99
100         char sqlQuery[MAX_QUERY_LEN+1];
101
102         msg_message_id_t msgId = 0;
103         int rowCnt = 0;
104         char *normalNum = NULL;
105
106         normalNum = msg_normalize_number(pMsgInfo->addressList[0].addressVal);
107
108         memset(sqlQuery, 0x00, sizeof(sqlQuery));
109         snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE ADDRESS_VAL = %s AND MSG_REF > 0 ORDER BY TIME ASC;",
110                         MSGFW_SMS_REPORT_TABLE_NAME, normalNum);
111         MSG_DEBUG("[SQL Query] %s", sqlQuery);
112
113         if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
114                 return MSG_ERR_DB_PREPARE;
115
116         if (dbHandle->stepQuery() == MSG_ERR_DB_ROW)
117                 msgId = dbHandle->columnInt(0);
118
119         dbHandle->finalizeQuery();
120
121         pMsgInfo->msgId = msgId;
122
123         /** Update Status - MSG_MESSAGE_TABLE */
124         memset(sqlQuery, 0x00, sizeof(sqlQuery));
125         snprintf(sqlQuery, sizeof(sqlQuery), "SELECT * FROM %s WHERE MSG_ID = %d AND MSG_REF > 0;",
126                         MSGFW_SMS_REPORT_TABLE_NAME, msgId);
127
128         if (dbHandle->getTable(sqlQuery, &rowCnt, NULL) != MSG_SUCCESS) {
129                 dbHandle->freeTable();
130                 return MSG_ERR_DB_GETTABLE;
131         }
132
133         dbHandle->freeTable();
134
135         MSG_DEBUG("Selected row count = [%d]", rowCnt);
136
137         if (rowCnt == 1 && pMsgInfo->networkStatus == MSG_NETWORK_DELIVER_SUCCESS) {
138                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
139                 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET NETWORK_STATUS = %d WHERE MSG_ID = %d;",
140                                 MSGFW_MESSAGE_TABLE_NAME, (int)pMsgInfo->networkStatus, msgId);
141                 MSG_DEBUG("[SQL Query] %s", sqlQuery);
142
143                 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
144                         MSG_DEBUG("Query Failed : [%s]", sqlQuery);
145                         return MSG_ERR_DB_EXEC;
146                 }
147         }
148
149         /** Update Status - MSG_REPORT_TABLE */
150         if (pMsgInfo->networkStatus == MSG_NETWORK_DELIVER_SUCCESS) {
151                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
152                 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET MSG_REF = -1, STATUS = %d, TIME = %d WHERE MSG_ID = %d and ADDRESS_VAL = '%s';",
153                                 MSGFW_SMS_REPORT_TABLE_NAME, 1, (int)pMsgInfo->displayTime, msgId, normalNum);
154                 MSG_DEBUG("[SQL Query] %s", sqlQuery);
155
156                 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
157                         MSG_DEBUG("Query Failed : [%s]", sqlQuery);
158                         return MSG_ERR_DB_EXEC;
159                 }
160         } else if (pMsgInfo->networkStatus == MSG_NETWORK_DELIVER_EXPIRED) {
161                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
162                 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET MSG_REF = -1, STATUS = %d, TIME = %d WHERE MSG_ID = %d and ADDRESS_VAL = '%s';",
163                                 MSGFW_SMS_REPORT_TABLE_NAME, 0, (int)pMsgInfo->displayTime, msgId, normalNum);
164                 MSG_DEBUG("[SQL Query] %s", sqlQuery);
165
166                 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
167                         MSG_DEBUG("Query Failed : [%s]", sqlQuery);
168                         return MSG_ERR_DB_EXEC;
169                 }
170         } else if (pMsgInfo->networkStatus == MSG_NETWORK_DELIVER_PENDING) {
171                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
172                 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET MSG_REF = -1, STATUS = %d, TIME = %d WHERE MSG_ID = %d and ADDRESS_VAL = '%s';",
173                                 MSGFW_SMS_REPORT_TABLE_NAME, 3, (int)pMsgInfo->displayTime, msgId, normalNum);
174                 MSG_DEBUG("[SQL Query] %s", sqlQuery);
175
176                 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
177                         MSG_DEBUG("Query Failed : [%s]", sqlQuery);
178                         return MSG_ERR_DB_EXEC;
179                 }
180         } else if (pMsgInfo->networkStatus == MSG_NETWORK_DELIVER_FAIL) {
181                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
182                 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET MSG_REF = -1, STATUS = %d, TIME = %d WHERE MSG_ID = %d and ADDRESS_VAL = '%s';",
183                                 MSGFW_SMS_REPORT_TABLE_NAME, 8, (int)pMsgInfo->displayTime, msgId, normalNum);
184                 MSG_DEBUG("[SQL Query] %s", sqlQuery);
185
186                 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
187                         MSG_DEBUG("Query Failed : [%s]", sqlQuery);
188                         return MSG_ERR_DB_EXEC;
189                 }
190         }
191
192         MSG_END();
193
194         return MSG_SUCCESS;
195 }
196
197
198 msg_error_t SmsPluginStorage::updateSentMsg(MSG_MESSAGE_INFO_S *pMsgInfo, msg_network_status_t status)
199 {
200         MSG_BEGIN();
201
202         if (!pMsgInfo || (pMsgInfo && pMsgInfo->msgId <= 0)) {
203                 MSG_DEBUG("Invalid message id");
204                 return MSG_ERR_INVALID_MESSAGE_ID;
205         }
206
207 /***  Comment below line to not save the time value after sent status (it could be used later.)
208         time_t curTime = time(NULL);
209 ***/
210         MsgDbHandler *dbHandle = getDbHandle();
211
212         char sqlQuery[MAX_QUERY_LEN+1];
213
214         memset(sqlQuery, 0x00, sizeof(sqlQuery));
215
216         MSG_DEBUG("Update Msg ID : [%d], Network Status : [%d] ", pMsgInfo->msgId, status);
217
218         /** Move Msg to SENTBOX */
219         if (status == MSG_NETWORK_SEND_SUCCESS) {
220                 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET NETWORK_STATUS = %d, FOLDER_ID = %d WHERE MSG_ID = %d;",
221                                         MSGFW_MESSAGE_TABLE_NAME, status, MSG_SENTBOX_ID, pMsgInfo->msgId);
222         } else {
223                 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET NETWORK_STATUS = %d, READ_STATUS = 0 WHERE MSG_ID = %d;",
224                                         MSGFW_MESSAGE_TABLE_NAME, status, pMsgInfo->msgId);
225         }
226
227         if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
228                 MSG_DEBUG("MsgExecQuery() : [%s]", sqlQuery);
229                 return MSG_ERR_DB_EXEC;
230         }
231
232 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
233         if (status == MSG_NETWORK_SEND_SUCCESS) {
234                 MSG_DEBUG("MsgAddPhoneLog() : folderId [%d]", pMsgInfo->folderId);
235                 MsgAddPhoneLog(pMsgInfo);
236         }
237 #endif /* MSG_CONTACTS_SERVICE_NOT_SUPPORTED */
238         MSG_END();
239
240         return MSG_SUCCESS;
241 }
242
243 #ifdef SMS_REPORT_OPERATION
244 msg_error_t SmsPluginStorage::updateMsgRef(msg_message_id_t MsgId, unsigned char MsgRef)
245 {
246         MSG_BEGIN();
247
248         MsgDbHandler *dbHandle = getDbHandle();
249
250         char sqlQuery[MAX_QUERY_LEN+1];
251
252         memset(sqlQuery, 0x00, sizeof(sqlQuery));
253
254         snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET MSG_REF = %d WHERE MSG_ID = %d;",
255                                 MSGFW_REPORT_TABLE_NAME, (int)MsgRef, MsgId);
256
257         if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
258                 MSG_DEBUG("Query Failed : [%s]", sqlQuery);
259                 return MSG_ERR_DB_EXEC;
260         }
261
262         /** Set Message Reference for updating report table */
263         tmpMsgRef = MsgRef;
264
265         MSG_DEBUG("MsgRef : %d", MsgRef);
266
267         MSG_END();
268
269         return MSG_SUCCESS;
270 }
271
272
273 msg_error_t SmsPluginStorage::updateStatusReport(unsigned char MsgRef, msg_delivery_report_status_t Status, time_t DeliveryTime)
274 {
275         MSG_BEGIN();
276
277         MSG_DEBUG("tmpMsgRef : %d", tmpMsgRef);
278
279         MsgDbHandler *dbHandle = getDbHandle();
280
281         char sqlQuery[MAX_QUERY_LEN+1];
282
283         /** Get Msg Id for Quickpanel Noti */
284         msg_message_id_t msgId = 0;
285
286         memset(sqlQuery, 0x00, sizeof(sqlQuery));
287         snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE MSG_REF = %d;",
288                                         MSGFW_REPORT_TABLE_NAME, (int)tmpMsgRef);
289
290         if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
291                 return MSG_ERR_DB_PREPARE;
292
293         if (dbHandle->stepQuery() == MSG_ERR_DB_ROW)
294                 msgId = dbHandle->columnInt(0);
295
296         dbHandle->finalizeQuery();
297
298         /** Update Status */
299         memset(sqlQuery, 0x00, sizeof(sqlQuery));
300         snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET MSG_REF = -1, DELIVERY_REPORT_STATUS = %d, DELIVERY_REPORT_TIME = %lu WHERE MSG_REF = %d;",
301                                         MSGFW_REPORT_TABLE_NAME, Status, DeliveryTime, (int)tmpMsgRef);
302
303         if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
304                 MSG_DEBUG("Query Failed : [%s]", sqlQuery);
305                 return MSG_ERR_DB_EXEC;
306         }
307
308         /** Insert Quickpanel Noti */
309         msg_error_t ret = MSG_SUCCESS;
310
311         ret = MsgInsertSmsNotiToQuickpanel(dbHandle, msgId, Status);
312
313         if (ret != MSG_SUCCESS) {
314                 MSG_DEBUG("MsgInsertSmsNotiToQuickpanel() Failed : [%d]", ret);
315                 return ret;
316         }
317
318         MSG_END();
319
320         return MSG_SUCCESS;
321 }
322 #endif
323
324 msg_error_t SmsPluginStorage::addSimMessage(MSG_MESSAGE_INFO_S *pSimMsgInfo, int *simIdList)
325 {
326         msg_error_t err = MSG_SUCCESS;
327
328         unsigned int simId = 0;
329         MsgDbHandler *dbHandle = getDbHandle();
330
331         char sqlQuery[MAX_QUERY_LEN+1];
332
333         if (simIdList) {
334                 MSG_DEBUG("simIdList exist.");
335                 for (int i = 0; i < MAX_SIM_SMS_NUM; ++i) {
336                         if (simIdList[i]) {
337                                 simId = simIdList[i] - 1;
338                                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
339                                 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d);",
340                                                 MSGFW_SIM_MSG_TABLE_NAME, simId, pSimMsgInfo->msgId);
341
342                                 MSG_DEBUG("QUERY : %s", sqlQuery);
343
344                                 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
345                                         return MSG_ERR_DB_EXEC;
346                                 }
347                         } else {
348                                 break;
349                         }
350                 }
351         }
352
353         return err;
354 }
355
356
357 msg_error_t SmsPluginStorage::insertSimMessage(int simId, int msgId)
358 {
359         MSG_BEGIN();
360
361         MsgDbHandler *dbHandle = getDbHandle();
362
363         char sqlQuery[MAX_QUERY_LEN+1];
364
365         dbHandle->beginTrans();
366
367         /** Insert Message into msg_sim table */
368         memset(sqlQuery, 0x00, sizeof(sqlQuery));
369         snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d);", MSGFW_SIM_MSG_TABLE_NAME, simId, msgId);
370         if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
371                 dbHandle->endTrans(false);
372                 return MSG_ERR_DB_EXEC;
373         }
374
375         dbHandle->endTrans(true);
376
377         return MSG_SUCCESS;
378 }
379
380
381 msg_error_t SmsPluginStorage::deleteSimMessage(int sim_idx, int simId)
382 {
383         MSG_BEGIN();
384
385         MsgDbHandler *dbHandle = getDbHandle();
386
387         char sqlQuery[MAX_QUERY_LEN+1];
388
389         dbHandle->beginTrans();
390
391         /** Delete Message from msg_sim table */
392         memset(sqlQuery, 0x00, sizeof(sqlQuery));
393         snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE SIM_ID = %d AND SIM_SLOT_ID = %d;", MSGFW_SIM_MSG_TABLE_NAME, simId, sim_idx);
394         if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
395                 dbHandle->endTrans(false);
396                 return MSG_ERR_DB_EXEC;
397         }
398
399         dbHandle->endTrans(true);
400
401         return MSG_SUCCESS;
402 }
403
404
405 msg_error_t SmsPluginStorage::checkMessage(MSG_MESSAGE_INFO_S *pMsgInfo)
406 {
407         MSG_BEGIN();
408
409         msg_error_t err = MSG_SUCCESS;
410
411         /**  Check whether storage is full or not */
412         err = checkStorageStatus(pMsgInfo);
413
414         if (err != MSG_SUCCESS) {
415                 if (pMsgInfo->msgType.classType == MSG_CLASS_0) {
416                         pMsgInfo->folderId = 0;
417                         err = MSG_SUCCESS;
418                 }
419                 else if (pMsgInfo->msgType.classType == MSG_CLASS_2 &&
420                                 (pMsgInfo->msgType.subType == MSG_NORMAL_SMS || pMsgInfo->msgType.subType == MSG_REJECT_SMS)) {
421                         err = addClass2Message(pMsgInfo);
422                 }
423                 else if (pMsgInfo->msgType.subType == MSG_NOTIFICATIONIND_MMS) {
424                         err = MSG_SUCCESS;
425                 }
426                 return err;
427         }
428
429         /**  Amend message information for type **/
430         if (pMsgInfo->msgType.subType == MSG_NORMAL_SMS || pMsgInfo->msgType.subType == MSG_REJECT_SMS) {
431                 MSG_DEBUG("Normal SMS");
432
433                 if (pMsgInfo->msgType.classType == MSG_CLASS_2) {
434                         err = addClass2Message(pMsgInfo);
435                 } else if (pMsgInfo->msgType.classType == MSG_CLASS_0) {
436                         /** Class 0 Msg should be saved in hidden folder */
437                         pMsgInfo->folderId = 0;
438                 }
439
440         } else if ((pMsgInfo->msgType.subType >= MSG_REPLACE_TYPE1_SMS) && (pMsgInfo->msgType.subType <= MSG_REPLACE_TYPE7_SMS)) {
441                 MSG_DEBUG("Replace SM Type [%d]", pMsgInfo->msgType.subType-3);
442
443                 if (pMsgInfo->msgType.classType == MSG_CLASS_2) {
444                         err = addClass2Message(pMsgInfo);
445                 } else if (pMsgInfo->msgType.classType == MSG_CLASS_0) {
446                         /** Class 0 Msg should be saved in hidden folder */
447                         pMsgInfo->folderId = 0;
448                         pMsgInfo->msgType.subType = MSG_NORMAL_SMS;
449                 }
450
451         } else if ((pMsgInfo->msgType.subType >= MSG_MWI_VOICE_SMS) && (pMsgInfo->msgType.subType <= MSG_MWI_OTHER_SMS)) {
452                 if (pMsgInfo->bStore == true) {
453                         MSG_DEBUG("MWI Message");
454
455                         if (pMsgInfo->msgType.classType == MSG_CLASS_2) {
456                                 err = addClass2Message(pMsgInfo);
457                         }
458                 }
459         } else {
460                 MSG_DEBUG("No matching type [%d]", pMsgInfo->msgType.subType);
461         }
462
463         if (err == MSG_SUCCESS) {
464                 MSG_DEBUG("Success to check message !!");
465         } else {
466                 MSG_DEBUG("fail to check message !! : [%d]", err);
467         }
468
469         return err;
470 }
471
472
473 msg_error_t SmsPluginStorage::addSmsMessage(MSG_MESSAGE_INFO_S *pMsgInfo)
474 {
475         msg_error_t err = MSG_SUCCESS;
476
477         unsigned int rowId = 0;
478         msg_thread_id_t convId = 0;
479
480         MsgDbHandler *dbHandle = getDbHandle();
481
482         dbHandle->beginTrans();
483
484         if (pMsgInfo->nAddressCnt > 0) {
485                 err = MsgStoAddAddress(dbHandle, pMsgInfo, &convId);
486
487                 if (err != MSG_SUCCESS) {
488                         dbHandle->endTrans(false);
489                         return err;
490                 }
491
492                 pMsgInfo->threadId = convId;
493         }
494
495         /**  Add Message Table */
496         rowId = MsgStoAddMessageTable(dbHandle, pMsgInfo);
497
498         if (rowId <= 0) {
499                 dbHandle->endTrans(false);
500                 return MSG_ERR_DB_ROW;
501         }
502
503         /** Update conversation table */
504         err = MsgStoUpdateConversation(dbHandle, convId);
505
506         if (err != MSG_SUCCESS) {
507                 dbHandle->endTrans(false);
508                 return err;
509         }
510
511         err = dbHandle->endTrans(true);
512         if (err != MSG_SUCCESS) {
513                 return err;
514         }
515
516         pMsgInfo->msgId = (msg_message_id_t)rowId;
517
518         MSG_END();
519
520         return MSG_SUCCESS;
521 }
522
523
524 msg_error_t SmsPluginStorage::deleteSmsMessage(msg_message_id_t msgId)
525 {
526         MSG_BEGIN();
527
528         MsgDbHandler *dbHandle = getDbHandle();
529
530         char sqlQuery[MAX_QUERY_LEN+1];
531
532          /**  Get SUB_TYPE, STORAGE_ID */
533         memset(sqlQuery, 0x00, sizeof(sqlQuery));
534         snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MAIN_TYPE, SUB_TYPE, FOLDER_ID, CONV_ID, SIM_INDEX \
535                         FROM %s WHERE MSG_ID = %d;",
536                         MSGFW_MESSAGE_TABLE_NAME, msgId);
537
538         if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
539                 return MSG_ERR_DB_PREPARE;
540
541         MSG_MESSAGE_TYPE_S msgType;
542         msg_folder_id_t folderId;
543
544         msg_thread_id_t convId;
545         msg_sim_slot_id_t simIndex;
546
547         if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
548                 msgType.mainType = dbHandle->columnInt(0);
549                 msgType.subType = dbHandle->columnInt(1);
550                 folderId = dbHandle->columnInt(2);
551                 convId = dbHandle->columnInt(3);
552                 simIndex = dbHandle->columnInt(4);
553
554                 MSG_DEBUG("Main Type:[%d] SubType:[%d] FolderId:[%d] ConversationId:[%d]", msgType.mainType, msgType.subType, folderId, convId);
555         } else {
556                 MSG_DEBUG("MsgStepQuery() Error [%s]", sqlQuery);
557                 dbHandle->finalizeQuery();
558                 return MSG_ERR_DB_STEP;
559         }
560
561         dbHandle->finalizeQuery();
562
563         dbHandle->beginTrans();
564
565         memset(sqlQuery, 0x00, sizeof(sqlQuery));
566         snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;", MSGFW_SMS_SENDOPT_TABLE_NAME, msgId);
567
568         /**  Delete SMS Send Option */
569         if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
570                 dbHandle->endTrans(false);
571                 return MSG_ERR_DB_EXEC;
572         }
573
574         if (msgType.subType == MSG_CB_SMS || msgType.subType == MSG_JAVACB_SMS) {
575                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
576                 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;", MSGFW_CB_MSG_TABLE_NAME, msgId);
577
578                 /** Delete Push Message from push table */
579                 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
580                         dbHandle->endTrans(false);
581                         return MSG_ERR_DB_EXEC;
582                 }
583         } else if (msgType.subType >= MSG_WAP_SI_SMS && msgType.subType <= MSG_WAP_CO_SMS) {
584                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
585                 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;", MSGFW_PUSH_MSG_TABLE_NAME, msgId);
586
587                 /**  Delete Push Message from push table */
588                 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
589                         dbHandle->endTrans(false);
590                         return MSG_ERR_DB_EXEC;
591                 }
592         } else if (msgType.subType == MSG_SYNCML_CP) {
593                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
594                 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;", MSGFW_SYNCML_MSG_TABLE_NAME, msgId);
595
596                 /**  Delete SyncML Message from syncML table */
597                 if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
598                         dbHandle->endTrans(false);
599                         return MSG_ERR_DB_EXEC;
600                 }
601         }
602
603         /** Delete Message from msg table */
604         memset(sqlQuery, 0x00, sizeof(sqlQuery));
605         snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;", MSGFW_MESSAGE_TABLE_NAME, msgId);
606         if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
607                 dbHandle->endTrans(false);
608                 return MSG_ERR_DB_EXEC;
609         }
610
611         /** Delete Message from msg_report table */
612         memset(sqlQuery, 0x00, sizeof(sqlQuery));
613         snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;", MSGFW_SMS_REPORT_TABLE_NAME, msgId);
614         if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
615                 dbHandle->endTrans(false);
616                 return MSG_ERR_DB_EXEC;
617         }
618
619         /** Delete Message from msg_sim table */
620         memset(sqlQuery, 0x00, sizeof(sqlQuery));
621         snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;", MSGFW_SIM_MSG_TABLE_NAME, msgId);
622         if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
623                 dbHandle->endTrans(false);
624                 return MSG_ERR_DB_EXEC;
625         }
626
627         /**  Clear Conversation table */
628         if (MsgStoClearConversationTable(dbHandle) != MSG_SUCCESS) {
629                 dbHandle->endTrans(false);
630                 return MSG_ERR_DB_EXEC;
631         }
632
633         /**  Update conversation table.*/
634         if (MsgStoUpdateConversation(dbHandle, convId) != MSG_SUCCESS) {
635                 dbHandle->endTrans(false);
636                 return MSG_ERR_STORAGE_ERROR;
637         }
638
639         dbHandle->endTrans(true);
640
641         signed char folder_id = (signed char)folderId;
642         if (folder_id == MSG_INBOX_ID) {
643                 msgType.classType = MSG_CLASS_NONE;
644
645                 /**  Set memory status in SIM */
646                 if (MsgStoCheckMsgCntFull(dbHandle, &msgType, folderId) == MSG_SUCCESS) {
647                         MSG_DEBUG("Set Memory Status");
648                         SmsPlgSetMemoryStatus(simIndex, MSG_SUCCESS);
649                 }
650         }
651
652         MsgRefreshAllNotification(true, false, MSG_ACTIVE_NOTI_TYPE_NONE);
653
654         return MSG_SUCCESS;
655 }
656
657
658 msg_error_t SmsPluginStorage::addClass2Message(MSG_MESSAGE_INFO_S *pMsgInfo)
659 {
660         MSG_BEGIN();
661
662         msg_error_t err = MSG_SUCCESS;
663         bool bSimSst = true;
664
665         char keyName[MAX_VCONFKEY_NAME_LEN];
666         memset(keyName, 0x00, sizeof(keyName));
667         snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_SERVICE_TABLE, pMsgInfo->sim_idx);
668
669         if (MsgSettingGetBool(keyName, &bSimSst) != MSG_SUCCESS) {
670                 MSG_ERR("MsgSettingGetBool [%s] failed", keyName);
671         }
672
673         if (bSimSst == false) {
674                 return MSG_ERR_SIM_STORAGE_FULL;
675         }
676         pthread_t thd;
677         memset(&msgInfo, 0, sizeof(MSG_MESSAGE_INFO_S));
678         memset(&addrInfo, 0, sizeof(MSG_ADDRESS_INFO_S));
679         memcpy(&msgInfo, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
680         memcpy(&addrInfo, pMsgInfo->addressList, sizeof(MSG_ADDRESS_INFO_S));
681         msgInfo.addressList = &addrInfo;
682
683         if (pthread_create(&thd, NULL, &class2_thread, (void *)&msgInfo) < 0)
684                 MSG_DEBUG("pthread_create() error");
685
686         pthread_detach(thd);
687
688 #if 0
689         err = SmsPluginSimMsg::instance()->saveClass2Message(pMsgInfo);
690
691
692         if (err == MSG_SUCCESS) {
693                 MSG_DEBUG("Success to saveClass2Message.");
694         } else {
695                 MSG_DEBUG("Fail to saveClass2Message : [%d]", err);
696         }
697 #endif
698
699         MSG_END();
700
701         return err;
702 }
703
704 void* SmsPluginStorage::class2_thread(void *data)
705 {
706         MSG_BEGIN();
707
708         msg_error_t err = MSG_SUCCESS;
709         MSG_MESSAGE_INFO_S *pMsgInfo = (MSG_MESSAGE_INFO_S *)data;
710
711         err = SmsPluginSimMsg::instance()->saveClass2Message(pMsgInfo);
712         if (err == MSG_SUCCESS) {
713                 MSG_DEBUG("Success to saveClass2Message.");
714         } else {
715                 MSG_ERR("Fail to saveClass2Message : [%d]", err);
716         }
717
718         MSG_END();
719         return (void *)err;
720 }
721
722
723 msg_error_t SmsPluginStorage::getReplaceSimMsg(const MSG_MESSAGE_INFO_S *pMsg, int *pMsgId, int *pSimId)
724 {
725         MSG_BEGIN();
726
727         MsgDbHandler *dbHandle = getDbHandle();
728
729         char sqlQuery[MAX_QUERY_LEN+1];
730         msg_thread_id_t convId = 0;
731         msg_message_id_t msgId = 0;
732
733         dbHandle->beginTrans();
734
735         if (MsgExistAddress(dbHandle, pMsg, &convId) == true) {
736                 MSG_DEBUG("Address Info. exists [%d]", convId);
737
738                 /**  Find Replace Type Msg : Same Replace Type, Same Origin Address, Same Storage ID */
739                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
740                 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s \
741                                                         WHERE CONV_ID = %d AND SUB_TYPE = %d AND STORAGE_ID = %d \
742                                                         ORDER BY DISPLAY_TIME ASC;",
743                                 MSGFW_MESSAGE_TABLE_NAME, (int)convId, pMsg->msgType.subType, MSG_STORAGE_SIM);
744
745                 MSG_DEBUG("Query=[%s]", sqlQuery);
746                 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
747                         dbHandle->endTrans(false);
748                         return MSG_ERR_DB_PREPARE;
749                 }
750
751                 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
752                         *pMsgId = dbHandle->columnInt(0);
753                 } else {
754                         dbHandle->finalizeQuery();
755                         dbHandle->endTrans(false);
756                         return MSG_ERR_DB_STEP;
757                 }
758
759                 dbHandle->finalizeQuery();
760
761         } else {
762                 dbHandle->endTrans(false);
763                 return MSG_ERR_DB_NORECORD;
764         }
765
766         memset(sqlQuery, 0x00, sizeof(sqlQuery));
767
768         snprintf(sqlQuery, sizeof(sqlQuery), "SELECT SIM_ID FROM %s \
769                         WHERE MSG_ID = %d;",
770                         MSGFW_SIM_MSG_TABLE_NAME, *pMsgId);
771
772         if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
773                 dbHandle->endTrans(false);
774                 return MSG_ERR_DB_PREPARE;
775         }
776
777         if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
778                 *pSimId = dbHandle->columnInt(0);
779         } else {
780                 dbHandle->finalizeQuery();
781                 dbHandle->endTrans(false);
782                 return MSG_ERR_DB_STEP;
783         }
784
785         MSG_DEBUG("Replace Msg Id=[%d], Sim Id=[%d]", *pMsgId, *pSimId);
786
787         dbHandle->finalizeQuery();
788
789         dbHandle->endTrans(true);
790
791         MSG_END();
792
793         return msgId;
794 }
795
796 msg_error_t SmsPluginStorage::addSmsSendOption(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo)
797 {
798         MSG_BEGIN();
799
800         msg_error_t err = MSG_SUCCESS;
801
802         if (pSendOptInfo->bSetting == false) {
803                 MsgSettingGetBool(SMS_SEND_DELIVERY_REPORT, &pSendOptInfo->bDeliverReq);
804                 MsgSettingGetBool(SMS_SEND_REPLY_PATH, &pSendOptInfo->option.smsSendOptInfo.bReplyPath);
805
806                 MsgSettingGetBool(MSG_KEEP_COPY, &pSendOptInfo->bKeepCopy);
807         }
808
809         MsgDbHandler *dbHandle = getDbHandle();
810
811         char sqlQuery[MAX_QUERY_LEN+1];
812
813         dbHandle->beginTrans();
814
815         memset(sqlQuery, 0x00, sizeof(sqlQuery));
816         snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d, %d, %d);",
817                         MSGFW_SMS_SENDOPT_TABLE_NAME, pMsg->msgId, pSendOptInfo->bDeliverReq,
818                         pSendOptInfo->bKeepCopy, pSendOptInfo->option.smsSendOptInfo.bReplyPath, pMsg->encodeType);
819
820         MSG_DEBUG("Query = [%s]", sqlQuery);
821
822         if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
823                 MSG_ERR("execQuery() is failed");
824                 dbHandle->endTrans(false);
825                 return MSG_ERR_DB_EXEC;
826         }
827
828         dbHandle->endTrans(true);
829
830         MSG_END();
831
832         return err;
833 }
834
835
836 msg_error_t SmsPluginStorage::checkStorageStatus(MSG_MESSAGE_INFO_S *pMsgInfo)
837 {
838         msg_error_t err = MSG_SUCCESS;
839
840         MsgDbHandler *dbHandle = getDbHandle();
841
842         err = MsgStoCheckMsgCntFull(dbHandle, &(pMsgInfo->msgType), pMsgInfo->folderId);
843
844         if (err != MSG_SUCCESS) {
845                 if (err == MSG_ERR_MESSAGE_COUNT_FULL) {
846                         bool bAutoErase = false;
847
848                         MsgSettingGetBool(MSG_AUTO_ERASE, &bAutoErase);
849
850                         MSG_DEBUG("bAutoErase: %d", bAutoErase);
851
852                         if (bAutoErase == true) {
853                                 msg_message_id_t msgId;
854
855                                 /** Find the oldest message's msgId */
856                                 err = MsgStoGetOldestMessage(dbHandle, pMsgInfo, &msgId);
857
858                                 if (err != MSG_SUCCESS)
859                                         return err;
860
861                                 /** Delete the corresponding message. */
862                                 err = deleteSmsMessage(msgId);
863                         }
864                 }
865
866                 return err;
867         }
868
869         return err;
870 }
871
872
873 #if 0
874
875 msg_error_t SmsPluginStorage::isReceivedCBMessage(SMS_CBMSG_PAGE_S CbPage)
876 {
877         msg_error_t err = MSG_SUCCESS;
878
879         int rowCnt = 0;
880
881         MsgDbHandler *dbHandle = getDbHandle();
882
883         char sqlQuery[MAX_QUERY_LEN+1] = {0, };
884
885         memset(sqlQuery, 0x00, sizeof(sqlQuery));
886
887         snprintf(sqlQuery, sizeof(sqlQuery), "SELECT * FROM %s WHERE GEO_SCOPE = %d AND MSG_CODE = %d AND MESSAGE_ID = %d AND UPDATE_NUM = %d",
888                         MSGFW_RECEIVED_CB_MSG_TABLE_NAME, CbPage.pageHeader.serialNum.geoScope,
889                         CbPage.pageHeader.serialNum.msgCode, CbPage.pageHeader.msgId, CbPage.pageHeader.serialNum.updateNum);
890
891         err = dbHandle->getTable(sqlQuery, &rowCnt, NULL);
892         MSG_DEBUG("rowCnt: %d", rowCnt);
893
894         dbHandle->freeTable();
895         return err;
896 }
897
898 msg_error_t SmsPluginStorage::insertReceivedCBMessage(SMS_CBMSG_PAGE_S CbPage)
899 {
900         msg_error_t err = MSG_SUCCESS;
901
902         unsigned int rowId = 0;
903
904         MsgDbHandler *dbHandle = getDbHandle();
905
906         char sqlQuery[MAX_QUERY_LEN+1];
907
908         err = dbHandle->getRowId(MSGFW_RECEIVED_CB_MSG_TABLE_NAME, &rowId);
909
910         if (err != MSG_SUCCESS)
911                 return err;
912
913         /* Add Folder */
914         memset(sqlQuery, 0x00, sizeof(sqlQuery));
915         snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d, %d, %d);",
916                         MSGFW_RECEIVED_CB_MSG_TABLE_NAME, rowId, CbPage.pageHeader.serialNum.geoScope,
917                         CbPage.pageHeader.serialNum.msgCode, CbPage.pageHeader.msgId, CbPage.pageHeader.serialNum.updateNum);
918
919         if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS)
920                 return MSG_ERR_DB_EXEC;
921
922         return MSG_SUCCESS;
923 }
924
925 #endif
926
927 msg_error_t SmsPluginStorage::getRegisteredPushEvent(char* pPushHeader, int *count, char *application_id, int app_id_len, char *content_type, int content_type_len)
928 {
929         msg_error_t err = MSG_SUCCESS;
930
931         int rowCnt = 0, index = 0;
932
933         MsgDbHandler *dbHandle = getDbHandle();
934
935         char sqlQuery[MAX_QUERY_LEN+1] = {0, };
936
937         memset(sqlQuery, 0x00, sizeof(sqlQuery));
938
939         snprintf(sqlQuery, sizeof(sqlQuery), "SELECT CONTENT_TYPE, APP_ID, APPCODE FROM %s", MSGFW_PUSH_CONFIG_TABLE_NAME);
940
941         err = dbHandle->getTable(sqlQuery, &rowCnt, &index);
942         MSG_DEBUG("rowCnt: %d", rowCnt);
943
944         if (err != MSG_SUCCESS) {
945                 dbHandle->freeTable();
946
947                 if (err == MSG_ERR_DB_NORECORD)
948                         return MSG_SUCCESS;
949                 else
950                         return err;
951         }
952
953         char contentType[MAX_WAPPUSH_CONTENT_TYPE_LEN + 1] = {0, };
954         char appId[MAX_WAPPUSH_ID_LEN + 1] = {0, };
955         int appcode = 0, default_appcode = 0;
956         bool found = false;
957         char *_content_type = NULL, *_app_id = NULL;
958         *count = 0;
959
960
961         for (int i = 0; i < rowCnt; i++) {
962                 memset(contentType, 0, MAX_WAPPUSH_CONTENT_TYPE_LEN);
963                 memset(appId, 0, MAX_WAPPUSH_ID_LEN);
964
965                 dbHandle->getColumnToString(index++, MAX_WAPPUSH_CONTENT_TYPE_LEN + 1, contentType);
966                 dbHandle->getColumnToString(index++, MAX_WAPPUSH_ID_LEN + 1, appId);
967                 appcode = dbHandle->getColumnToInt(index++);
968
969                 /* MSG_DEBUG("content_type: %s, app_id: %s", content_type, app_id); */
970                 _content_type = strcasestr(pPushHeader, contentType);
971                 if (_content_type) {
972                         _app_id = strcasestr(pPushHeader, appId);
973                         if (appcode)
974                                 default_appcode = appcode;
975
976                         if (_app_id) {
977                                 PUSH_APPLICATION_INFO_S pInfo = {0, };
978                                 pInfo.appcode = appcode;
979                                 MSG_SEC_DEBUG("appcode: %d, app_id: %s", pInfo.appcode, appId);
980                                 snprintf(application_id, app_id_len, "%s", appId);
981                                 snprintf(content_type, content_type_len, "%s", contentType);
982                                 pushAppInfoList.push_back(pInfo);
983                                 (*count)++;
984                                 found = true;
985                         }
986                 }
987         }
988
989         if (!found && default_appcode != SMS_WAP_APPLICATION_LBS) {
990                 /* perform default action. */
991                 PUSH_APPLICATION_INFO_S pInfo = {0, };
992                 pInfo.appcode = default_appcode;
993                 memset(appId, 0, MAX_WAPPUSH_ID_LEN + 1);
994                 snprintf(application_id, app_id_len, "%s", appId);
995                 snprintf(content_type, content_type_len, "%s", contentType);
996                 pushAppInfoList.push_back(pInfo);
997                 *count = 1;
998         }
999         dbHandle->freeTable();
1000
1001         return err;
1002 }
1003
1004
1005 msg_error_t SmsPluginStorage::getnthPushEvent(int index, int *appcode)
1006 {
1007         msg_error_t err = MSG_SUCCESS;
1008         if ((unsigned int)index > pushAppInfoList.size() - 1)
1009                 return MSG_ERR_INVALID_PARAMETER;
1010
1011         std::list<PUSH_APPLICATION_INFO_S>::iterator it = pushAppInfoList.begin();
1012         int count = 0;
1013         for (; it != pushAppInfoList.end(); it++) {
1014                 if (index == count) {
1015                         *appcode = it->appcode;
1016                         break;
1017                 }
1018                 count++;
1019         }
1020
1021         return err;
1022 }
1023
1024
1025 msg_error_t SmsPluginStorage::releasePushEvent()
1026 {
1027         msg_error_t err = MSG_SUCCESS;
1028         std::list<PUSH_APPLICATION_INFO_S>::iterator it = pushAppInfoList.begin();
1029
1030         for (; it != pushAppInfoList.end(); it++)
1031                 it = pushAppInfoList.erase(it);
1032
1033         return err;
1034 }
1035
1036
1037 msg_error_t SmsPluginStorage::updateSmsMessage(MSG_MESSAGE_INFO_S *pMsgInfo)
1038 {
1039         MSG_BEGIN();
1040         MsgDbHandler *dbHandle = getDbHandle();
1041         char sqlQuery[MAX_QUERY_LEN+1] = {0, };
1042         msg_thread_id_t convId = 0;
1043
1044         dbHandle->beginTrans();
1045
1046         if (pMsgInfo->nAddressCnt > 0) {
1047                 pMsgInfo->threadId = 0;
1048                 msg_error_t err = MsgStoAddAddress(dbHandle, pMsgInfo, &convId);
1049
1050                 if (err != MSG_SUCCESS) {
1051                         dbHandle->endTrans(false);
1052                         return err;
1053                 }
1054         }
1055
1056         int fileSize = 0;
1057
1058         char *pFileData = NULL;
1059         unique_ptr<char*, void(*)(char**)> buf(&pFileData, unique_ptr_deleter);
1060
1061         /* Get File Data */
1062         if (pMsgInfo->bTextSms == false) {
1063                 if (MsgOpenAndReadFile(pMsgInfo->msgData, &pFileData, &fileSize) == false) {
1064                         dbHandle->endTrans(false);
1065                         return MSG_ERR_STORAGE_ERROR;
1066                 }
1067         }
1068
1069         snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET CONV_ID = %d, FOLDER_ID = %d, STORAGE_ID = %d, MAIN_TYPE = %d, SUB_TYPE = %d, \
1070                         DISPLAY_TIME = %lu, DATA_SIZE = %d, NETWORK_STATUS = %d, READ_STATUS = %d, PROTECTED = %d, PRIORITY = %d, MSG_DIRECTION = %d, \
1071                         BACKUP = %d, SUBJECT = ?, MSG_TEXT = ?, SIM_INDEX = %d \
1072                         WHERE MSG_ID = %d;",
1073                         MSGFW_MESSAGE_TABLE_NAME, convId, pMsgInfo->folderId, pMsgInfo->storageId, pMsgInfo->msgType.mainType, pMsgInfo->msgType.subType, pMsgInfo->displayTime, pMsgInfo->dataSize,
1074                         pMsgInfo->networkStatus, pMsgInfo->bRead, pMsgInfo->bProtected, pMsgInfo->priority, pMsgInfo->direction, pMsgInfo->bBackup, pMsgInfo->sim_idx, pMsgInfo->msgId);
1075
1076         if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
1077                 dbHandle->endTrans(false);
1078                 return MSG_ERR_DB_EXEC;
1079         }
1080
1081         dbHandle->bindText(pMsgInfo->subject, 1);
1082
1083         if (pMsgInfo->bTextSms == false)
1084                 dbHandle->bindText(pFileData, 2);
1085         else
1086                 dbHandle->bindText(pMsgInfo->msgText, 2);
1087
1088         MSG_DEBUG("%s", sqlQuery);
1089
1090         if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
1091                 dbHandle->finalizeQuery();
1092                 dbHandle->endTrans(false);
1093                 return MSG_ERR_DB_EXEC;
1094         }
1095
1096         dbHandle->finalizeQuery();
1097         dbHandle->endTrans(true);
1098
1099         MSG_END();
1100         return MSG_SUCCESS;
1101 }