RemoteMessagePort::SendMessage() returns E_SYSTEM when the socket receiver buffer...
[platform/framework/native/appfw.git] / src / app / FApp_SqlDataControlImpl.cpp
index 35d0e38..4c95acd 100644 (file)
@@ -1,5 +1,4 @@
 //
-// Open Service Platform
 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
 //
 // Licensed under the Apache License, Version 2.0 (the License);
  */
 
 #include <typeinfo>
-#include <new>
+#include <unique_ptr.h>
 
 #include <appsvc/appsvc.h>
 
 #include <FBaseInteger.h>
 #include <FBaseString.h>
 #include <FBaseLongLong.h>
+#include <FBaseColLinkedList.h>
 #include <FBaseColIList.h>
 #include <FBaseColIMap.h>
 #include <FBaseColIMapEnumerator.h>
+#include <FBaseRtIEventArg.h>
+#include <FBaseSysLog.h>
 #include <FIoFile.h>
+#include <FAppApp.h>
 #include <FAppSqlDataControl.h>
 #include <FAppISqlDataControlResponseListener.h>
 
-#include <FBaseSysLog.h>
+#include <FBase_StringConverter.h>
 #include <FIo_DataControlResultSetEnumerator.h>
 
 #include "FApp_AppControlManager.h"
-#include "FApp_AppManagerProxy.h"
 #include "FApp_SqlDataControlImpl.h"
 #include "FApp_AppArg.h"
+#include "FApp_DataControlManager.h"
+#include "FAppPkg_PackageManagerImpl.h"
+
+#define DATACONTROL_PROTOCOL_VER_2_1_0_2 // ver_2.1.0.2
+#define DATACONTROL_PROTOCOL_VER_2_1_0_3 // ver_2.1.0.3
+
+using namespace std;
 
 using namespace Tizen::Base;
 using namespace Tizen::Base::Collection;
-using namespace Tizen::App;
+using namespace Tizen::Base::Runtime;
 using namespace Tizen::Io;
