secureswitools/swisistools/source/dbmanager/dblayer.cpp
branchRCL_3
changeset 25 7333d7932ef7
parent 0 ba25891c3a9e
child 26 8b7f4e561641
equal deleted inserted replaced
24:5cc91383ab1e 25:7333d7932ef7
     1 /*
     1 /*
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of the License "Eclipse Public License v1.0"
     5 * under the terms of the License "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    19 #include "dblayer.h"
    19 #include "dblayer.h"
    20 #include "exception.h"
    20 #include "exception.h"
    21 #include "logs.h"
    21 #include "logs.h"
    22 #include "util.h"
    22 #include "util.h"
    23 #include "symbiantypes.h"
    23 #include "symbiantypes.h"
       
    24 #include "utility.h"
    24 
    25 
    25 #include <string>
    26 #include <string>
    26 #include <vector>
    27 #include <vector>
    27 #include <algorithm>
    28 #include <algorithm>
    28 #include <sstream>
    29 #include <sstream>
    35 typedef std::vector<std::string>::iterator StringIterator;
    36 typedef std::vector<std::string>::iterator StringIterator;
    36 typedef std::vector<std::string>::const_iterator ConstStringIterator;
    37 typedef std::vector<std::string>::const_iterator ConstStringIterator;
    37 typedef std::vector<std::wstring>::const_iterator ConstWstringIterator;
    38 typedef std::vector<std::wstring>::const_iterator ConstWstringIterator;
    38 typedef std::vector<XmlDetails::TScrEnvironmentDetails>::const_iterator ScrEnvIterator;
    39 typedef std::vector<XmlDetails::TScrEnvironmentDetails>::const_iterator ScrEnvIterator;
    39 typedef std::vector<XmlDetails::TScrEnvironmentDetails::TLocalizedSoftwareTypeName>::const_iterator ScrEnvLocSwTypeNameIterator;
    40 typedef std::vector<XmlDetails::TScrEnvironmentDetails::TLocalizedSoftwareTypeName>::const_iterator ScrEnvLocSwTypeNameIterator;
       
    41 typedef std::vector<XmlDetails::TScrEnvironmentDetails::TCustomAcessList>::const_iterator ScrEnvCustomAccessIterator;
    40 typedef std::vector<XmlDetails::TScrPreProvisionDetail::TComponent>::const_iterator CompIterator;
    42 typedef std::vector<XmlDetails::TScrPreProvisionDetail::TComponent>::const_iterator CompIterator;
    41 typedef std::vector<XmlDetails::TScrPreProvisionDetail::TComponentLocalizable>::const_iterator CompLocIterator;
    43 typedef std::vector<XmlDetails::TScrPreProvisionDetail::TComponentLocalizable>::const_iterator CompLocIterator;
    42 typedef std::vector<XmlDetails::TScrPreProvisionDetail::TComponentProperty>::const_iterator CompPropIterator;
    44 typedef std::vector<XmlDetails::TScrPreProvisionDetail::TComponentProperty>::const_iterator CompPropIterator;
    43 typedef std::vector<XmlDetails::TScrPreProvisionDetail::TComponentFile>::const_iterator CompFileIter;
    45 typedef std::vector<XmlDetails::TScrPreProvisionDetail::TComponentFile>::const_iterator CompFileIter;
    44 typedef std::vector<XmlDetails::TScrPreProvisionDetail::TComponentFile::TFileProperty>::const_iterator FilePropIterator;
    46 typedef std::vector<XmlDetails::TScrPreProvisionDetail::TComponentFile::TFileProperty>::const_iterator FilePropIterator;
       
    47 typedef std::vector<XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo>::const_iterator CompApplicationRegistrationInfoIterator;
       
    48 typedef std::vector<XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TAppAttribute>::const_iterator ApplicationAttributeIterator;
       
    49 typedef std::vector<XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TDataType>::const_iterator ApplicationDataTypeIterator;
       
    50 typedef std::vector<XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TAppServiceInfo>::const_iterator ApplicationServiceInfoIterator;
       
    51 typedef std::vector<XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TAppLocalizableInfo>::const_iterator ApplicationLocalizableInfoIterator;
       
    52 typedef std::vector<XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TAppLocalizableInfo::TLocalizableAttribute>::const_iterator LocalizableAttributeIterator;
       
    53 typedef std::vector<XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TAppLocalizableInfo::TViewData>::const_iterator ViewDataIterator;
       
    54 typedef std::vector<XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TAppLocalizableInfo::TViewData::TViewDataAttributes>::const_iterator ViewDataAttributeIterator;
       
    55 typedef std::vector<XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TAppProperty>::const_iterator ApplicationPropertyIterator;
       
    56 
       
    57 
       
    58 #ifdef __LINUX__
       
    59 
       
    60 /*
       
    61 * Platform specific feature
       
    62 *
       
    63 * In WINDOWS : sizeof(wchar_t) = 2
       
    64 * In LINUX   : sizeof(wchar_t) = 4
       
    65 */
       
    66 
       
    67 static utf16WString utf32WString2utf16WString(std::wstring aParameter)
       
    68 {
       
    69 	int strLen = aParameter.length();
       
    70 	const wchar_t * source = aParameter.c_str();
       
    71 	unsigned short int* buffer = new unsigned short int[strLen + 1];
       
    72 
       
    73 	// Using a temp variable in place of buffer as ConvertUTF32toUTF16 modifies the source pointer passed.
       
    74 	unsigned short int* temp = buffer;
       
    75 
       
    76 	ConvertUTF32toUTF16(&source, source + strLen, &temp,  temp + strLen, lenientConversion);
       
    77 
       
    78 	// Appending NUL to the converted buffer.
       
    79 	*temp = 0;
       
    80 
       
    81 	utf16WString utf16Ws;
       
    82 	utf16Ws.resize(strLen);
       
    83 
       
    84 	// The built-in basic_string template class copy operation
       
    85 	// truncates when a NUL is encountered when a c_str() is
       
    86 	// used to construct the required string.
       
    87 	// So, if aParameter is any hashable string having the
       
    88 	// syntax : swtypeName + L'\0' + someId then, we will end
       
    89 	// up returning only part of the converted UTF-16 string.
       
    90 	// Hence, we resort to the explicit copy operation with
       
    91 	// two bytes at a time.
       
    92 	while( strLen-- )
       
    93 	{
       
    94 		utf16Ws[ strLen ] = buffer[ strLen ];
       
    95 	}
       
    96 
       
    97 	delete[] buffer;
       
    98 
       
    99 	return utf16Ws;
       
   100 }
       
   101 
       
   102 #else
       
   103 
       
   104 // We need not do anything for WINDOWS, since the windows wstring
       
   105 // will already be in UTF-16 encoding.
       
   106 #define utf32WString2utf16WString(aParameter) (aParameter)
       
   107 
       
   108 #endif
       
   109 
       
   110 
    45 
   111 
    46 const int KMaxDrives=26;
   112 const int KMaxDrives=26;
    47 
   113 
    48 CDbLayer::CDbLayer(const std::string& aDllPath, const std::string& aSqlDbName)
   114 CDbLayer::CDbLayer(const std::string& aDllPath, const std::string& aSqlDbName)
    49 	{
   115 	{
    85 
   151 
    86 void CDbLayer::PopulatePreProvisionDetails(const XmlDetails::TScrPreProvisionDetail& aPreProvisionDetailList)
   152 void CDbLayer::PopulatePreProvisionDetails(const XmlDetails::TScrPreProvisionDetail& aPreProvisionDetailList)
    87 	{
   153 	{
    88 	try
   154 	try
    89 		{
   155 		{
       
   156 		LOGENTER("CDbLayer::PopulatePreProvisionDetails()");
    90 		AddPreProvisionDetails(aPreProvisionDetailList);
   157 		AddPreProvisionDetails(aPreProvisionDetailList);
    91 		}
   158 		}
    92 		catch(CException& aException)
   159 		catch(CException& aException)
    93 			{
   160 			{
    94 			std::string rollbackTransaction("ROLLBACK;");
   161 			std::string rollbackTransaction("ROLLBACK;");
    95 			ExecuteStatement(rollbackTransaction);
   162 			ExecuteStatement(rollbackTransaction);
    96 			std::string errMsg = "Failed to populate SCR database with environment details.";
   163 			std::string errMsg = "Failed to populate SCR database with pre provision details.";
    97 			LOGERROR(aException.GetMessageA());
   164 			LOGERROR(aException.GetMessageA());
    98 			throw CException(errMsg,ExceptionCodes::ESqlCorrupt);
   165 			throw CException(errMsg,ExceptionCodes::ESqlCorrupt);
    99 			}
   166 			}
   100 	}
   167 	}
   101 
   168 
   108 	aStatement->Reset();
   175 	aStatement->Reset();
   109 	}
   176 	}
   110 
   177 
   111 void CDbLayer::PopulateDatabase(const std::vector<XmlDetails::TScrEnvironmentDetails>& aScrEnvDetails)
   178 void CDbLayer::PopulateDatabase(const std::vector<XmlDetails::TScrEnvironmentDetails>& aScrEnvDetails)
   112 	{
   179 	{
   113 	std::string insertSoftwareType("INSERT INTO SoftwareTypes(SoftwareTypeId,SifPluginUid,InstallerSecureId,ExecutionLayerSecureId) VALUES(?,?,?,?);");
   180 	LOGENTER("CDbLayer::PopulateDatabase()");
       
   181 	std::string insertSoftwareType("INSERT INTO SoftwareTypes(SoftwareTypeId,SifPluginUid,LauncherExecutable) VALUES(?,?,?);");
   114 	std::auto_ptr<CStatement> stmtSwType(iScrDbHandler->PrepareStatement(insertSoftwareType));
   182 	std::auto_ptr<CStatement> stmtSwType(iScrDbHandler->PrepareStatement(insertSoftwareType));
       
   183 	
       
   184 	std::string insertSTWithoutLE("INSERT INTO SoftwareTypes(SoftwareTypeId,SifPluginUid) VALUES(?,?);");
       
   185 	std::auto_ptr<CStatement> stmtSwTypeWithoutLE(iScrDbHandler->PrepareStatement(insertSTWithoutLE));
       
   186 	
       
   187     std::string insertCustomAccessList("INSERT INTO CustomAccessList(SoftwareTypeId,SecureId,AccessMode) VALUES(?,?,?);");
       
   188 	std::auto_ptr<CStatement> stmtCustomAccessList(iScrDbHandler->PrepareStatement(insertCustomAccessList));
   115 	
   189 	
   116 	std::string insertSwTypeName("INSERT INTO SoftwareTypeNames(SoftwareTypeId,Locale,Name) VALUES(?,?,?);");
   190 	std::string insertSwTypeName("INSERT INTO SoftwareTypeNames(SoftwareTypeId,Locale,Name) VALUES(?,?,?);");
   117 	std::auto_ptr<CStatement> stmtSwTypeName(iScrDbHandler->PrepareStatement(insertSwTypeName));
   191 	std::auto_ptr<CStatement> stmtSwTypeName(iScrDbHandler->PrepareStatement(insertSwTypeName));
   118 		
   192 		
   119 	std::string insertMimeType("INSERT INTO MimeTypes(SoftwareTypeId,MimeType) VALUES(?,?);");
   193 	std::string insertMimeType("INSERT INTO MimeTypes(SoftwareTypeId,MimeType) VALUES(?,?);");
   120 	std::auto_ptr<CStatement> stmtMimeType(iScrDbHandler->PrepareStatement(insertMimeType));
   194 	std::auto_ptr<CStatement> stmtMimeType(iScrDbHandler->PrepareStatement(insertMimeType));
   121 
   195 
   122 	for(ScrEnvIterator aScrEnvIterator = aScrEnvDetails.begin(); aScrEnvIterator != aScrEnvDetails.end(); ++aScrEnvIterator)
   196 	for(ScrEnvIterator aScrEnvIterator = aScrEnvDetails.begin(); aScrEnvIterator != aScrEnvDetails.end(); ++aScrEnvIterator)
   123 		{
   197 		{
   124 		unsigned int swTypeId = Util::Crc32(aScrEnvIterator->iUniqueSoftwareTypeName.c_str(),aScrEnvIterator->iUniqueSoftwareTypeName.length()*2);
   198 		// To maintain the consistency of CRC value across the platforms(WINDOWS and LINUX), we are
       
   199 		// using UTF-16 string in CRC generation.
       
   200 		utf16WString utf16Ws = utf32WString2utf16WString(aScrEnvIterator->iUniqueSoftwareTypeName);
       
   201 		unsigned int swTypeId = Util::Crc32(utf16Ws.c_str(),aScrEnvIterator->iUniqueSoftwareTypeName.length()*2);
       
   202 
       
   203 		if (!aScrEnvIterator->iLauncherExecutable.empty())
       
   204 		{
   125 		stmtSwType->BindInt(1, swTypeId);
   205 		stmtSwType->BindInt(1, swTypeId);
   126 		stmtSwType->BindInt(2, aScrEnvIterator->iSifPluginUid);
   206 		stmtSwType->BindInt(2, aScrEnvIterator->iSifPluginUid);
   127 		stmtSwType->BindInt(3, aScrEnvIterator->iInstallerSid);
   207 		stmtSwType->BindStr(3, aScrEnvIterator->iLauncherExecutable);
   128 		stmtSwType->BindInt(4, aScrEnvIterator->iExecutionLayerSid);
       
   129 		stmtSwType->ExecuteStatement();
   208 		stmtSwType->ExecuteStatement();
   130 		stmtSwType->Reset();
   209 		stmtSwType->Reset();
       
   210 		}
       
   211 		else
       
   212 		{
       
   213 		stmtSwTypeWithoutLE->BindInt(1, swTypeId);
       
   214 		stmtSwTypeWithoutLE->BindInt(2, aScrEnvIterator->iSifPluginUid);
       
   215 		stmtSwTypeWithoutLE->ExecuteStatement();
       
   216 		stmtSwTypeWithoutLE->Reset();
       
   217 		}
   131 		// First insert unique sw type name
   218 		// First insert unique sw type name
   132 		const TInt uniqueSwTypeNameLocale = 0;
   219 		const TInt uniqueSwTypeNameLocale = 0;
   133 		ExecuteSwTypeNameStatement(stmtSwTypeName, swTypeId, uniqueSwTypeNameLocale, aScrEnvIterator->iUniqueSoftwareTypeName);
   220 		ExecuteSwTypeNameStatement(stmtSwTypeName, swTypeId, uniqueSwTypeNameLocale, aScrEnvIterator->iUniqueSoftwareTypeName);
   134 		// Then, insert localized sw type names.
   221 		// Then, insert localized sw type names.
   135 		for(ScrEnvLocSwTypeNameIterator swTypeNameIter = aScrEnvIterator->iLocalizedSoftwareTypeNames.begin(); swTypeNameIter != aScrEnvIterator->iLocalizedSoftwareTypeNames.end(); ++swTypeNameIter)
   222 		for(ScrEnvLocSwTypeNameIterator swTypeNameIter = aScrEnvIterator->iLocalizedSoftwareTypeNames.begin(); swTypeNameIter != aScrEnvIterator->iLocalizedSoftwareTypeNames.end(); ++swTypeNameIter)
   136 			{
   223 			{
   137 			ExecuteSwTypeNameStatement(stmtSwTypeName, swTypeId, swTypeNameIter->iLocale, swTypeNameIter->iName);
   224 			ExecuteSwTypeNameStatement(stmtSwTypeName, swTypeId, swTypeNameIter->iLocale, swTypeNameIter->iName);
   138 			}
   225 			}
       
   226                 
       
   227         for(ScrEnvCustomAccessIterator customAccessIter = aScrEnvIterator->iCustomAcessList.begin(); customAccessIter != aScrEnvIterator->iCustomAcessList.end(); ++customAccessIter)
       
   228 			{
       
   229         	stmtCustomAccessList->BindInt(1, swTypeId);
       
   230             stmtCustomAccessList->BindInt(2, customAccessIter->iSecureId);
       
   231             stmtCustomAccessList->BindInt(3, customAccessIter->iAccessMode);
       
   232             stmtCustomAccessList->ExecuteStatement();
       
   233             stmtCustomAccessList->Reset();
       
   234 			}
       
   235 		
   139 		for(ConstWstringIterator mimeIter= aScrEnvIterator->iMIMEDetails.begin(); mimeIter != aScrEnvIterator->iMIMEDetails.end(); ++mimeIter)
   236 		for(ConstWstringIterator mimeIter= aScrEnvIterator->iMIMEDetails.begin(); mimeIter != aScrEnvIterator->iMIMEDetails.end(); ++mimeIter)
   140 			{
   237 			{
   141 			stmtMimeType->BindInt(1, swTypeId);
   238 			stmtMimeType->BindInt(1, swTypeId);
   142 			stmtMimeType->BindStr(2, *mimeIter);
   239 			stmtMimeType->BindStr(2, *mimeIter);
   143 			stmtMimeType->ExecuteStatement();
   240 			stmtMimeType->ExecuteStatement();
   144 			stmtMimeType->Reset();
   241 			stmtMimeType->Reset();
   145 			}
   242 			}
   146 		}
   243 		}
       
   244 	LOGEXIT("CDbLayer::PopulateDatabase()");
   147 
   245 
   148 	}
   246 	}
   149 
   247 
   150 void CDbLayer::AddPreProvisionDetails(const XmlDetails::TScrPreProvisionDetail& aPreProvisionDetailList)
   248 void CDbLayer::AddPreProvisionDetails(const XmlDetails::TScrPreProvisionDetail& aPreProvisionDetailList)
   151 	{
   249 	{
       
   250 	LOGENTER("CDbLayer::AddPreProvisionDetails()");
   152 	for(CompIterator aCompIterator = aPreProvisionDetailList.iComponents.begin(); aCompIterator != aPreProvisionDetailList.iComponents.end(); ++aCompIterator)
   251 	for(CompIterator aCompIterator = aPreProvisionDetailList.iComponents.begin(); aCompIterator != aPreProvisionDetailList.iComponents.end(); ++aCompIterator)
   153 		{	
   252 		{	
   154 		std::string beginTransaction("BEGIN;");
   253 		std::string beginTransaction("BEGIN;");
   155 		ExecuteStatement(beginTransaction);
   254 		ExecuteStatement(beginTransaction);
   156 		
   255 		
   157 		AddComponentDetails(*aCompIterator, aPreProvisionDetailList.iSoftwareTypeName);
   256 		int componentId = 0;
   158 		int componentId = iScrDbHandler->LastInsertedId();
   257 		if (!AddComponentDetails(*aCompIterator, aPreProvisionDetailList.iSoftwareTypeName))
   159 		AddComponentLocalizables(componentId,aCompIterator->iComponentLocalizables);
   258 			{
   160 		AddComponentProperties(componentId,aCompIterator->iComponentProperties);
   259 			componentId = iScrDbHandler->LastInsertedId();
   161 		AddComponentFiles(componentId,aCompIterator->iComponentFiles);
   260 			AddComponentLocalizables(componentId,aCompIterator->iComponentLocalizables);
   162 		AddComponentDependencies(componentId, aCompIterator->iComponentDependency, aPreProvisionDetailList.iSoftwareTypeName);
   261 			AddComponentProperties(componentId,aCompIterator->iComponentProperties);
   163 
   262 			AddComponentFiles(componentId,aCompIterator->iComponentFiles);
       
   263 			AddComponentDependencies(componentId, aCompIterator->iComponentDependency, aPreProvisionDetailList.iSoftwareTypeName);
       
   264 			}
       
   265 		AddApplicationRegistrationInfo(componentId,aCompIterator->iApplicationRegistrationInfo);
   164 		std::string commitTransaction("COMMIT;");
   266 		std::string commitTransaction("COMMIT;");
   165 		ExecuteStatement(commitTransaction);
   267 		ExecuteStatement(commitTransaction);
   166 
   268 
   167 		}
   269 		}
   168 	}
   270 	LOGEXIT("CDbLayer::AddPreProvisionDetails()");
   169 
   271 	}
   170 void CDbLayer::AddComponentDetails(const XmlDetails::TScrPreProvisionDetail::TComponent& aComponent, const std::wstring& aSoftwareTypeName)
   272 
   171 	{
   273 bool CDbLayer::AddComponentDetails(const XmlDetails::TScrPreProvisionDetail::TComponent& aComponent, const std::wstring& aSoftwareTypeName)
       
   274 	{
       
   275 	LOGENTER("CDbLayer::AddComponentDetails()");
   172 	std::string insertComponents;
   276 	std::string insertComponents;
   173 	XmlDetails::TScrPreProvisionDetail::TComponentDetails 
   277 	XmlDetails::TScrPreProvisionDetail::TComponentDetails 
   174 		componentDetail = aComponent.iComponentDetails;
   278 		componentDetail = aComponent.iComponentDetails;
   175 
   279 	if (aComponent.iComponentDetails.iIsRomApplication)
   176 	unsigned int swTypeId = Util::Crc32(aSoftwareTypeName.c_str(),aSoftwareTypeName.length()*2);
   280 		{
       
   281 		LOGINFO("Is rom app");
       
   282 		return true;
       
   283 		}
       
   284 	LOGINFO("Not rom app");
       
   285 
       
   286 	// To maintain the consistency of CRC value across the platforms(WINDOWS and LINUX), we are
       
   287 	// using UTF-16 string in CRC generation.
       
   288     utf16WString utf16Ws = utf32WString2utf16WString(aSoftwareTypeName);
       
   289 	unsigned int swTypeId = Util::Crc32(utf16Ws.c_str(),aSoftwareTypeName.length()*2);
       
   290 
       
   291 
   177 	std::wstring strGlobalId = componentDetail.iGlobalId;
   292 	std::wstring strGlobalId = componentDetail.iGlobalId;
   178 	
   293 	
   179 	if(!strGlobalId.empty())
   294 	if(!strGlobalId.empty())
   180 		{
   295 		{
   181 		insertComponents = "INSERT INTO Components(SoftwareTypeId, SoftwareTypeName, Removable, Size, ScomoState, InstalledDrives, OriginVerified, Hidden, GlobalIdHash, GlobalId, Version, InstallTime) VALUES(?,?,?,?,?,?,?,?,?,?,?,?);";
   296 		insertComponents = "INSERT INTO Components(SoftwareTypeId, SoftwareTypeName, Removable, Size, ScomoState, InstalledDrives, OriginVerified, Hidden, GlobalIdHash, GlobalId, Version, InstallTime) VALUES(?,?,?,?,?,?,?,?,?,?,?,?);";
   209 	std::wstring localTime = GetLocalTime();
   324 	std::wstring localTime = GetLocalTime();
   210 	
   325 	
   211 	if(!strGlobalId.empty())
   326 	if(!strGlobalId.empty())
   212 		{
   327 		{
   213 		std::wstring concatGlobalId = aSoftwareTypeName + L'\0' + strGlobalId;
   328 		std::wstring concatGlobalId = aSoftwareTypeName + L'\0' + strGlobalId;
   214 		unsigned int globalIdHash = Util::Crc32(concatGlobalId.c_str(),concatGlobalId.length()*2);
   329 
       
   330 		// To maintain the consistency of CRC value across the platforms(WINDOWS and LINUX), we are
       
   331 		// using UTF-16 string in CRC generation.
       
   332 		utf16WString utf16Ws = utf32WString2utf16WString(concatGlobalId);
       
   333 		unsigned int globalIdHash = Util::Crc32(utf16Ws.c_str(),concatGlobalId.length()*2);
       
   334 
   215 		stmtComponents->BindInt(9, globalIdHash);
   335 		stmtComponents->BindInt(9, globalIdHash);
   216 		stmtComponents->BindStr(10, concatGlobalId);
   336 		stmtComponents->BindStr(10, concatGlobalId);
   217 		stmtComponents->BindStr(11, version);
   337 		stmtComponents->BindStr(11, version);
   218 		stmtComponents->BindStr(12, localTime);
   338 		stmtComponents->BindStr(12, localTime);
   219 		}
   339 		}
   223 		stmtComponents->BindStr(10, localTime);
   343 		stmtComponents->BindStr(10, localTime);
   224 		}
   344 		}
   225 	
   345 	
   226 	stmtComponents->ExecuteStatement();
   346 	stmtComponents->ExecuteStatement();
   227 	stmtComponents->Reset();
   347 	stmtComponents->Reset();
   228 
   348 	LOGEXIT("CDbLayer::AddComponentDetails()");
       
   349 	return false;
   229 	}
   350 	}
   230 
   351 
   231 int CDbLayer::GetInstalledDrives(const std::vector<XmlDetails::TScrPreProvisionDetail::TComponentFile>& aComponentFiles )
   352 int CDbLayer::GetInstalledDrives(const std::vector<XmlDetails::TScrPreProvisionDetail::TComponentFile>& aComponentFiles )
   232 	{
   353 	{
   233 	int installedDrives = 0;
   354 	int installedDrives = 0;
   275 	return wstr;
   396 	return wstr;
   276 	}
   397 	}
   277 
   398 
   278 void CDbLayer::AddComponentLocalizables( int aComponentId, const std::vector<XmlDetails::TScrPreProvisionDetail::TComponentLocalizable>& aComponentLocalizable)
   399 void CDbLayer::AddComponentLocalizables( int aComponentId, const std::vector<XmlDetails::TScrPreProvisionDetail::TComponentLocalizable>& aComponentLocalizable)
   279 	{
   400 	{
       
   401 	LOGENTER("CDbLayer::AddComponentLocalizables()");
   280 	std::string insertComponentLocalizable("INSERT INTO ComponentLocalizables(ComponentId,Locale,Name,Vendor) VALUES(?,?,?,?);");
   402 	std::string insertComponentLocalizable("INSERT INTO ComponentLocalizables(ComponentId,Locale,Name,Vendor) VALUES(?,?,?,?);");
   281 	std::auto_ptr<CStatement> stmtComponentLocalizable(iScrDbHandler->PrepareStatement(insertComponentLocalizable));
   403 	std::auto_ptr<CStatement> stmtComponentLocalizable(iScrDbHandler->PrepareStatement(insertComponentLocalizable));
   282 
   404 
   283 	for(CompLocIterator compLocIter = aComponentLocalizable.begin(); compLocIter != aComponentLocalizable.end() ; ++compLocIter )
   405 	for(CompLocIterator compLocIter = aComponentLocalizable.begin(); compLocIter != aComponentLocalizable.end() ; ++compLocIter )
   284 		{
   406 		{
   287 		stmtComponentLocalizable->BindStr(3, compLocIter->iName);
   409 		stmtComponentLocalizable->BindStr(3, compLocIter->iName);
   288 		stmtComponentLocalizable->BindStr(4, compLocIter->iVendor);
   410 		stmtComponentLocalizable->BindStr(4, compLocIter->iVendor);
   289 		stmtComponentLocalizable->ExecuteStatement();
   411 		stmtComponentLocalizable->ExecuteStatement();
   290 		stmtComponentLocalizable->Reset();
   412 		stmtComponentLocalizable->Reset();
   291 		}
   413 		}
       
   414 	LOGEXIT("CDbLayer::AddComponentLocalizables()");
   292 	}
   415 	}
   293 
   416 
   294 void CDbLayer::AddComponentProperties( 
   417 void CDbLayer::AddComponentProperties( 
   295 	int aComponentId, 
   418 	int aComponentId, 
   296 	const std::vector<XmlDetails::TScrPreProvisionDetail::TComponentProperty>& aComponentProperty)
   419 	const std::vector<XmlDetails::TScrPreProvisionDetail::TComponentProperty>& aComponentProperty)
   297 	{
   420 	{
   298 	
   421 	LOGENTER("CDbLayer::AddComponentProperties()");
   299 	std::string insertComponentProperties;
   422 	std::string insertComponentProperties;
   300 	
   423 	
   301 	for(CompPropIterator compPropIter = aComponentProperty.begin(); compPropIter != aComponentProperty.end() ; ++compPropIter )
   424 	for(CompPropIterator compPropIter = aComponentProperty.begin(); compPropIter != aComponentProperty.end() ; ++compPropIter )
   302 		{
   425 		{
   303 		if(compPropIter->iIsIntValue == 1)
   426 		if(compPropIter->iIsIntValue == 1)
   320 			}
   443 			}
   321 		else
   444 		else
   322 			{
   445 			{
   323 			if(compPropIter->iIsStr8Bit)
   446 			if(compPropIter->iIsStr8Bit)
   324 				{
   447 				{
   325 				std::string str = Util::wstring2string(compPropIter->iValue);
   448 				std::string str = wstring2string(compPropIter->iValue);
   326 				std::string decodedString = Util::Base64Decode(str);
   449 				std::string decodedString = Util::Base64Decode(str);
   327 				stmtComponentProperty->BindBinary(4, str);
   450 				stmtComponentProperty->BindBinary(4, decodedString);
   328 				}
   451 				}
   329 			else
   452 			else
   330 				{
   453 				{
   331 				stmtComponentProperty->BindStr(4, compPropIter->iValue);
   454 				stmtComponentProperty->BindStr(4, compPropIter->iValue);
   332 				}
   455 				}
   336 		stmtComponentProperty->BindInt(5, compPropIter->iIsStr8Bit);
   459 		stmtComponentProperty->BindInt(5, compPropIter->iIsStr8Bit);
   337 	
   460 	
   338 		stmtComponentProperty->ExecuteStatement();
   461 		stmtComponentProperty->ExecuteStatement();
   339 		stmtComponentProperty->Reset();
   462 		stmtComponentProperty->Reset();
   340 		}
   463 		}
   341 	
   464 	LOGEXIT("CDbLayer::AddComponentProperties()");
   342 	}
   465 	}
   343 
   466 
   344 void CDbLayer::AddComponentFiles(int aComponentId, const std::vector<XmlDetails::TScrPreProvisionDetail::TComponentFile>& aComponentFiles)
   467 void CDbLayer::AddComponentFiles(int aComponentId, const std::vector<XmlDetails::TScrPreProvisionDetail::TComponentFile>& aComponentFiles)
   345 	{
   468 	{
       
   469 	LOGENTER("CDbLayer::AddComponentFiles()");
   346 	for(CompFileIter compFile = aComponentFiles.begin() ; compFile != aComponentFiles.end() ; ++compFile)
   470 	for(CompFileIter compFile = aComponentFiles.begin() ; compFile != aComponentFiles.end() ; ++compFile)
   347 		{
   471 		{
   348 		AddLocation(aComponentId,compFile->iLocation);
   472 		AddLocation(aComponentId,compFile->iLocation);
   349 		int cmpFileId = iScrDbHandler->LastInsertedId();
   473 		int cmpFileId = iScrDbHandler->LastInsertedId();
   350 		AddFileProperties(cmpFileId,compFile->iFileProperties);
   474 		AddFileProperties(cmpFileId,compFile->iFileProperties);
   351 		
   475 		}
   352 		}
   476 	LOGEXIT("CDbLayer::AddComponentFiles()");
   353 	}
   477 	}
   354 
   478 
   355 
   479 
   356 void CDbLayer::AddComponentDependencies	(	int aComponentId, 
   480 void CDbLayer::AddComponentDependencies	(	int aComponentId, 
   357 											const XmlDetails::TScrPreProvisionDetail::TComponentDependency& aComponentDependency,
   481 											const XmlDetails::TScrPreProvisionDetail::TComponentDependency& aComponentDependency,
   358 											const std::wstring& aSoftwareTypeName
   482 											const std::wstring& aSoftwareTypeName
   359 										)
   483 										)
   360 	{
   484 	{
       
   485 	LOGENTER("CDbLayer::AddComponentDependencies()");
   361 	std::wstring dependentId = aComponentDependency.iDependentId;
   486 	std::wstring dependentId = aComponentDependency.iDependentId;
   362 
   487 
   363 	if(dependentId.empty())
   488 	if(dependentId.empty())
   364 		return;
   489 		return;
   365 	
   490 	
   371 	std::vector<XmlDetails::TScrPreProvisionDetail::TComponentDependency::TComponentDependencyDetail>::const_iterator compDepIter;
   496 	std::vector<XmlDetails::TScrPreProvisionDetail::TComponentDependency::TComponentDependencyDetail>::const_iterator compDepIter;
   372 
   497 
   373 	for(compDepIter = aComponentDependencyDetails.begin() ; compDepIter != aComponentDependencyDetails.end() ; ++compDepIter)
   498 	for(compDepIter = aComponentDependencyDetails.begin() ; compDepIter != aComponentDependencyDetails.end() ; ++compDepIter)
   374 		{
   499 		{
   375 		std::wstring concatGlobalId = dependantGlobalId + compDepIter->iSupplierId;
   500 		std::wstring concatGlobalId = dependantGlobalId + compDepIter->iSupplierId;
   376 				
   501 
   377 		unsigned int globalIdHash = Util::Crc32(concatGlobalId.c_str(),concatGlobalId.length()*2);
   502 		// To maintain the consistency of CRC value across the platforms(WINDOWS and LINUX), we are
   378 		unsigned int dependantIdHash = Util::Crc32(dependantGlobalId.c_str(),dependantGlobalId.length()*2);
   503 		// using UTF-16 string in CRC generation.
   379 		unsigned int supplierIdHash = Util::Crc32(compDepIter->iSupplierId.c_str(),compDepIter->iSupplierId.length()*2);
   504 		utf16WString utf16Ws = utf32WString2utf16WString(concatGlobalId);
   380 		
   505 		unsigned int globalIdHash = Util::Crc32(utf16Ws.c_str(),concatGlobalId.length()*2);
       
   506 
       
   507 		utf16Ws = utf32WString2utf16WString(dependantGlobalId);
       
   508 		unsigned int dependantIdHash = Util::Crc32(utf16Ws.c_str(),dependantGlobalId.length()*2);
       
   509 
       
   510 		utf16Ws = utf32WString2utf16WString(compDepIter->iSupplierId);
       
   511 		unsigned int supplierIdHash = Util::Crc32(utf16Ws.c_str(),compDepIter->iSupplierId.length()*2);
       
   512 
       
   513 
   381 		std::string insertComponentDeps("INSERT INTO ComponentDependencies(GlobalIdHash,DependantGlobalIdHash, SupplierGlobalIdHash, DependantGlobalId,SupplierGlobalId,VersionFrom,VersionTo) VALUES(?,?,?,?,?,?,?);");
   514 		std::string insertComponentDeps("INSERT INTO ComponentDependencies(GlobalIdHash,DependantGlobalIdHash, SupplierGlobalIdHash, DependantGlobalId,SupplierGlobalId,VersionFrom,VersionTo) VALUES(?,?,?,?,?,?,?);");
   382 		std::auto_ptr<CStatement> stmtComponentDeps(iScrDbHandler->PrepareStatement(insertComponentDeps));
   515 		std::auto_ptr<CStatement> stmtComponentDeps(iScrDbHandler->PrepareStatement(insertComponentDeps));
   383 		
   516 		
   384 		stmtComponentDeps->BindInt( 1 ,globalIdHash);
   517 		stmtComponentDeps->BindInt( 1 ,globalIdHash);
   385 		stmtComponentDeps->BindInt( 2 ,dependantIdHash);
   518 		stmtComponentDeps->BindInt( 2 ,dependantIdHash);
   391 		
   524 		
   392 		stmtComponentDeps->ExecuteStatement();
   525 		stmtComponentDeps->ExecuteStatement();
   393 		stmtComponentDeps->Reset();
   526 		stmtComponentDeps->Reset();
   394 	
   527 	
   395 		}	
   528 		}	
       
   529 	LOGEXIT("CDbLayer::AddComponentDependencies()");
   396 	}
   530 	}
   397 
   531 
   398 
   532 
   399 void CDbLayer::AddLocation(int aComponentId,  const std::wstring& aLocation)
   533 void CDbLayer::AddLocation(int aComponentId,  const std::wstring& aLocation)
   400 	{
   534 	{
   401 	std::string insertComponentFileDetails("INSERT INTO ComponentsFiles(ComponentId,LocationHash,Location) VALUES(?,?,?);");
   535 	std::string insertComponentFileDetails("INSERT INTO ComponentsFiles(ComponentId,LocationHash,Location) VALUES(?,?,?);");
   402 	std::auto_ptr<CStatement> stmtComponentFileDetails(iScrDbHandler->PrepareStatement(insertComponentFileDetails));
   536 	std::auto_ptr<CStatement> stmtComponentFileDetails(iScrDbHandler->PrepareStatement(insertComponentFileDetails));
   403 	
   537 	
   404 	stmtComponentFileDetails->BindInt(1,aComponentId);
   538 	stmtComponentFileDetails->BindInt(1,aComponentId);
   405 	
   539 	
   406 	// size does not return the actual binary size of the object
       
   407 	int length = aLocation.length()*2 ;
   540 	int length = aLocation.length()*2 ;
       
   541 
   408 	// generate hash for location
   542 	// generate hash for location
   409 	std::wstring location = aLocation;
   543 	std::wstring location = aLocation;
   410 	std::transform(	location.begin(), location.end(), location.begin(), tolower);
   544 	std::transform(	location.begin(), location.end(), location.begin(), tolower);
   411 
   545 
   412 	unsigned int hash = Util::Crc32(location.c_str(),length);
   546 	#ifdef __TOOLS2_LINUX__
   413 	
   547 
       
   548 	// To maintain the consistency of the LocationHash value(essentially the CRC of
       
   549 	// Location string) across the WINDOWS and LINUX platforms, we reconstruct the
       
   550 	// location to have WINDOWS specific path.
       
   551 
       
   552     std::wstring::size_type idx = 0;
       
   553      while( (idx = location.find(L"//", idx)) != std::wstring::npos)
       
   554      {
       
   555     	 location.replace( idx, 2, L"\\\\" );
       
   556      }
       
   557 
       
   558      idx = 0;
       
   559 
       
   560      while( (idx = location.find(L"/", idx)) != std::wstring::npos)
       
   561      {
       
   562     	 location.replace( idx, 1, L"\\" );
       
   563      }
       
   564 
       
   565 	#endif
       
   566 
       
   567 
       
   568 	// To maintain the consistency of CRC value across the platforms(WINDOWS and LINUX), we are
       
   569 	// using UTF-16 string in CRC generation.
       
   570 
       
   571 	utf16WString utf16Ws = utf32WString2utf16WString(location);
       
   572 	unsigned int hash = Util::Crc32(utf16Ws.c_str(),length);
       
   573 
   414 	stmtComponentFileDetails->BindInt(2,hash);
   574 	stmtComponentFileDetails->BindInt(2,hash);
   415 	stmtComponentFileDetails->BindStr(3,aLocation);
   575 	stmtComponentFileDetails->BindStr(3,aLocation);
   416 	stmtComponentFileDetails->ExecuteStatement();
   576 	stmtComponentFileDetails->ExecuteStatement();
   417 	stmtComponentFileDetails->Reset();
   577 	stmtComponentFileDetails->Reset();
   418 		
   578 		
   445 			int intValue = Util::WideCharToInteger(filePropIter->iValue.c_str());
   605 			int intValue = Util::WideCharToInteger(filePropIter->iValue.c_str());
   446 			stmtFileProperty->BindInt(3, intValue);
   606 			stmtFileProperty->BindInt(3, intValue);
   447 			}
   607 			}
   448 		else
   608 		else
   449 			{
   609 			{
   450 			std::string str = Util::wstring2string(filePropIter->iValue);
   610 			std::string str = wstring2string(filePropIter->iValue);
   451 			std::string decodedString = Util::Base64Decode(str);
   611 			std::string decodedString = Util::Base64Decode(str);
   452 			stmtFileProperty->BindBinary(3, str);
   612 			stmtFileProperty->BindBinary(3, decodedString);
   453 			stmtFileProperty->BindInt(4, 1);
   613 			stmtFileProperty->BindInt(4, 1);
   454 			}
   614 			}
   455 
   615 
   456 		stmtFileProperty->ExecuteStatement();
   616 		stmtFileProperty->ExecuteStatement();
   457 		stmtFileProperty->Reset();
   617 		stmtFileProperty->Reset();
   458 		}
   618 		}
   459 	}
   619 	}
   460 
   620 
       
   621 
       
   622 void CDbLayer::AddApplicationRegistrationInfo( int aComponentId, const std::vector<XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo>& aApplicationRegistrationInfo)
       
   623 	{
       
   624 	LOGENTER("CDbLayer::AddApplicationRegistrationInfo()");
       
   625 	int appflag = 0;
       
   626 	int appUid = 0;
       
   627 	int error = 0;
       
   628 
       
   629 	for(CompApplicationRegistrationInfoIterator compApplicationRegistrationInfoIter = aApplicationRegistrationInfo.begin(); compApplicationRegistrationInfoIter != aApplicationRegistrationInfo.end() ; ++compApplicationRegistrationInfoIter )
       
   630 	{
       
   631 		try {
       
   632 			appflag = 0;
       
   633 			appUid = AddAppAttribute(aComponentId, compApplicationRegistrationInfoIter->iApplicationAttribute);
       
   634 		}
       
   635 		catch(CException& aException)
       
   636 		{
       
   637 			LOGERROR(aException.GetMessageA());
       
   638 			LOGERROR("one of AddAppAttribute is already present in database");
       
   639 			appflag = 1;
       
   640 			error = 1;
       
   641 		}
       
   642 
       
   643 		if(appflag)
       
   644 			continue;
       
   645 				
       
   646 		if (appUid != 0)
       
   647 			{
       
   648 			AddFileOwnershipInfo(appUid, compApplicationRegistrationInfoIter->iFileOwnershipInfo);
       
   649 			AddServiceInfo(appUid, compApplicationRegistrationInfoIter->iApplicationServiceInfo);
       
   650 			AddAppLocalizableInfo(appUid, compApplicationRegistrationInfoIter->iApplicationLocalizableInfo);
       
   651 			AddProperty(appUid, compApplicationRegistrationInfoIter->iApplicationProperty);
       
   652 			}
       
   653 		else
       
   654 			{
       
   655 			std::string errMsg = "AppUid is null.";
       
   656 			LOGERROR(errMsg);
       
   657 			throw CException(errMsg,ExceptionCodes::ESqlArgumentError);
       
   658 			}
       
   659 	}
       
   660 
       
   661 	if(error)
       
   662 	{
       
   663 		std::string errMsg = "Duplicate entry present in database.";
       
   664 		LOGERROR(errMsg);
       
   665 		throw CException(errMsg,ExceptionCodes::EFileExists);
       
   666 	}
       
   667 
       
   668 	LOGEXIT("CDbLayer::AddApplicationRegistrationInfo()");
       
   669 	}
       
   670 
       
   671 int CDbLayer::AddAppAttribute( int aComponentId, const std::vector<XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TAppAttribute>& aAppAttribute)
       
   672 	{
       
   673 	LOGENTER("CDbLayer::AddAppAttribute()");
       
   674 	std::string insertAppAttributes;
       
   675 	
       
   676 	insertAppAttributes = "INSERT INTO AppRegistrationInfo(AppUid,ComponentId,AppFile,TypeId,Attributes,Hidden,Embeddable,Newfile,Launch,GroupName,DefaultScreenNumber) VALUES(?,?,?,?,?,?,?,?,?,?,?);";
       
   677 	std::auto_ptr<CStatement> stmtAppAttribute(iScrDbHandler->PrepareStatement(insertAppAttributes));
       
   678 
       
   679 	stmtAppAttribute->BindInt64(2, aComponentId);
       
   680 
       
   681 	//Assigning Default Values
       
   682 	TInt64 intVal = 0; 
       
   683 	stmtAppAttribute->BindInt64(1, intVal); //AppUid
       
   684 	stmtAppAttribute->BindInt64(4, intVal); //TypeId
       
   685 	stmtAppAttribute->BindInt64(5, intVal); //Attributes
       
   686 	stmtAppAttribute->BindInt64(6, intVal); //Hidden
       
   687 	stmtAppAttribute->BindInt64(7, intVal); //Embeddable
       
   688 	stmtAppAttribute->BindInt64(8, intVal); //Newfile
       
   689 	stmtAppAttribute->BindInt64(9, intVal); //Launch
       
   690 	stmtAppAttribute->BindInt64(11, intVal); //DefaultScreenNumber
       
   691 	std::wstring strVal(L"");
       
   692 	stmtAppAttribute->BindStr(3, strVal);  //AppFile
       
   693 	stmtAppAttribute->BindStr(10, strVal); //GroupName
       
   694 	
       
   695 	int appUid = 0;
       
   696 	std::string appfile;
       
   697 	for(ApplicationAttributeIterator applicationAttributeIter = aAppAttribute.begin(); applicationAttributeIter != aAppAttribute.end() ; ++applicationAttributeIter )
       
   698 		{
       
   699 		if (applicationAttributeIter->iName == L"AppUid")
       
   700 			{
       
   701 			LOGINFO("CDbLayer::AddAppAttribute()- appuid");
       
   702 			TInt64 intValue = Util::WideCharToInt64(applicationAttributeIter->iValue.c_str());
       
   703 			stmtAppAttribute->BindInt64(1, intValue);
       
   704 			appUid = intValue;
       
   705 			}
       
   706 		else if (applicationAttributeIter->iName == L"AppFile")
       
   707 			{
       
   708 			stmtAppAttribute->BindStr(3, applicationAttributeIter->iValue);
       
   709 			if (applicationAttributeIter->iValue.length() == 0)
       
   710 				{
       
   711 				std::string errMsg = "Invalid app file.";
       
   712 				LOGERROR(errMsg);
       
   713 				throw CException(errMsg,ExceptionCodes::ESqlArgumentError);
       
   714 				}
       
   715 			
       
   716 			}
       
   717 		else if (applicationAttributeIter->iName == L"TypeId")
       
   718 			{
       
   719 			TInt64 intValue = Util::WideCharToInt64(applicationAttributeIter->iValue.c_str());
       
   720 			stmtAppAttribute->BindInt64(4, intValue);
       
   721 			}
       
   722 		else if (applicationAttributeIter->iName == L"Attributes")
       
   723 			{
       
   724 			TInt64 intValue = Util::WideCharToInt64(applicationAttributeIter->iValue.c_str());
       
   725 			stmtAppAttribute->BindInt64(5, intValue);
       
   726 			}
       
   727 		else if (applicationAttributeIter->iName == L"Hidden")
       
   728 			{
       
   729 			TInt64 intValue = Util::WideCharToInt64(applicationAttributeIter->iValue.c_str());
       
   730 			stmtAppAttribute->BindInt64(6, intValue);
       
   731 			}
       
   732 		else if (applicationAttributeIter->iName == L"Embeddable")
       
   733 			{
       
   734 			TInt64 intValue = Util::WideCharToInt64(applicationAttributeIter->iValue.c_str());
       
   735 			stmtAppAttribute->BindInt64(7, intValue);
       
   736 			}
       
   737 		else if (applicationAttributeIter->iName == L"Newfile")
       
   738 			{
       
   739 			TInt64 intValue = Util::WideCharToInt64(applicationAttributeIter->iValue.c_str());
       
   740 			stmtAppAttribute->BindInt64(8, intValue);
       
   741 			}
       
   742 		else if (applicationAttributeIter->iName == L"Launch")
       
   743 			{
       
   744 			TInt64 intValue = Util::WideCharToInt64(applicationAttributeIter->iValue.c_str());
       
   745 			stmtAppAttribute->BindInt64(9, intValue);
       
   746 			}
       
   747 		else if (applicationAttributeIter->iName == L"GroupName")
       
   748 			{
       
   749 			stmtAppAttribute->BindStr(10, applicationAttributeIter->iValue);
       
   750 			}
       
   751 		else if (applicationAttributeIter->iName == L"DefaultScreenNumber")
       
   752 			{
       
   753 			TInt64 intValue = Util::WideCharToInt64(applicationAttributeIter->iValue.c_str());
       
   754 			stmtAppAttribute->BindInt64(11, intValue);
       
   755 			}
       
   756 		else
       
   757 			{
       
   758 			std::string errMsg = "Invalid application attribute.";
       
   759 			LOGERROR(errMsg);
       
   760 			throw CException(errMsg,ExceptionCodes::ESqlArgumentError);
       
   761 			}
       
   762 		}
       
   763 
       
   764 		try
       
   765 		{
       
   766 			stmtAppAttribute->ExecuteStatement();
       
   767 			stmtAppAttribute->Reset();
       
   768 		}
       
   769 		catch(CException& aException)
       
   770 		{
       
   771 			LOGERROR(aException.GetMessageA());
       
   772 			LOGERROR("AppUid Already Present in Database");
       
   773 		}
       
   774 
       
   775 	LOGEXIT("CDbLayer::AddAppAttribute()");
       
   776 	return appUid;
       
   777 	}
       
   778 
       
   779 void CDbLayer::AddFileOwnershipInfo( int aAppUid, const std::vector<std::wstring>& aFileOwnershipInfo)
       
   780 	{
       
   781 	LOGENTER("CDbLayer::AddFileOwnershipInfo()");
       
   782 	std::string insertFileOwnershipInfo;
       
   783 	
       
   784 	for(ConstWstringIterator cWstringIter = aFileOwnershipInfo.begin(); cWstringIter != aFileOwnershipInfo.end() ; ++cWstringIter )
       
   785 		{  
       
   786 		insertFileOwnershipInfo = "INSERT INTO FileOwnershipInfo(AppUid,FileName) VALUES(?,?);";
       
   787 		std::auto_ptr<CStatement> stmtFileOwnershipInfo(iScrDbHandler->PrepareStatement(insertFileOwnershipInfo));
       
   788 		
       
   789 		stmtFileOwnershipInfo->BindInt64(1, aAppUid);
       
   790 		stmtFileOwnershipInfo->BindStr(2, *cWstringIter);
       
   791 			
       
   792 		stmtFileOwnershipInfo->ExecuteStatement();
       
   793 		stmtFileOwnershipInfo->Reset();
       
   794 		}
       
   795 	LOGEXIT("CDbLayer::AddFileOwnershipInfo()");
       
   796 	}
       
   797 
       
   798 void CDbLayer::AddServiceInfo( int aAppUid, const std::vector<XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TAppServiceInfo>& aApplicationServiceInfo)
       
   799 	{
       
   800 	LOGENTER("CDbLayer::AddServiceInfo()");
       
   801 	std::string insertServiceInfo;
       
   802 	
       
   803 	for(ApplicationServiceInfoIterator serviceInfoIter = aApplicationServiceInfo.begin(); serviceInfoIter != aApplicationServiceInfo.end() ; ++serviceInfoIter )
       
   804 		{  
       
   805 		insertServiceInfo = "INSERT INTO ServiceInfo(AppUid,Uid) VALUES(?,?);";
       
   806 		std::auto_ptr<CStatement> stmtServiceInfo(iScrDbHandler->PrepareStatement(insertServiceInfo));
       
   807 		
       
   808 		stmtServiceInfo->BindInt64(1, aAppUid);
       
   809 		stmtServiceInfo->BindInt64(2, serviceInfoIter->iUid);
       
   810 		stmtServiceInfo->ExecuteStatement();
       
   811 		stmtServiceInfo->Reset();
       
   812 		
       
   813 		int serviceId = iScrDbHandler->LastInsertedId();
       
   814 		std::string insertDataType;
       
   815 		
       
   816 		const std::vector<XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TDataType>& datatype = serviceInfoIter->iDataType;
       
   817 		for(ApplicationDataTypeIterator dataTypeIter = datatype.begin(); dataTypeIter != datatype.end() ; ++dataTypeIter )
       
   818 			{  
       
   819 			insertDataType = "INSERT INTO DataType(ServiceId,Priority,Type) VALUES(?,?,?);";
       
   820 			std::auto_ptr<CStatement> stmtDataType(iScrDbHandler->PrepareStatement(insertDataType));
       
   821 			
       
   822 			stmtDataType->BindInt64(1, serviceId);
       
   823 			stmtDataType->BindInt64(2, dataTypeIter->iPriority);
       
   824 			#ifdef __TOOLS2_LINUX__
       
   825 			stmtDataType->BindStr(3, dataTypeIter->iType, avoidSlashConversion);
       
   826 			#else
       
   827 			stmtDataType->BindStr(3, dataTypeIter->iType);
       
   828 			#endif
       
   829 				
       
   830 			stmtDataType->ExecuteStatement();
       
   831 			stmtDataType->Reset();
       
   832 			}
       
   833 		}
       
   834 	LOGEXIT("CDbLayer::AddServiceInfo()");
       
   835 	}
       
   836 
       
   837 void CDbLayer::AddAppLocalizableInfo( int aAppUid, const std::vector<XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TAppLocalizableInfo>& aApplicationLocalizableInfo)
       
   838 {
       
   839 	LOGENTER("CDbLayer::AddAppLocalizableInfo()");
       
   840 	for(ApplicationLocalizableInfoIterator localizableInfoIter = aApplicationLocalizableInfo.begin(); localizableInfoIter != aApplicationLocalizableInfo.end() ; ++localizableInfoIter )
       
   841 	{
       
   842 		AddLocalizableAttribute(aAppUid, localizableInfoIter->iLocalizableAttribute);
       
   843 		int localAppInfoId = iScrDbHandler->LastInsertedId();
       
   844 		AddViewData(localAppInfoId, localizableInfoIter->iViewData);
       
   845 	}
       
   846 	LOGEXIT("CDbLayer::AddAppLocalizableInfo()");
       
   847 }
       
   848 
       
   849 void CDbLayer::AddLocalizableAttribute( int aAppUid, const std::vector<XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TAppLocalizableInfo::TLocalizableAttribute>& aApplicationLocalizableAttribute)
       
   850 {
       
   851 	LOGENTER("CDbLayer::AddLocalizableAttribute()");
       
   852 	std::string insertAppLocalizableInfo;
       
   853 		
       
   854 	insertAppLocalizableInfo = "INSERT INTO LocalizableAppInfo(AppUid,ShortCaption,GroupName,Locale,CaptionAndIconId) VALUES(?,?,?,?,?);";
       
   855 	std::auto_ptr<CStatement> stmtAppLocalizableInfo(iScrDbHandler->PrepareStatement(insertAppLocalizableInfo));
       
   856 
       
   857 	//Assigning default value
       
   858 	TInt64 intVal = 0;
       
   859 	stmtAppLocalizableInfo->BindInt64(4, intVal); //Locale
       
   860 	stmtAppLocalizableInfo->BindInt64(5, intVal); //CaptionAndIconId
       
   861 	std::wstring strVal(L"");
       
   862 	stmtAppLocalizableInfo->BindStr(2, strVal);   //ShortCaption
       
   863 	stmtAppLocalizableInfo->BindStr(3, strVal);   //GroupName
       
   864 	
       
   865 	std::string insertCaptionAndIconInfo;
       
   866 		
       
   867 	insertCaptionAndIconInfo = "INSERT INTO CaptionAndIconInfo(Caption,NumberOfIcons,IconFile) VALUES(?,?,?);";
       
   868 	std::auto_ptr<CStatement> stmtCaptionAndIconInfo(iScrDbHandler->PrepareStatement(insertCaptionAndIconInfo));
       
   869 
       
   870 	//Assigning default value
       
   871 	stmtCaptionAndIconInfo->BindStr(1, strVal);   //Caption
       
   872 	stmtCaptionAndIconInfo->BindInt64(2, intVal); //NumberOfIcons
       
   873 	stmtCaptionAndIconInfo->BindStr(3, strVal);   //IconFile
       
   874 
       
   875 
       
   876 	bool captionAndIconInfoPresent = 0;
       
   877 	//for every TLocalizableAttribute
       
   878 	stmtAppLocalizableInfo->BindInt64(1, aAppUid);
       
   879 	for(LocalizableAttributeIterator localizableAttributeIter = aApplicationLocalizableAttribute.begin(); localizableAttributeIter != aApplicationLocalizableAttribute.end() ; ++localizableAttributeIter )
       
   880 	{
       
   881 		if (localizableAttributeIter->iName == L"ShortCaption")
       
   882 		{
       
   883 			stmtAppLocalizableInfo->BindStr(2, localizableAttributeIter->iValue);
       
   884 		}
       
   885 		else if(localizableAttributeIter->iName == L"GroupName")
       
   886 		{
       
   887 			stmtAppLocalizableInfo->BindStr(3, localizableAttributeIter->iValue);
       
   888 		}
       
   889 		else if(localizableAttributeIter->iName == L"Locale")
       
   890 		{
       
   891 			TInt64 intValue = Util::WideCharToInt64(localizableAttributeIter->iValue.c_str());
       
   892 			stmtAppLocalizableInfo->BindInt64(4, intValue);
       
   893 		}
       
   894 		else if(localizableAttributeIter->iName == L"Caption")
       
   895 		{
       
   896 			stmtCaptionAndIconInfo->BindStr(1, localizableAttributeIter->iValue);
       
   897 			captionAndIconInfoPresent = 1;
       
   898 		}
       
   899 		else if(localizableAttributeIter->iName == L"NumberOfIcons")
       
   900 		{
       
   901 			TInt64 intValue = Util::WideCharToInt64(localizableAttributeIter->iValue.c_str());
       
   902 			stmtCaptionAndIconInfo->BindInt64(2, intValue);
       
   903 			captionAndIconInfoPresent = 1;
       
   904 		}
       
   905 		else if(localizableAttributeIter->iName == L"IconFile")
       
   906 		{
       
   907 			stmtCaptionAndIconInfo->BindStr(3, localizableAttributeIter->iValue);
       
   908 			captionAndIconInfoPresent = 1;
       
   909 		}
       
   910 		else
       
   911 		{
       
   912 			std::string errMsg = "Invalid localizable attribute.";
       
   913 			LOGERROR(errMsg);
       
   914 			throw CException(errMsg,ExceptionCodes::ESqlArgumentError);
       
   915 		}
       
   916 	}
       
   917 	if (captionAndIconInfoPresent)
       
   918 	{
       
   919 		stmtCaptionAndIconInfo->ExecuteStatement();
       
   920 		stmtCaptionAndIconInfo->Reset();
       
   921 		int captionAndIconIdForLocalizableInfo = iScrDbHandler->LastInsertedId();
       
   922 		stmtAppLocalizableInfo->BindInt64(5, captionAndIconIdForLocalizableInfo);
       
   923 	}
       
   924 	stmtAppLocalizableInfo->ExecuteStatement();
       
   925 	stmtAppLocalizableInfo->Reset();
       
   926 	LOGEXIT("CDbLayer::AddLocalizableAttribute()");
       
   927 }
       
   928 
       
   929 
       
   930 void CDbLayer::AddViewData( int alocalAppInfoId, const std::vector<XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TAppLocalizableInfo::TViewData>& aViewData)
       
   931 {
       
   932 	LOGENTER("CDbLayer::AddViewData()");
       
   933 
       
   934 	for(ViewDataIterator viewDataIter = aViewData.begin(); viewDataIter != aViewData.end() ; ++viewDataIter )
       
   935 	{
       
   936 		AddViewDataAttributes(alocalAppInfoId, viewDataIter->iViewDataAttributes);
       
   937 	}
       
   938 
       
   939 	LOGEXIT("CDbLayer::AddViewData()");
       
   940 }
       
   941 
       
   942 
       
   943 void CDbLayer::AddViewDataAttributes( int alocalAppInfoId, const std::vector<XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TAppLocalizableInfo::TViewData::TViewDataAttributes>& aViewDataAttribute)
       
   944 	{
       
   945 	LOGENTER("CDbLayer::AddViewData()");
       
   946 	std::string insertViewData;
       
   947 
       
   948 	insertViewData = "INSERT INTO ViewData(LocalAppInfoId,Uid,ScreenMode,CaptionAndIconId) VALUES(?,?,?,?);";
       
   949 	std::auto_ptr<CStatement> stmtViewData(iScrDbHandler->PrepareStatement(insertViewData));
       
   950 
       
   951 
       
   952 	//Assigning Default Value
       
   953 	TInt64 intVal = 0;
       
   954 	stmtViewData->BindInt64(2, intVal); //Uid
       
   955 	stmtViewData->BindInt64(3, intVal); //ScreenMode
       
   956 	stmtViewData->BindInt64(4, intVal); //CaptionAndIconId
       
   957 
       
   958 	std::string insertCaptionAndIconInfo;
       
   959 		
       
   960 	insertCaptionAndIconInfo = "INSERT INTO CaptionAndIconInfo(Caption,NumberOfIcons,IconFile) VALUES(?,?,?);";
       
   961 	std::auto_ptr<CStatement> stmtCaptionAndIconInfo(iScrDbHandler->PrepareStatement(insertCaptionAndIconInfo));
       
   962 
       
   963 	//Assigning Default Value
       
   964 	stmtCaptionAndIconInfo->BindInt64(2, intVal); //NumberOfIcons
       
   965 	std::wstring strVal(L"");
       
   966 	stmtCaptionAndIconInfo->BindStr(1, strVal); //Caption
       
   967 	stmtCaptionAndIconInfo->BindStr(3, strVal); //IconFile
       
   968 
       
   969 	bool captionAndIconInfoPresent = 0;
       
   970 	//for every TViewData
       
   971 	stmtViewData->BindInt64(1, alocalAppInfoId);
       
   972 
       
   973 	for(ViewDataAttributeIterator viewDataIter = aViewDataAttribute.begin(); viewDataIter != aViewDataAttribute.end() ; ++viewDataIter )
       
   974 		{
       
   975 		if (viewDataIter->iName == L"Uid")
       
   976 			{
       
   977 			TInt64 intValue = Util::WideCharToInt64(viewDataIter->iValue.c_str());
       
   978 			stmtViewData->BindInt64(2, intValue);
       
   979 			}
       
   980 		else if(viewDataIter->iName == L"ScreenMode")
       
   981 			{
       
   982 			TInt64 intValue = Util::WideCharToInt64(viewDataIter->iValue.c_str());
       
   983 			stmtViewData->BindInt64(3, intValue);
       
   984 			}
       
   985 		else if(viewDataIter->iName == L"Caption")
       
   986 			{
       
   987 			stmtCaptionAndIconInfo->BindStr(1, viewDataIter->iValue);
       
   988 			captionAndIconInfoPresent = 1;
       
   989 			}
       
   990 		else if(viewDataIter->iName == L"NumberOfIcons")
       
   991 			{
       
   992 			TInt64 intValue = Util::WideCharToInt64(viewDataIter->iValue.c_str());
       
   993 			stmtCaptionAndIconInfo->BindInt64(2, intValue);
       
   994 			captionAndIconInfoPresent = 1;
       
   995 			}
       
   996 		else if(viewDataIter->iName == L"IconFile")
       
   997 			{
       
   998 			stmtCaptionAndIconInfo->BindStr(3, viewDataIter->iValue);
       
   999 			captionAndIconInfoPresent = 1;
       
  1000 			}
       
  1001 		else
       
  1002 			{
       
  1003 			std::string errMsg = "Invalid view data attribute.";
       
  1004 			LOGERROR(errMsg);
       
  1005 			throw CException(errMsg,ExceptionCodes::ESqlArgumentError);
       
  1006 			}
       
  1007 		}
       
  1008 	if (captionAndIconInfoPresent)
       
  1009 		{
       
  1010 		stmtCaptionAndIconInfo->ExecuteStatement();
       
  1011 		stmtCaptionAndIconInfo->Reset();
       
  1012 		int captionAndIconIdForViewData = iScrDbHandler->LastInsertedId();
       
  1013 		stmtViewData->BindInt64(4, captionAndIconIdForViewData);
       
  1014 		}
       
  1015 	stmtViewData->ExecuteStatement();
       
  1016 	stmtViewData->Reset();
       
  1017 	LOGEXIT("CDbLayer::AddViewData()");
       
  1018 	}
       
  1019 
       
  1020 void CDbLayer::AddProperty( int aAppUid, const std::vector<XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TAppProperty>& aApplicationProperty)
       
  1021 	{
       
  1022 	LOGENTER("CDbLayer::AddProperty()");
       
  1023 	std::string insertApplicationProperty;
       
  1024 
       
  1025 	for(ApplicationPropertyIterator appPropertyIter = aApplicationProperty.begin(); appPropertyIter != aApplicationProperty.end() ; ++appPropertyIter )
       
  1026 		{  
       
  1027 
       
  1028 		insertApplicationProperty = "INSERT INTO AppProperties(AppUid,Locale,Name,ServiceUid,IntValue,StrValue,IsStr8Bit) VALUES(?,?,?,?,?,?,?);";
       
  1029 		std::auto_ptr<CStatement> stmtAppProperty(iScrDbHandler->PrepareStatement(insertApplicationProperty));
       
  1030 		
       
  1031 		stmtAppProperty->BindInt64(1, aAppUid);
       
  1032 		stmtAppProperty->BindInt(2, appPropertyIter->iLocale);
       
  1033 		stmtAppProperty->BindStr(3, appPropertyIter->iName);
       
  1034 		stmtAppProperty->BindInt(4, appPropertyIter->iServiceUid);
       
  1035 		stmtAppProperty->BindInt(5, appPropertyIter->iIntValue);
       
  1036 
       
  1037 		if(appPropertyIter->iIsStr8Bit)
       
  1038 			{
       
  1039 				std::string str;
       
  1040 				int len = appPropertyIter->iStrValue.length();
       
  1041 				str.assign(appPropertyIter->iStrValue.c_str(),appPropertyIter->iStrValue.c_str()+len);
       
  1042 				stmtAppProperty->BindBinary(6, str);
       
  1043 			}
       
  1044 		else
       
  1045 			{
       
  1046 			stmtAppProperty->BindStr(6, appPropertyIter->iStrValue);
       
  1047 			}
       
  1048 		
       
  1049 		stmtAppProperty->BindInt(7, appPropertyIter->iIsStr8Bit);
       
  1050 
       
  1051 		stmtAppProperty->ExecuteStatement();
       
  1052 		stmtAppProperty->Reset();
       
  1053 		}
       
  1054 	LOGEXIT("CDbLayer::AddProperty()");
       
  1055 	}
       
  1056 
   461 void CDbLayer::ExecuteStatement(const std::string& aStmtStr)
  1057 void CDbLayer::ExecuteStatement(const std::string& aStmtStr)
   462 	{
  1058 	{
   463 	std::auto_ptr<CStatement> stmt(iScrDbHandler->PrepareStatement(aStmtStr));
  1059 	std::auto_ptr<CStatement> stmt(iScrDbHandler->PrepareStatement(aStmtStr));
   464 	stmt->ExecuteStatement();
  1060 	stmt->ExecuteStatement();
   465 	}
  1061 	}