RemoteMessagePort::SendMessage() returns E_SYSTEM when the socket receiver buffer...
[platform/framework/native/appfw.git] / src / app / FApp_SqlDataControlImpl.cpp
old mode 100755 (executable)
new mode 100644 (file)
index bfeea90..4c95acd
@@ -1,5 +1,4 @@
 //
-// Open Service Platform
 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
 //
 // Licensed under the Apache License, Version 2.0 (the License);
@@ -21,7 +20,6 @@
  */
 
 #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_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::Base::Runtime;
-using namespace Tizen::App;
 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
@@ -96,7 +105,7 @@ class _SqlDataControlEvent
        : public Event
 {
 protected:
-               virtual void FireImpl(IEventListener& listener, const IEventArg& arg);
+       virtual void FireImpl(IEventListener& listener, const IEventArg& arg);
 };
 
 void
@@ -135,9 +144,7 @@ _SqlDataControlEvent::FireImpl(IEventListener& listener, const IEventArg& arg)
 
 // private
 _SqlDataControlImpl::_SqlDataControlImpl(void)
-       : __appId(L"")
-       , __providerId(L"")
-       , __access(_DATACONTROL_ACCESS_UNDEFINED)
+       : __access(_DATACONTROL_ACCESS_UNDEFINED)
        , __pPreviousListener(null)
        , __pSqlDataControlEvent(null)
 {
@@ -146,6 +153,19 @@ _SqlDataControlImpl::_SqlDataControlImpl(void)
 _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*
@@ -168,12 +188,25 @@ _SqlDataControlImpl::StartSqlDataControl(int type, const IList* pDataList, int*
        result r = E_SUCCESS;
 
        int req = -1;
-       _AppControlManager* pAppManagerImpl = _AppControlManager::GetInstance();
+       _DataControlManager* pDcMgr = _DataControlManager::GetInstance();
 
        // Check the request count of DataControl operation
-       int count = pAppManagerImpl->GetLaunchRequestCount();
+       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().
@@ -181,6 +214,8 @@ _SqlDataControlImpl::StartSqlDataControl(int type, const IList* pDataList, int*
 
        pArg->Construct(*this, static_cast <_DataControlRequestType>(type), pDataList);
 
+       _AppControlManager* pAppManagerImpl = _AppControlManager::GetInstance();
+
        if (__pSqlDataControlEvent)
        {
                // reqId is system-wide id because the bundle is system-wide.
@@ -188,7 +223,6 @@ _SqlDataControlImpl::StartSqlDataControl(int type, const IList* pDataList, int*
                _AppControlManager::_RequestGuard reqObj = _AppControlManager::_RequestGuard(*pAppManagerImpl, pArg, SqlDataControlCallback, __pSqlDataControlEvent, -1);
                req = reqObj.GetRequestNumber();
 #else
-               _DataControlManager* pDcMgr = _DataControlManager::GetInstance();
                _AppControlManager::_RequestGuard reqObj = _AppControlManager::_RequestGuard(*pAppManagerImpl, pArg, SqlDataControlCallback, pDcMgr, -1);
                req = reqObj.GetRequestNumber();
 #endif
@@ -197,8 +231,9 @@ _SqlDataControlImpl::StartSqlDataControl(int type, const IList* pDataList, int*
                                "[E_OUT_OF_MEMORY] The memory is insufficient");
 
                pReqInfo = new (std::nothrow) _DataControlRequestInfo(__pSqlDataControlEvent);
-               SysTryCatch(NID_APP, pReqId != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
+               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));
@@ -209,10 +244,11 @@ _SqlDataControlImpl::StartSqlDataControl(int type, const IList* pDataList, int*
                        SysPropagate(NID_APP, r);
                        reqObj.Invalidate();
                        pDcMgr->RemoveRequestInfo(*pReqId);
-                       delete pArg;
                        return r;
                }
 
+               __pRequestList->Add(new (std::nothrow) Integer(req));
+
                if (pReq)
                {
                        *pReq = req;
@@ -303,7 +339,7 @@ _SqlDataControlImpl::Select(const String& dataId, const IList* pColumnList, cons
                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 (%d) exceeds the maximum limit.", argSize);
+                       "[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
 
@@ -361,15 +397,24 @@ _SqlDataControlImpl::SqlDataControlCallback(void* data, _AppArg* pArg, _AppArg*
 
                _DataControlManager* pDcMgr = static_cast< _DataControlManager* >(data);
                _DataControlRequestInfo* pReqInfo = pDcMgr->GetRequestInfo(key);
-               SysTryCatch(NID_APP, pReqInfo != null, r = E_SYSTEM, E_SYSTEM,
-                               "[E_SYSTEM] Failed to get request info");
+               if (pReqInfo == 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");
+               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
@@ -406,7 +451,7 @@ _SqlDataControlImpl::SqlDataControlCallback(void* data, _AppArg* pArg, _AppArg*
                        SysTryCatch(NID_APP, pDataId, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
                                        "[E_OUT_OF_MEMORY] The memory is insufficient.");
 
-                       SysLog(NID_APP, "[DC_CALLER_RECV] provider result: %ld, requestType: %d, req: %d, provider: %ls, data: %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))
@@ -494,10 +539,6 @@ _SqlDataControlImpl::SqlDataControlCallback(void* data, _AppArg* pArg, _AppArg*
        SysTryCatch(NID_APP, p, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
        launchReqId = atoi(p);
 
-       // Remove the request count
-       SysLog(NID_APP, "Remove a launch request: req: %d", launchReqId);
-       _AppControlManager::GetInstance()->RemoveLaunchRequest(launchReqId);
-
        return E_SUCCESS;
 
 CATCH:
@@ -519,25 +560,86 @@ _SqlDataControlImpl::Insert(const String& dataId, const IMap& insertMap, Request
 
        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_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 String(Integer::ToString(columnCount)))); // list(1): inserted column count
+       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);
 
-       IMapEnumerator* pMapEnum = const_cast< IMap* >(&insertMap)->GetMapEnumeratorN();
-       while (pMapEnum->MoveNext() == E_SUCCESS) // list(2): column-value pairs
+#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 (std::nothrow) String(tmpPath)); // list[2]: path 
+#endif
+
+       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.");
@@ -555,9 +657,22 @@ _SqlDataControlImpl::Insert(const String& dataId, const IMap& insertMap, Request
                argSize += pColumn->GetLength() * sizeof(wchar_t);
                argSize += pValue->GetLength() * sizeof(wchar_t);
                i++;
+#endif
        }
-       SysTryCatch(NID_APP, argSize <= _MAX_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED,
-                       "[E_MAX_EXCEEDED] The size of sending argument (%d) exceeds the maximum limit.", argSize);
+       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));
@@ -583,7 +698,11 @@ _SqlDataControlImpl::Update(const String& dataId, const IMap& updateMap, const S
 
        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_SEND] SqlDataControl UPDATE");
 
@@ -593,15 +712,72 @@ _SqlDataControlImpl::Update(const String& dataId, const IMap& updateMap, const S
        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 String(Integer::ToString(columnCount)))); // list(1): updated column count
+       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);
 
-       IMapEnumerator* pMapEnum = const_cast< IMap* >(&updateMap)->GetMapEnumeratorN();
-       while (pMapEnum->MoveNext() == E_SUCCESS) // list(2): column-value pairs
+#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 (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.");
@@ -619,20 +795,34 @@ _SqlDataControlImpl::Update(const String& dataId, const IMap& updateMap, const S
                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)));
+               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_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED,
-                       "[E_MAX_EXCEEDED] The size of sending argument (%d) exceeds the maximum limit.", argSize);
+       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, &id);
        SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
@@ -678,7 +868,7 @@ _SqlDataControlImpl::Delete(const String& dataId, const String* pWhere, RequestI
                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 (%d) exceeds the maximum limit.", argSize);
+                       "[E_MAX_EXCEEDED] The size of sending argument (%lld) exceeds the maximum limit.", argSize);
 
        r = StartSqlDataControl(_DATACONTROL_REQUEST_TYPE_SQL_DELETE, pArgList, &id);
        SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
@@ -744,6 +934,9 @@ _SqlDataControlImpl::CreateSqlDataControl(const String& appId, const String& pro
        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")