+using namespace Tizen::App;
+using namespace Tizen::App::Package;
 
 namespace Tizen { namespace App
 {
 
+static const int MAX_REQUEST_COUNT = 128;
+static const int REQUEST_THRESHOLD = 100;
+static const int _MAX_ARGUMENT_SIZE = 16384; // 16KB
+static const int _MAX_REQUEST_ARGUMENT_SIZE = 1048576; // 1MB
+//static const char* _DATACONTROL_REQUEST_DIR = "/tmp/osp/DataControlRequest/\0";
+static const char* _DATACONTROL_REQUEST_DIR = "/tmp/osp/data-control/request/\0";
+
+class _SqlDataControlEventArg
+       : public IEventArg
+{
+public:
+               _SqlDataControlEventArg(_DataControlRequestType requestType, RequestId reqId, String providerId, String dataId,
+                               _DataControlResultSetEnumerator* pResultSetEnum, long long insertRowId, bool providerResult, String* pErrorMsg)
+                       : __requestType(requestType)
+                       , __reqId(reqId)
+                       , __providerId(providerId)
+                       , __dataId(dataId)
+                       , __pResultSetEnum(pResultSetEnum)
+                       , __insertRowId(insertRowId)
+                       , __providerResult(providerResult)
+                       , __pErrorMsg(pErrorMsg)
+               {
+               }
+               ~_SqlDataControlEventArg(void)
+               {
+                       delete __pResultSetEnum;
+                       delete __pErrorMsg;
+               }
+
+               _DataControlRequestType __requestType;
+               RequestId __reqId;
+               String __providerId;
+               String __dataId;
+               _DataControlResultSetEnumerator* __pResultSetEnum;
+               long long __insertRowId;
+               bool __providerResult;
+               String* __pErrorMsg;
+};
+
+class _SqlDataControlEvent
+       : public Event
+{
+protected:
+       virtual void FireImpl(IEventListener& listener, const IEventArg& arg);
+};
+
+void
+_SqlDataControlEvent::FireImpl(IEventListener& listener, const IEventArg& arg)
+{
+       const _SqlDataControlEventArg* pArg = dynamic_cast<const _SqlDataControlEventArg*>(&arg);
+       if (pArg != null)
+       {
+               ISqlDataControlResponseListener* pListener = dynamic_cast<ISqlDataControlResponseListener*> (&listener);
+               if (pListener != null)
+               {
+                       switch (pArg->__requestType)
+                       {
+                       case _DATACONTROL_REQUEST_TYPE_SQL_QUERY:
+                               pListener->OnSqlDataControlSelectResponseReceived(pArg->__reqId, pArg->__providerId, pArg->__dataId,
+                                               *(pArg->__pResultSetEnum), pArg->__providerResult, pArg->__pErrorMsg);
+                               break;
+                       case _DATACONTROL_REQUEST_TYPE_SQL_INSERT:
+                               pListener->OnSqlDataControlInsertResponseReceived(pArg->__reqId, pArg->__providerId, pArg->__dataId,
+                                                pArg->__insertRowId, pArg->__providerResult, pArg->__pErrorMsg);
+                               break;
+                       case _DATACONTROL_REQUEST_TYPE_SQL_UPDATE:
+                               pListener->OnSqlDataControlUpdateResponseReceived(pArg->__reqId, pArg->__providerId, pArg->__dataId,
+                                               pArg->__providerResult, pArg->__pErrorMsg);
+                               break;
+                       case _DATACONTROL_REQUEST_TYPE_SQL_DELETE:
+                               pListener->OnSqlDataControlDeleteResponseReceived(pArg->__reqId, pArg->__providerId, pArg->__dataId,
+                                               pArg->__providerResult, pArg->__pErrorMsg);
+                               break;
+                       default:
+                               break;
+                       }
+               }
+       }
+}
+
 // private
 _SqlDataControlImpl::_SqlDataControlImpl(void)
-       : __appId(L"")
-       , __providerId(L"")
-       , __access(_DATACONTROL_ACCESS_UNDEFINED)
-       , __pListener(null)
+       : __access(_DATACONTROL_ACCESS_UNDEFINED)
+       , __pPreviousListener(null)
+       , __pSqlDataControlEvent(null)
 {
 }
 
 _SqlDataControlImpl::~_SqlDataControlImpl(void)
 {
+       delete __pSqlDataControlEvent;
+
+       _DataControlManager* pDcMgr = _DataControlManager::GetInstance();
+
+       IEnumerator* pEnum = __pRequestList->GetEnumeratorN();
+       while (pEnum->MoveNext() == E_SUCCESS)
+       {
+               Integer* pReqId = dynamic_cast< Integer* >(pEnum->GetCurrent());
+               if (pReqId != null)
+               {
+                       pDcMgr->RemoveRequestInfo(*pReqId);
+               }
+       }
+       delete __pRequestList;
 }
 
 _SqlDataControlImpl*
@@ -77,29 +181,73 @@ _SqlDataControlImpl::GetInstance(const SqlDataControl& dc)
 }
 
 result
-_SqlDataControlImpl::StartSqlDataControl(int type, const IList* pDataList, ISqlDataControlResponseListener* pListener,
-                                                                                int* pReq)
+_SqlDataControlImpl::StartSqlDataControl(int type, const IList* pDataList, int* pReq)
 {
+       Integer* pReqId = null;
+       _DataControlRequestInfo* pReqInfo = null;
        result r = E_SUCCESS;
 
+       int req = -1;
+       _DataControlManager* pDcMgr = _DataControlManager::GetInstance();
+
+       // Check the request count of DataControl operation
+       int count = pDcMgr->GetRequestCount();
+       SysLog(NID_APP, "Current launch request count: %d", count);
+
+       if (count > REQUEST_THRESHOLD)
+       {
+               _AppManagerImpl* pImpl = _AppManagerImpl::GetInstance();
+
+               // Clear the request queue if the provider is terminated
+               if (!pImpl->IsRunning(__appId))
+               {
+                       SysLog(NID_APP, "The request queue is cleared due to the invalid provider.");
+
+                       pDcMgr->RemoveAllRequests();
+               }
+       }
+
+       SysTryReturnResult(NID_APP, count < MAX_REQUEST_COUNT, E_MAX_EXCEEDED, "The number of requests has exceeded the maximum limit.");
+
        _AppArg* pArg = new (std::nothrow) _AppArg;  // XXX: pArg will be released in _AppManagerImpl::LaunchApp().
        SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "insufficient memory");
 
        pArg->Construct(*this, static_cast <_DataControlRequestType>(type), pDataList);
 
        _AppControlManager* pAppManagerImpl = _AppControlManager::GetInstance();
-       int req = -1;
 
-       if (__pListener)
+       if (__pSqlDataControlEvent)
        {
-               SysLog(NID_APP, "listener address: 0x%x", (void*) __pListener);
-
                // reqId is system-wide id because the bundle is system-wide.
-               _AppControlManager::_RequestGuard reqObj = _AppControlManager::_RequestGuard(*pAppManagerImpl, pArg, SqlDataControlCallback, __pListener, -1);
+#if 0
+               _AppControlManager::_RequestGuard reqObj = _AppControlManager::_RequestGuard(*pAppManagerImpl, pArg, SqlDataControlCallback, __pSqlDataControlEvent, -1);
                req = reqObj.GetRequestNumber();
+#else
+               _AppControlManager::_RequestGuard reqObj = _AppControlManager::_RequestGuard(*pAppManagerImpl, pArg, SqlDataControlCallback, pDcMgr, -1);
+               req = reqObj.GetRequestNumber();
+#endif
+               pReqId = new (std::nothrow) Integer(req);
+               SysTryCatch(NID_APP, pReqId != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
+                               "[E_OUT_OF_MEMORY] The memory is insufficient");
+
+               pReqInfo = new (std::nothrow) _DataControlRequestInfo(__pSqlDataControlEvent);
+               SysTryCatch(NID_APP, pReqInfo != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
+                               "[E_OUT_OF_MEMORY] The memory is insufficient");
+               pReqInfo->SetSqlDataControlImpl(this);
+
+               r = pDcMgr->AddRequestInfo(pReqId, pReqInfo);
+               SysTryCatch(NID_APP, !IsFailed(r), r = E_SYSTEM, E_SYSTEM, "[%s] Failed to add request info", GetErrorMessage(r));
 
                r = pAppManagerImpl->LaunchApp(__appId, pArg, req);
-               SysTryCatch(NID_APP, r == E_SUCCESS, reqObj.Invalidate(), r, "[%s] Propagating.", GetErrorMessage(r));
+               if (IsFailed(r))
+               {
+                       SysPropagate(NID_APP, r);
+                       reqObj.Invalidate();
+                       pDcMgr->RemoveRequestInfo(*pReqId);
+                       return r;
+               }
+
+               __pRequestList->Add(new (std::nothrow) Integer(req));
 
                if (pReq)
                {
@@ -109,21 +257,16 @@ _SqlDataControlImpl::StartSqlDataControl(int type, const IList* pDataList, ISqlD
        else
        {
                r = pAppManagerImpl->LaunchApp(__appId, pArg);
+               SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
+               delete pArg;
        }
 
-       {
-               // registers to server
-               _IAppManager* pMgr = _AppManagerProxy::GetService();
-
-               // actually register, not launch
-               if (pMgr)
-               {
-                       pMgr->LaunchApplication(__appId, null, req);
-               }
-       }
+       return E_SUCCESS;
 
 CATCH:
-
+       delete pArg;
+       delete pReqId;
+       delete pReqInfo;
        return r;
 }
 
@@ -139,12 +282,13 @@ _SqlDataControlImpl::Select(const String& dataId, const IList* pColumnList, cons
        const String* pColumn = null;
        int id = 0;
        result r = E_SUCCESS;
-       SysLog(NID_APP, "[DC_CALLER] SqlDataControl SELECT");
+       SysLog(NID_APP, "[DC_CALLER_SEND] SqlDataControl SELECT");
 
        ArrayList* pArgList = new ArrayList();
        pArgList->Construct();
 
        pArgList->Add(*(new String(dataId))); // list(0): data ID
+       long long argSize = dataId.GetLength() * sizeof(wchar_t);
 
        if (pColumnList != null)
        {
@@ -153,7 +297,7 @@ _SqlDataControlImpl::Select(const String& dataId, const IList* pColumnList, cons
                                "[E_INVALID_ARG] The specified pColumnList parameter is empty.");
 
                pArgList->Add(*(new String(Integer::ToString(columnCount)))); // list(1): selected column count
-               SysLog(NID_APP, "[DC_CALLER] selected column count: %d", columnCount);
+               SysLog(NID_APP, "[DC_CALLER_SEND] selected column count: %d", columnCount);
 
                int i = 0;
                while (i < columnCount) // list(2): column list
@@ -163,7 +307,8 @@ _SqlDataControlImpl::Select(const String& dataId, const IList* pColumnList, cons
                                        "[E_INVALID_ARG] The object is not String class.");
 
                        pArgList->Add(*(new String(*pColumn)));
-                       SysLog(NID_APP, "[DC_CALLER] column[%d]: %ls", i, pColumn->GetPointer());
+                       argSize += pColumn->GetLength() * sizeof(wchar_t);
+                       SysLog(NID_APP, "[DC_CALLER_SEND] column[%d]: %ls", i, pColumn->GetPointer());
                        i++;
                }
        }
@@ -175,7 +320,8 @@ _SqlDataControlImpl::Select(const String& dataId, const IList* pColumnList, cons
        if (pWhere != null)     // list(3): where clause
        {
                pArgList->Add(*(new String(*pWhere)));
-               SysLog(NID_APP, "[DC_CALLER] pWhere: %ls", pWhere->GetPointer());
+               argSize += pWhere->GetLength() * sizeof(wchar_t);
+               SysLog(NID_APP, "[DC_CALLER_SEND] pWhere: %ls", pWhere->GetPointer());
        }
        else
        {
@@ -185,22 +331,26 @@ _SqlDataControlImpl::Select(const String& dataId, const IList* pColumnList, cons
        if (pOrder != null)     // list(4): order clause
        {
                pArgList->Add(*(new String(*pOrder)));
-               SysLog(NID_APP, "[DC_CALLER] pOrder: %ls", pOrder->GetPointer());
+               argSize += pOrder->GetLength() * sizeof(wchar_t);
+               SysLog(NID_APP, "[DC_CALLER_SEND] pOrder: %ls", pOrder->GetPointer());
        }
        else
        {
                pArgList->Add(*(new String(L"NULL")));
        }
+       SysTryCatch(NID_APP, argSize <= _MAX_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED,
+                       "[E_MAX_EXCEEDED] The size of sending argument (%lld) exceeds the maximum limit.", argSize);
 
        pArgList->Add(*(new String(Integer::ToString(pageNo)))); // list(5): page number
 
        pArgList->Add(*(new String(Integer::ToString(countPerPage)))); // list(6): count per page
 
-       r = StartSqlDataControl(_DATACONTROL_REQUEST_TYPE_SQL_QUERY, pArgList, __pListener, &id);
+       r = StartSqlDataControl(_DATACONTROL_REQUEST_TYPE_SQL_QUERY, pArgList, &id);
+       SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
 
        reqId = static_cast< RequestId >(id);
 
-       SysLog(NID_APP, "[DC_CALLER] dataId: %ls, pColumnList: 0x%x, pWhere: 0x%x, pOrder: 0x%x, reqId: %d, pageNo: %d, countPerPage: %d",
+       SysLog(NID_APP, "[DC_CALLER_SEND] data: %ls, pColumnList: 0x%x, pWhere: 0x%x, pOrder: 0x%x, req: %d, pageNo: %d, countPerPage: %d",
                        dataId.GetPointer(), pColumnList, pWhere, pOrder, reqId, pageNo, countPerPage);
 
        // fall through
@@ -212,25 +362,26 @@ CATCH:
 }
 
 result
-_SqlDataControlImpl::SqlDataControlCallback(void* data, _AppArg* pArg, _AppArg* pResArg, service_result_e res, int prop)
+_SqlDataControlImpl::SqlDataControlCallback(void* data, _AppArg* pArg, _AppArg* pResArg, service_result_e res, int prop, int option)
 {
        ArrayList* pResultList = null;
-       ArrayList* pOrigList = null;
        String* pResult = null;
-       String* pRequestType = null;
-       String* pReqId = null;
        String* pProviderId = null;
        String* pDataId = null;
+       String* pErrorMessage = null;
        String* pErrorMsg = null;
        String* pTmpPath = null;
        String* pInsertRowId = null;
        _DataControlResultSetEnumerator* pResultSetEnum = null;
        int requestType = 0;
        int reqId = 0;
+       int launchReqId = 0;
        int providerRes = 0;
        bool providerResult = true;
-       bundle* origBundle = null;
+       //bundle* origBundle = null;
        bundle* resBundle = null;
+       _SqlDataControlEventArg* pEventArg = null;
+       const char* p = null;
        result r = E_SUCCESS;
 
        SysTryReturnResult(NID_APP, pResArg != null, E_INVALID_ARG, "Empty result callback.");
@@ -239,53 +390,68 @@ _SqlDataControlImpl::SqlDataControlCallback(void* data, _AppArg* pArg, _AppArg*
        resBundle = pResArg->GetBundle();
        if (resBundle)
        {
-               ISqlDataControlResponseListener* pListener = static_cast< ISqlDataControlResponseListener* >(data);
-
-               if (pListener != null && typeid(pListener) == typeid(ISqlDataControlResponseListener*))
+               p = appsvc_get_data(resBundle, OSP_K_REQUEST_ID);
+               SysTryCatch(NID_APP, p, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
+               reqId = atoi(p);
+               Integer key(reqId);
+
+               _DataControlManager* pDcMgr = static_cast< _DataControlManager* >(data);
+               _DataControlRequestInfo* pReqInfo = pDcMgr->GetRequestInfo(key);
+               if (pReqInfo == null)
                {
-                       const char* p = null;
+                       SysLog(NID_APP, "No request info of reqId %d", reqId);
+                       return E_SUCCESS;
+               }
+
+               _SqlDataControlEvent* pSqlDataControlEvent = dynamic_cast< _SqlDataControlEvent* >(pReqInfo->GetEvent());
+               SysTryCatch(NID_APP, pSqlDataControlEvent != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request info");
 
+               pDcMgr->RemoveRequestInfo(key);
+
+               _SqlDataControlImpl* pDcImpl = pReqInfo->GetSqlDataControlImpl();
+               SysTryCatch(NID_APP, pDcImpl != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request info");
+               pDcImpl->__pRequestList->Remove(key);
+
+               // Remove the request from the queue
+               SysLog(NID_APP, "Remove the request, req: %d", reqId);
+
+               if (pSqlDataControlEvent != null && typeid(pSqlDataControlEvent) == typeid(_SqlDataControlEvent*))
+               {
                        // result list
                        pResultList = _AppArg::GetListN(resBundle, OSP_K_ARG);
                        SysTryCatch(NID_APP, pResultList, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid result");
 
-                       pResult = dynamic_cast <String*>(pResultList->GetAt(0));
+                       pResult = dynamic_cast <String*>(pResultList->GetAt(0)); // result list[0]
                        SysTryCatch(NID_APP, pResult, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid result");
                        Integer::Parse(*pResult, providerRes);
                        providerResult = static_cast< bool >(providerRes);
 
-                       pErrorMsg = dynamic_cast< String* >(pResultList->GetAt(1));
-                       SysTryCatch(NID_APP, pErrorMsg, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid result");
-
-                       origBundle = pArg->GetBundle();
+                       pErrorMessage = dynamic_cast< String* >(pResultList->GetAt(1)); // result list[1]
+                       SysTryCatch(NID_APP, pErrorMessage, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid result");
+                       pErrorMsg = new (std::nothrow) String(*pErrorMessage);
+                       SysTryCatch(NID_APP, pErrorMsg, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
+                                       "[E_OUT_OF_MEMORY] The memory is insufficient.");
 
                        // request info
-                       p = appsvc_get_data(origBundle, OSP_K_DATACONTROL_REQUEST_TYPE);
-                       SysTryCatch(NID_APP, p, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
-                       pRequestType = new (std::nothrow) String(p);
-                       SysTryCatch(NID_APP, pRequestType, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
-                                       "[E_OUT_OF_MEMORY] The memory was insufficient.");
-                       Integer::Parse(*pRequestType, requestType);
+                       //origBundle = pArg->GetBundle();
 
-                       p = appsvc_get_data(origBundle, OSP_K_REQUEST_ID);
+                       p = appsvc_get_data(resBundle, OSP_K_DATACONTROL_REQUEST_TYPE);
                        SysTryCatch(NID_APP, p, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
-                       pReqId = new (std::nothrow) String(p);
-                       SysTryCatch(NID_APP, pReqId, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
-                                       "[E_OUT_OF_MEMORY] The memory was insufficient.");
-                       Integer::Parse(*pReqId, reqId);
+                       requestType = atoi(p);
 
-                       p = appsvc_get_data(origBundle, OSP_K_DATACONTROL_PROVIDER);
+                       p = appsvc_get_data(resBundle, OSP_K_DATACONTROL_PROVIDER);
                        SysTryCatch(NID_APP, p, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
                        pProviderId = new (std::nothrow) String(p);
                        SysTryCatch(NID_APP, pProviderId, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
-                                       "[E_OUT_OF_MEMORY] The memory was insufficient.");
+                                       "[E_OUT_OF_MEMORY] The memory is insufficient.");
 
-                       pOrigList = _AppArg::GetListN(origBundle, OSP_K_ARG);
-                       SysTryCatch(NID_APP, pOrigList, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
-                       pDataId = dynamic_cast <String*>(pOrigList->GetAt(0));
-                       SysTryCatch(NID_APP, pDataId, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
+                       p = appsvc_get_data(resBundle, OSP_K_DATACONTROL_DATA);
+                       SysTryCatch(NID_APP, p, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
+                       pDataId = new (std::nothrow) String(p);
+                       SysTryCatch(NID_APP, pDataId, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
+                                       "[E_OUT_OF_MEMORY] The memory is insufficient.");
 
-                       SysLog(NID_APP, "providerResult: %ld, requestType: %d, reqId: %d, providerId: %ls, dataId: %ls, errorMsg: %ls ",
+                       SysSecureLog(NID_APP, "[DC_CALLER_RECV] provider result: %ld, requestType: %d, req: %d, provider: %ls, data: %ls, errorMsg: %ls ",
                                        providerRes, requestType, reqId, pProviderId->GetPointer(), pDataId->GetPointer(), pErrorMsg->GetPointer());
 
                        switch (static_cast <_DataControlRequestType>(requestType))
@@ -294,22 +460,29 @@ _SqlDataControlImpl::SqlDataControlCallback(void* data, _AppArg* pArg, _AppArg*
                        {
                                pResultSetEnum = new (std::nothrow) _DataControlResultSetEnumerator;
                                SysTryCatch(NID_APP, pResultSetEnum, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
-                                               "[E_OUT_OF_MEMORY] The memory was insufficient.");
+                                               "[E_OUT_OF_MEMORY] The memory is insufficient.");
 
                                if (providerResult == true)
                                {
                                        pTmpPath = dynamic_cast< String* >(pResultList->GetAt(2)); // result list[2]
-                                       SysTryCatch(NID_APP, pTmpPath, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid result");
+                                       if (pTmpPath == null)
+                                       {
+                                               SysLogException(NID_APP, E_SYSTEM, "[E_SYSTEM] invalid result");
+                                               delete pResultSetEnum;
+                                               goto CATCH;
+                                       }
 
-                                       SysLog(NID_APP, "tempPath: %ls", pTmpPath->GetPointer());
+                                       SysLog(NID_APP, "[DC_CALLER_RECV] tempPath: %ls", pTmpPath->GetPointer());
                                        if (pTmpPath->Equals(L"NoResultSet", true) == false) // Result set exists
                                        {
                                                pResultSetEnum->SetPath(*pTmpPath);
                                        }
                                }
 
-                               pListener->OnSqlDataControlSelectResponseReceived(static_cast <RequestId>(reqId), *pProviderId,
-                                               *pDataId, *pResultSetEnum, providerResult, pErrorMsg);
+                               pEventArg = new (std::nothrow) _SqlDataControlEventArg(_DATACONTROL_REQUEST_TYPE_SQL_QUERY, static_cast <RequestId>(reqId),
+                                               *pProviderId, *pDataId, pResultSetEnum, -1, providerResult, pErrorMsg);
+                               SysTryCatch(NID_APP, pEventArg != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+                               pSqlDataControlEvent->Fire(*pEventArg);
 
                                if (pTmpPath)
                                {
@@ -317,7 +490,6 @@ _SqlDataControlImpl::SqlDataControlCallback(void* data, _AppArg* pArg, _AppArg*
                                        SysTryLog(NID_APP, !IsFailed(r), "Failed to remove temp file for result set: %ls", pTmpPath->GetPointer());
                                }
 
-                               delete pResultSetEnum;
                                break;
                        }
                        case _DATACONTROL_REQUEST_TYPE_SQL_INSERT:
@@ -331,130 +503,208 @@ _SqlDataControlImpl::SqlDataControlCallback(void* data, _AppArg* pArg, _AppArg*
                                        LongLong::Parse(*pInsertRowId, insertRowId);
                                }
 
-                               pListener->OnSqlDataControlInsertResponseReceived(static_cast <RequestId>(reqId), *pProviderId,
-                                               *pDataId, insertRowId, providerResult, pErrorMsg);
+                               pEventArg = new (std::nothrow) _SqlDataControlEventArg(_DATACONTROL_REQUEST_TYPE_SQL_INSERT, static_cast <RequestId>(reqId),
+                                               *pProviderId, *pDataId, null, insertRowId, providerResult, pErrorMsg);
+                               SysTryCatch(NID_APP, pEventArg != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+                               pSqlDataControlEvent->Fire(*pEventArg);
                                break;
                        }
                        case _DATACONTROL_REQUEST_TYPE_SQL_UPDATE:
-                               pListener->OnSqlDataControlUpdateResponseReceived(static_cast <RequestId>(reqId), *pProviderId,
-                                               *pDataId, providerResult, pErrorMsg);
+                       {
+                               pEventArg = new (std::nothrow) _SqlDataControlEventArg(_DATACONTROL_REQUEST_TYPE_SQL_UPDATE, static_cast <RequestId>(reqId),
+                                               *pProviderId, *pDataId, null, -1, providerResult, pErrorMsg);
+                               SysTryCatch(NID_APP, pEventArg != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+                               pSqlDataControlEvent->Fire(*pEventArg);
                                break;
+                       }
                        case _DATACONTROL_REQUEST_TYPE_SQL_DELETE:
-                               pListener->OnSqlDataControlDeleteResponseReceived(static_cast <RequestId>(reqId), *pProviderId,
-                                               *pDataId, providerResult, pErrorMsg);
+                       {
+                               pEventArg = new (std::nothrow) _SqlDataControlEventArg(_DATACONTROL_REQUEST_TYPE_SQL_DELETE, static_cast <RequestId>(reqId),
+                                               *pProviderId, *pDataId, null, -1, providerResult, pErrorMsg);
+                               SysTryCatch(NID_APP, pEventArg != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+                               pSqlDataControlEvent->Fire(*pEventArg);
                                break;
+                       }
                        default:
                                break;
                        }
 
                        pResultList->RemoveAll(true);
                        delete pResultList;
-
-                       pOrigList->RemoveAll(true);
-                       delete pOrigList;
-
-                       delete pRequestType;
-                       delete pReqId;
                        delete pProviderId;
                }
        }
 
+       p = appsvc_get_data(pArg->GetBundle(), OSP_K_REQUEST_ID);
+       SysTryCatch(NID_APP, p, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
+       launchReqId = atoi(p);
+
        return E_SUCCESS;
 
 CATCH:
-       delete pResultSetEnum;
-
        if (pResultList)
        {
                pResultList->RemoveAll(true);
                delete pResultList;
        }
-
-       if (pOrigList)
-       {
-               pOrigList->RemoveAll(true);
-               delete pOrigList;
-       }
-
-       delete pRequestType;
-       delete pReqId;
        delete pProviderId;
 
        return r;
 }
 
 result
-_SqlDataControlImpl::Insert(const Tizen::Base::String& dataId, const Tizen::Base::Collection::IMap& insertMap,
-               RequestId& reqId)
+_SqlDataControlImpl::Insert(const String& dataId, const IMap& insertMap, RequestId& reqId)
 {
        SysTryReturnResult(NID_APP, (__access & _DATACONTROL_ACCESS_WRITE) > 0, E_ILLEGAL_ACCESS,
                        "The INSERT query is not permitted by DataControl provider.");
 
        int columnCount = 0;
        int id = 0;
-       int i = 0;
+       int uniqueId = -1;
+       File request;
+       IMapEnumerator* pMapEnum = null;
+       _PackageManagerImpl* pPkgMgrImpl = null;
+       unique_ptr< String > pProviderAppId(null);
        result r = E_SUCCESS;
-       SysLog(NID_APP, "[DC_CALLER] SqlDataControl INSERT");
+       SysLog(NID_APP, "[DC_CALLER_SEND] SqlDataControl INSERT");
 
        columnCount = insertMap.GetCount();
        SysTryReturnResult(NID_APP, columnCount > 0, E_INVALID_ARG, "The specified insertMap parameter is empty.");
 
-       ArrayList* pArgList = new ArrayList();
+       ArrayList* pArgList = new (std::nothrow) ArrayList();
        pArgList->Construct();
 
-       pArgList->Add(*(new String(dataId))); // list(0): data ID
+       pArgList->Add(new (std::nothrow) String(dataId)); // list[0]: data ID
+       long long argSize = dataId.GetLength() * sizeof(wchar_t);
+
+       pArgList->Add(new (std::nothrow) String(Integer::ToString(columnCount))); // list[1]: inserted column count
+       SysLog(NID_APP, "[DC_CALLER_SEND] inserted column count: %d", columnCount);
+
+#ifdef DATACONTROL_PROTOCOL_VER_2_1_0_2
+       String tmpPath(_DATACONTROL_REQUEST_DIR);
+       tmpPath.Append(App::GetInstance()->GetAppId());
+
+       _DataControlManager* pDcMgr = _DataControlManager::GetInstance();
+       SysTryCatch(NID_APP, pDcMgr, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed to get _DataControlManager instance.");
+       uniqueId = pDcMgr->GetUniqueId();
+
+       tmpPath.Append(uniqueId);
+       SysLog(NID_APP, "[DC_CALLER_SEND] request: %ls", tmpPath.GetPointer());
+
+       r = request.Construct(tmpPath, L"w+", true);
+       SysTryCatch(NID_APP, !IsFailed(r), r = E_SYSTEM, E_SYSTEM, "[%s] Failed to create request (%ls).",
+                       GetErrorMessage(r), tmpPath.GetPointer());
 
-       pArgList->Add(*(new String(Integer::ToString(columnCount)))); // list(1): inserted column count
-       SysLog(NID_APP, "[DC_CALLER] inserted column count: %d", columnCount);
+       pArgList->Add(new (std::nothrow) String(tmpPath)); // list[2]: path 
+#endif
 
-       IMapEnumerator* pMapEnum = const_cast< IMap* >(&insertMap)->GetMapEnumeratorN();
-       while (pMapEnum->MoveNext() == E_SUCCESS) // list(2): column-value pairs
+       pMapEnum = const_cast< IMap* >(&insertMap)->GetMapEnumeratorN();
+       while (pMapEnum->MoveNext() == E_SUCCESS) // list: column-value pairs
        {
+#ifdef DATACONTROL_PROTOCOL_VER_2_1_0_2
+               int length = 0;
+               String* pColumn = null;
+               String* pValue = null;
+               unique_ptr< char[] > pData(null);
+
+               pColumn = dynamic_cast< String* >(pMapEnum->GetKey());
+               SysTryCatch(NID_APP, pColumn != null, r = E_INVALID_ARG, E_INVALID_ARG,
+                               "[E_INVALID_ARG] The object is not String class.");
+
+               pData.reset(_StringConverter::CopyToCharArrayN(*pColumn));
+               SysTryCatch(NID_APP, pData != null, r = GetLastResult(), GetLastResult(), "[%s] Invalid request value",
+                               GetErrorMessage(GetLastResult()));
+
+               length = strlen(pData.get());
+               r = request.Write(&length, sizeof(int)); // data length
+               SysTryCatch(NID_APP, !IsFailed(r), , E_SYSTEM, "[%s] Failed to send request.", GetErrorMessage(r));
+
+               r = request.Write(pData.get(), length); // data
+               SysTryCatch(NID_APP, !IsFailed(r), , E_SYSTEM, "[%s] Failed to send request.", GetErrorMessage(r));
+
+               pValue = dynamic_cast< String* >(pMapEnum->GetValue());
+               SysTryCatch(NID_APP, pValue != null, r = E_INVALID_ARG, E_INVALID_ARG,
+                               "[E_INVALID_ARG] The object is not String class.");
+
+               pData.reset(_StringConverter::CopyToCharArrayN(*pValue));
+               SysTryCatch(NID_APP, pData != null, r = GetLastResult(), GetLastResult(), "[%s] Invalid request value",
+                               GetErrorMessage(GetLastResult()));
+
+               length = strlen(pData.get());
+               r = request.Write(&length, sizeof(int)); // data length
+               SysTryCatch(NID_APP, !IsFailed(r), , E_SYSTEM, "[%s] Failed to send request.", GetErrorMessage(r));
+
+               r = request.Write(pData.get(), length); // data
+               SysTryCatch(NID_APP, !IsFailed(r), , E_SYSTEM, "[%s] Failed to send request.", GetErrorMessage(r));
+
+               argSize += pColumn->GetLength() * sizeof(wchar_t);
+               argSize += pValue->GetLength() * sizeof(wchar_t);
+#else
                String* pColumn = dynamic_cast< String* >(pMapEnum->GetKey());
                SysTryCatch(NID_APP, pColumn != null, r = E_INVALID_ARG, E_INVALID_ARG,
                                "[E_INVALID_ARG] The object is not String class.");
 
                pArgList->Add(*(new String(*pColumn)));
-               SysLog(NID_APP, "[DC_CALLER] pColumn[%d]: %ls", i, pColumn->GetPointer());
+               SysLog(NID_APP, "[DC_CALLER_SEND] pColumn[%d]: %ls", i, pColumn->GetPointer());
 
                String* pValue = dynamic_cast< String* >(pMapEnum->GetValue());
                SysTryCatch(NID_APP, pValue != null, r = E_INVALID_ARG, E_INVALID_ARG,
                                "[E_INVALID_ARG] The object is not String class.");
 
                pArgList->Add(*(new String(*pValue)));
-               SysLog(NID_APP, "[DC_CALLER] pValue[%d]: %ls", i, pValue->GetPointer());
+               SysLog(NID_APP, "[DC_CALLER_SEND] pValue[%d]: %ls", i, pValue->GetPointer());
 
+               argSize += pColumn->GetLength() * sizeof(wchar_t);
+               argSize += pValue->GetLength() * sizeof(wchar_t);
                i++;
+#endif
        }
-
-       r = StartSqlDataControl(_DATACONTROL_REQUEST_TYPE_SQL_INSERT, pArgList, __pListener, &id);
+       SysTryCatch(NID_APP, argSize <= _MAX_REQUEST_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED,
+                       "[E_MAX_EXCEEDED] The size of sending argument (%lld) exceeds the maximum limit.", argSize);
+
+#ifdef DATACONTROL_PROTOCOL_VER_2_1_0_2
+       request.Flush();
+#endif
+#ifdef DATACONTROL_PROTOCOL_VER_2_1_0_3
+       pPkgMgrImpl = _PackageManagerImpl::GetInstance();
+       pProviderAppId.reset(pPkgMgrImpl->GetAppIdOfDataControlN(this->__providerId.GetPointer()));
+       SysTryCatch(NID_APP, pProviderAppId != null, r = E_SYSTEM, E_SYSTEM,
+                       "[E_SYSTEM] The method cannot proceed due to a severe system error.");
+       r = pDcMgr->AllowAccess(*(pProviderAppId.get()));
+       SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
+#endif
+
+       r = StartSqlDataControl(_DATACONTROL_REQUEST_TYPE_SQL_INSERT, pArgList, &id);
+       SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
 
        reqId = static_cast< RequestId >(id);
 
-       SysLog(NID_APP, "[DC_CALLER] dataId: %ls, insertMap: 0x%x, reqId: %d", dataId.GetPointer(), &insertMap, reqId);
+       SysLog(NID_APP, "[DC_CALLER_SEND] data: %ls, insertMap: 0x%x, req: %d", dataId.GetPointer(), &insertMap, reqId);
 
        // fall through
 CATCH:
        pArgList->RemoveAll(true);
        delete pArgList;
-
        delete pMapEnum;
 
        return r;
 }
 
 result
-_SqlDataControlImpl::Update(const Tizen::Base::String& dataId, const Tizen::Base::Collection::IMap& updateMap,
-                       const Tizen::Base::String* pWhere, RequestId& reqId)
+_SqlDataControlImpl::Update(const String& dataId, const IMap& updateMap, const String* pWhere, RequestId& reqId)
 {
        SysTryReturnResult(NID_APP, (__access & _DATACONTROL_ACCESS_WRITE) > 0, E_ILLEGAL_ACCESS,
                        "The UPDATE query is not permitted by DataControl provider.");
 
        int columnCount = 0;
        int id = 0;
-       int i = 0;
+       int uniqueId = -1;
+       File request;
+       IMapEnumerator* pMapEnum = null;
+       _PackageManagerImpl* pPkgMgrImpl = null;
+       unique_ptr< String > pProviderAppId(null);
        result r = E_SUCCESS;
-       SysLog(NID_APP, "[DC_CALLER] SqlDataControl UPDATE");
+       SysLog(NID_APP, "[DC_CALLER_SEND] SqlDataControl UPDATE");
 
        columnCount = updateMap.GetCount();
        SysTryReturnResult(NID_APP, columnCount > 0, E_INVALID_ARG, "The specified insertMap parameter is empty.");
@@ -462,89 +712,173 @@ _SqlDataControlImpl::Update(const Tizen::Base::String& dataId, const Tizen::Base
        ArrayList* pArgList = new ArrayList();
        pArgList->Construct();
 
-       pArgList->Add(*(new String(dataId))); // list(0): data ID
+       pArgList->Add(new (std::nothrow) String(dataId)); // list[0]: data ID
+       long long argSize = dataId.GetLength() * sizeof(wchar_t);
+
+       pArgList->Add(new (std::nothrow) String(Integer::ToString(columnCount))); // list[1]: updated column count
+       SysLog(NID_APP, "[DC_CALLER_SEND] updated column count: %d", columnCount);
+
+#ifdef DATACONTROL_PROTOCOL_VER_2_1_0_2
+       String tmpPath(_DATACONTROL_REQUEST_DIR);
+       tmpPath.Append(App::GetInstance()->GetAppId());
+
+       _DataControlManager* pDcMgr = _DataControlManager::GetInstance();
+       SysTryCatch(NID_APP, pDcMgr, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed to get _DataControlManager instance.");
+       uniqueId = pDcMgr->GetUniqueId();
 
-       pArgList->Add(*(new String(Integer::ToString(columnCount)))); // list(1): updated column count
-       SysLog(NID_APP, "[DC_CALLER] updated column count: %d", columnCount);
+       tmpPath.Append(uniqueId);
+       SysLog(NID_APP, "[DC_CALLER_SEND] request: %ls", tmpPath.GetPointer());
 
-       IMapEnumerator* pMapEnum = const_cast< IMap* >(&updateMap)->GetMapEnumeratorN();
-       while (pMapEnum->MoveNext() == E_SUCCESS) // list(2): column-value pairs
+       r = request.Construct(tmpPath, L"w+", true);
+       SysTryCatch(NID_APP, !IsFailed(r), r = E_SYSTEM, E_SYSTEM, "[%s] Failed to create request (%ls).",
+                       GetErrorMessage(r), tmpPath.GetPointer());
+
+       pArgList->Add(new (std::nothrow) String(tmpPath)); // list[2]: path 
+#endif
+
+       pMapEnum = const_cast< IMap* >(&updateMap)->GetMapEnumeratorN();
+       while (pMapEnum->MoveNext() == E_SUCCESS) // list: column-value pairs
        {
+#ifdef DATACONTROL_PROTOCOL_VER_2_1_0_2
+               int length = 0;
+               String* pColumn = null;
+               String* pValue = null;
+               unique_ptr< char[] > pData(null);
+
+               pColumn = dynamic_cast< String* >(pMapEnum->GetKey());
+               SysTryCatch(NID_APP, pColumn != null, r = E_INVALID_ARG, E_INVALID_ARG,
+                               "[E_INVALID_ARG] The object is not String class.");
+
+               pData.reset(_StringConverter::CopyToCharArrayN(*pColumn));
+               SysTryCatch(NID_APP, pData != null, r = GetLastResult(), GetLastResult(), "[%s] Invalid request value",
+                               GetErrorMessage(GetLastResult()));
+
+               length = strlen(pData.get());
+               r = request.Write(&length, sizeof(int)); // data length
+               SysTryCatch(NID_APP, !IsFailed(r), , E_SYSTEM, "[%s] Failed to send request.", GetErrorMessage(r));
+
+               r = request.Write(pData.get(), length); // data
+               SysTryCatch(NID_APP, !IsFailed(r), , E_SYSTEM, "[%s] Failed to send request.", GetErrorMessage(r));
+
+               pValue = dynamic_cast< String* >(pMapEnum->GetValue());
+               SysTryCatch(NID_APP, pValue != null, r = E_INVALID_ARG, E_INVALID_ARG,
+                               "[E_INVALID_ARG] The object is not String class.");
+
+               pData.reset(_StringConverter::CopyToCharArrayN(*pValue));
+               SysTryCatch(NID_APP, pData != null, r = GetLastResult(), GetLastResult(), "[%s] Invalid request value",
+                               GetErrorMessage(GetLastResult()));
+
+               length = strlen(pData.get());
+               r = request.Write(&length, sizeof(int)); // data length
+               SysTryCatch(NID_APP, !IsFailed(r), , E_SYSTEM, "[%s] Failed to send request.", GetErrorMessage(r));
+
+               r = request.Write(pData.get(), length); // data
+               SysTryCatch(NID_APP, !IsFailed(r), , E_SYSTEM, "[%s] Failed to send request.", GetErrorMessage(r));
+
+               argSize += pColumn->GetLength() * sizeof(wchar_t);
+               argSize += pValue->GetLength() * sizeof(wchar_t);
+#else
                String* pColumn = dynamic_cast< String* >(pMapEnum->GetKey());
                SysTryCatch(NID_APP, pColumn != null, r = E_INVALID_ARG, E_INVALID_ARG,
                                "[E_INVALID_ARG] The object is not String class.");
 
                pArgList->Add(*(new String(*pColumn)));
-               SysLog(NID_APP, "[DC_CALLER] pColumn[%d]: %ls", i, pColumn->GetPointer());
+               SysLog(NID_APP, "[DC_CALLER_SEND] pColumn[%d]: %ls", i, pColumn->GetPointer());
 
                String* pValue = dynamic_cast< String* >(pMapEnum->GetValue());
                SysTryCatch(NID_APP, pValue != null, r = E_INVALID_ARG, E_INVALID_ARG,
                                "[E_INVALID_ARG] The object is not String class.");
 
                pArgList->Add(*(new String(*pValue)));
-               SysLog(NID_APP, "[DC_CALLER] pValue[%d]: %ls", i, pValue->GetPointer());
+               SysLog(NID_APP, "[DC_CALLER_SEND] pValue[%d]: %ls", i, pValue->GetPointer());
 
+               argSize += pColumn->GetLength() * sizeof(wchar_t);
+               argSize += pValue->GetLength() * sizeof(wchar_t);
                i++;
+#endif
        }
 
-       if (pWhere != null)     // list(3): where clause
+#ifdef DATACONTROL_PROTOCOL_VER_2_1_0_2
+       request.Flush();
+#endif
+
+       if (pWhere != null)     // list: where clause
        {
-               pArgList->Add(*(new String(*pWhere)));
-               SysLog(NID_APP, "[DC_CALLER] pWhere: %ls", pWhere->GetPointer());
+               pArgList->Add(new (std::nothrow) String(*pWhere));
+               argSize += pWhere->GetLength() * sizeof(wchar_t);
+               SysLog(NID_APP, "[DC_CALLER_SEND] pWhere: %ls", pWhere->GetPointer());
        }
        else
        {
-               pArgList->Add(*(new String(L"NULL")));
+               pArgList->Add(new (std::nothrow) String(L"NULL"));
        }
+       SysTryCatch(NID_APP, argSize <= _MAX_REQUEST_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED,
+                       "[E_MAX_EXCEEDED] The size of sending argument (%lld) exceeds the maximum limit.", argSize);
+
+#ifdef DATACONTROL_PROTOCOL_VER_2_1_0_3
+       pPkgMgrImpl = _PackageManagerImpl::GetInstance();
+       pProviderAppId.reset(pPkgMgrImpl->GetAppIdOfDataControlN(this->__providerId.GetPointer()));
+       SysTryCatch(NID_APP, pProviderAppId != null, r = E_SYSTEM, E_SYSTEM,
+                       "[E_SYSTEM] The method cannot proceed due to a severe system error.");
+       r = pDcMgr->AllowAccess(*(pProviderAppId.get()));
+       SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
+#endif
 
-       r = StartSqlDataControl(_DATACONTROL_REQUEST_TYPE_SQL_UPDATE, pArgList, __pListener, &id);
+       r = StartSqlDataControl(_DATACONTROL_REQUEST_TYPE_SQL_UPDATE, pArgList, &id);
+       SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
 
        reqId = static_cast< RequestId >(id);
 
-       SysLog(NID_APP, "[DC_CALLER] dataId: %ls, updateMap: 0x%x, pWhere: 0x%x, reqId: %d",
+       SysLog(NID_APP, "[DC_CALLER_SEND] data: %ls, updateMap: 0x%x, pWhere: 0x%x, req: %d",
                                dataId.GetPointer(), &updateMap, pWhere, reqId);
 
        // fall through
 CATCH:
        pArgList->RemoveAll(true);
        delete pArgList;
-
        delete pMapEnum;
 
        return r;
 }
 
 result
-_SqlDataControlImpl::Delete(const Tizen::Base::String& dataId, const Tizen::Base::String* pWhere, RequestId& reqId)
+_SqlDataControlImpl::Delete(const String& dataId, const String* pWhere, RequestId& reqId)
 {
        SysTryReturnResult(NID_APP, (__access & _DATACONTROL_ACCESS_WRITE) > 0, E_ILLEGAL_ACCESS,
                        "The DELETE query is not permitted by DataControl provider.");
 
        int id = 0;
        result r = E_SUCCESS;
-       SysLog(NID_APP, "[DC_CALLER] SqlDataControl DELETE");
+       SysLog(NID_APP, "[DC_CALLER_SEND] SqlDataControl DELETE");
 
        ArrayList* pArgList = new ArrayList();
        pArgList->Construct();
 
        pArgList->Add(*(new String(dataId))); // list(0): data ID
+       long long argSize = dataId.GetLength() * sizeof(wchar_t);
 
        if (pWhere != null)     // list(1): where clause
        {
                pArgList->Add(*(new String(*pWhere)));
-               SysLog(NID_APP, "[DC_CALLER] pWhere: %ls", pWhere->GetPointer());
+               argSize += pWhere->GetLength() * sizeof(wchar_t);
+               SysLog(NID_APP, "[DC_CALLER_SEND] pWhere: %ls", pWhere->GetPointer());
        }
        else
        {
                pArgList->Add(*(new String(L"NULL")));
        }
+       SysTryCatch(NID_APP, argSize <= _MAX_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED,
+                       "[E_MAX_EXCEEDED] The size of sending argument (%lld) exceeds the maximum limit.", argSize);
 
-       r = StartSqlDataControl(_DATACONTROL_REQUEST_TYPE_SQL_DELETE, pArgList, __pListener, &id);
+       r = StartSqlDataControl(_DATACONTROL_REQUEST_TYPE_SQL_DELETE, pArgList, &id);
+       SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
 
        reqId = static_cast< RequestId >(id);
 
-       SysLog(NID_APP, "[DC_CALLER] dataId: %ls, pWhere: 0x%x, reqId: %d", dataId.GetPointer(), pWhere, reqId);
+       SysLog(NID_APP, "[DC_CALLER_SEND] data: %ls, pWhere: 0x%x, req: %d", dataId.GetPointer(), pWhere, reqId);
 
+       // fall through
+CATCH:
        pArgList->RemoveAll(true);
        delete pArgList;
 
@@ -554,7 +888,35 @@ _SqlDataControlImpl::Delete(const Tizen::Base::String& dataId, const Tizen::Base
 result
 _SqlDataControlImpl::SetSqlDataControlResponseListener(ISqlDataControlResponseListener* pListener)
 {
-       __pListener = pListener;
+       result r = E_SUCCESS;
+
+       if (__pPreviousListener != null)
+       {
+               r =  __pSqlDataControlEvent->RemoveListener(*__pPreviousListener);
+               SysTryReturnResult(NID_APP, !IsFailed(r), E_SYSTEM, "Remove listener failed.");
+                __pPreviousListener = null;
+       }
+
+       if (pListener != null)
+       {
+               r =  __pSqlDataControlEvent->AddListener(*pListener);
+               if (IsFailed(r))
+               {
+                       switch (r)
+                       {
+                       case E_OBJ_ALREADY_EXIST:
+                               return E_SUCCESS;
+                       case E_INVALID_OPERATION:
+                               SysLogException(NID_APP, E_SYSTEM, "[E_SYSTEM] The thread setting the listener is worker thread.");
+                               return E_SYSTEM;
+                       default:
+                               SysLogException(NID_APP, r, "[%s] Propagating to caller...", GetErrorMessage(r));
+                               return r;
+                       }
+               }
+       }
+
+       __pPreviousListener = pListener;
 
        return E_SUCCESS;
 }
@@ -563,15 +925,19 @@ _SqlDataControlImpl::SetSqlDataControlResponseListener(ISqlDataControlResponseLi
 SqlDataControl*
 _SqlDataControlImpl::CreateSqlDataControl(const String& appId, const String& providerId, const String& access)
 {
-       SqlDataControl* pDc = null;
-       _SqlDataControlImpl* pDcImpl = null;
-
-       pDc = new (std::nothrow) SqlDataControl;
-       SysTryReturn(NID_APP, pDc != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory was insufficient");
+       unique_ptr<SqlDataControl> pDc(new (std::nothrow) SqlDataControl);
+       SysTryReturn(NID_APP, pDc != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient");
 
-       pDcImpl = _SqlDataControlImpl::GetInstance(*pDc);
+       _SqlDataControlImpl* pDcImpl = _SqlDataControlImpl::GetInstance(*pDc);
        pDcImpl->__appId = appId;
        pDcImpl->__providerId = providerId;
+       unique_ptr<_SqlDataControlEvent> pSqlDataControlEvent(new (std::nothrow) _SqlDataControlEvent);
+       SysTryReturn(NID_IO, pSqlDataControlEvent != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+
+       pDcImpl->__pRequestList = new (std::nothrow) LinkedList(SingleObjectDeleter);
+       SysTryReturn(NID_IO, pDcImpl->__pRequestList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+
+       pDcImpl->__pSqlDataControlEvent = pSqlDataControlEvent.release();
 
        if (access == L"readonly")
        {
@@ -591,7 +957,7 @@ _SqlDataControlImpl::CreateSqlDataControl(const String& appId, const String& pro
                SysLog(NID_IO, "The accessibility of DataControl provider is invalid.");
        }
 
-       return pDc;
+       return pDc.release();
 }
 
 }} // Tizen::App