diff -r 5cc91383ab1e -r 7333d7932ef7 secureswitools/swisistools/source/dbmanager/dblayer.cpp --- a/secureswitools/swisistools/source/dbmanager/dblayer.cpp Thu Aug 19 10:02:49 2010 +0300 +++ b/secureswitools/swisistools/source/dbmanager/dblayer.cpp Tue Aug 31 15:21:33 2010 +0300 @@ -1,5 +1,5 @@ /* -* Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). +* Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). * All rights reserved. * This component and the accompanying materials are made available * under the terms of the License "Eclipse Public License v1.0" @@ -21,6 +21,7 @@ #include "logs.h" #include "util.h" #include "symbiantypes.h" +#include "utility.h" #include #include @@ -37,11 +38,76 @@ typedef std::vector::const_iterator ConstWstringIterator; typedef std::vector::const_iterator ScrEnvIterator; typedef std::vector::const_iterator ScrEnvLocSwTypeNameIterator; +typedef std::vector::const_iterator ScrEnvCustomAccessIterator; typedef std::vector::const_iterator CompIterator; typedef std::vector::const_iterator CompLocIterator; typedef std::vector::const_iterator CompPropIterator; typedef std::vector::const_iterator CompFileIter; typedef std::vector::const_iterator FilePropIterator; +typedef std::vector::const_iterator CompApplicationRegistrationInfoIterator; +typedef std::vector::const_iterator ApplicationAttributeIterator; +typedef std::vector::const_iterator ApplicationDataTypeIterator; +typedef std::vector::const_iterator ApplicationServiceInfoIterator; +typedef std::vector::const_iterator ApplicationLocalizableInfoIterator; +typedef std::vector::const_iterator LocalizableAttributeIterator; +typedef std::vector::const_iterator ViewDataIterator; +typedef std::vector::const_iterator ViewDataAttributeIterator; +typedef std::vector::const_iterator ApplicationPropertyIterator; + + +#ifdef __LINUX__ + +/* +* Platform specific feature +* +* In WINDOWS : sizeof(wchar_t) = 2 +* In LINUX : sizeof(wchar_t) = 4 +*/ + +static utf16WString utf32WString2utf16WString(std::wstring aParameter) +{ + int strLen = aParameter.length(); + const wchar_t * source = aParameter.c_str(); + unsigned short int* buffer = new unsigned short int[strLen + 1]; + + // Using a temp variable in place of buffer as ConvertUTF32toUTF16 modifies the source pointer passed. + unsigned short int* temp = buffer; + + ConvertUTF32toUTF16(&source, source + strLen, &temp, temp + strLen, lenientConversion); + + // Appending NUL to the converted buffer. + *temp = 0; + + utf16WString utf16Ws; + utf16Ws.resize(strLen); + + // The built-in basic_string template class copy operation + // truncates when a NUL is encountered when a c_str() is + // used to construct the required string. + // So, if aParameter is any hashable string having the + // syntax : swtypeName + L'\0' + someId then, we will end + // up returning only part of the converted UTF-16 string. + // Hence, we resort to the explicit copy operation with + // two bytes at a time. + while( strLen-- ) + { + utf16Ws[ strLen ] = buffer[ strLen ]; + } + + delete[] buffer; + + return utf16Ws; +} + +#else + +// We need not do anything for WINDOWS, since the windows wstring +// will already be in UTF-16 encoding. +#define utf32WString2utf16WString(aParameter) (aParameter) + +#endif + + const int KMaxDrives=26; @@ -87,13 +153,14 @@ { try { + LOGENTER("CDbLayer::PopulatePreProvisionDetails()"); AddPreProvisionDetails(aPreProvisionDetailList); } catch(CException& aException) { std::string rollbackTransaction("ROLLBACK;"); ExecuteStatement(rollbackTransaction); - std::string errMsg = "Failed to populate SCR database with environment details."; + std::string errMsg = "Failed to populate SCR database with pre provision details."; LOGERROR(aException.GetMessageA()); throw CException(errMsg,ExceptionCodes::ESqlCorrupt); } @@ -110,9 +177,16 @@ void CDbLayer::PopulateDatabase(const std::vector& aScrEnvDetails) { - std::string insertSoftwareType("INSERT INTO SoftwareTypes(SoftwareTypeId,SifPluginUid,InstallerSecureId,ExecutionLayerSecureId) VALUES(?,?,?,?);"); + LOGENTER("CDbLayer::PopulateDatabase()"); + std::string insertSoftwareType("INSERT INTO SoftwareTypes(SoftwareTypeId,SifPluginUid,LauncherExecutable) VALUES(?,?,?);"); std::auto_ptr stmtSwType(iScrDbHandler->PrepareStatement(insertSoftwareType)); + std::string insertSTWithoutLE("INSERT INTO SoftwareTypes(SoftwareTypeId,SifPluginUid) VALUES(?,?);"); + std::auto_ptr stmtSwTypeWithoutLE(iScrDbHandler->PrepareStatement(insertSTWithoutLE)); + + std::string insertCustomAccessList("INSERT INTO CustomAccessList(SoftwareTypeId,SecureId,AccessMode) VALUES(?,?,?);"); + std::auto_ptr stmtCustomAccessList(iScrDbHandler->PrepareStatement(insertCustomAccessList)); + std::string insertSwTypeName("INSERT INTO SoftwareTypeNames(SoftwareTypeId,Locale,Name) VALUES(?,?,?);"); std::auto_ptr stmtSwTypeName(iScrDbHandler->PrepareStatement(insertSwTypeName)); @@ -121,13 +195,26 @@ for(ScrEnvIterator aScrEnvIterator = aScrEnvDetails.begin(); aScrEnvIterator != aScrEnvDetails.end(); ++aScrEnvIterator) { - unsigned int swTypeId = Util::Crc32(aScrEnvIterator->iUniqueSoftwareTypeName.c_str(),aScrEnvIterator->iUniqueSoftwareTypeName.length()*2); + // To maintain the consistency of CRC value across the platforms(WINDOWS and LINUX), we are + // using UTF-16 string in CRC generation. + utf16WString utf16Ws = utf32WString2utf16WString(aScrEnvIterator->iUniqueSoftwareTypeName); + unsigned int swTypeId = Util::Crc32(utf16Ws.c_str(),aScrEnvIterator->iUniqueSoftwareTypeName.length()*2); + + if (!aScrEnvIterator->iLauncherExecutable.empty()) + { stmtSwType->BindInt(1, swTypeId); stmtSwType->BindInt(2, aScrEnvIterator->iSifPluginUid); - stmtSwType->BindInt(3, aScrEnvIterator->iInstallerSid); - stmtSwType->BindInt(4, aScrEnvIterator->iExecutionLayerSid); + stmtSwType->BindStr(3, aScrEnvIterator->iLauncherExecutable); stmtSwType->ExecuteStatement(); stmtSwType->Reset(); + } + else + { + stmtSwTypeWithoutLE->BindInt(1, swTypeId); + stmtSwTypeWithoutLE->BindInt(2, aScrEnvIterator->iSifPluginUid); + stmtSwTypeWithoutLE->ExecuteStatement(); + stmtSwTypeWithoutLE->Reset(); + } // First insert unique sw type name const TInt uniqueSwTypeNameLocale = 0; ExecuteSwTypeNameStatement(stmtSwTypeName, swTypeId, uniqueSwTypeNameLocale, aScrEnvIterator->iUniqueSoftwareTypeName); @@ -136,6 +223,16 @@ { ExecuteSwTypeNameStatement(stmtSwTypeName, swTypeId, swTypeNameIter->iLocale, swTypeNameIter->iName); } + + for(ScrEnvCustomAccessIterator customAccessIter = aScrEnvIterator->iCustomAcessList.begin(); customAccessIter != aScrEnvIterator->iCustomAcessList.end(); ++customAccessIter) + { + stmtCustomAccessList->BindInt(1, swTypeId); + stmtCustomAccessList->BindInt(2, customAccessIter->iSecureId); + stmtCustomAccessList->BindInt(3, customAccessIter->iAccessMode); + stmtCustomAccessList->ExecuteStatement(); + stmtCustomAccessList->Reset(); + } + for(ConstWstringIterator mimeIter= aScrEnvIterator->iMIMEDetails.begin(); mimeIter != aScrEnvIterator->iMIMEDetails.end(); ++mimeIter) { stmtMimeType->BindInt(1, swTypeId); @@ -144,36 +241,54 @@ stmtMimeType->Reset(); } } + LOGEXIT("CDbLayer::PopulateDatabase()"); } void CDbLayer::AddPreProvisionDetails(const XmlDetails::TScrPreProvisionDetail& aPreProvisionDetailList) { + LOGENTER("CDbLayer::AddPreProvisionDetails()"); for(CompIterator aCompIterator = aPreProvisionDetailList.iComponents.begin(); aCompIterator != aPreProvisionDetailList.iComponents.end(); ++aCompIterator) { std::string beginTransaction("BEGIN;"); ExecuteStatement(beginTransaction); - AddComponentDetails(*aCompIterator, aPreProvisionDetailList.iSoftwareTypeName); - int componentId = iScrDbHandler->LastInsertedId(); - AddComponentLocalizables(componentId,aCompIterator->iComponentLocalizables); - AddComponentProperties(componentId,aCompIterator->iComponentProperties); - AddComponentFiles(componentId,aCompIterator->iComponentFiles); - AddComponentDependencies(componentId, aCompIterator->iComponentDependency, aPreProvisionDetailList.iSoftwareTypeName); - + int componentId = 0; + if (!AddComponentDetails(*aCompIterator, aPreProvisionDetailList.iSoftwareTypeName)) + { + componentId = iScrDbHandler->LastInsertedId(); + AddComponentLocalizables(componentId,aCompIterator->iComponentLocalizables); + AddComponentProperties(componentId,aCompIterator->iComponentProperties); + AddComponentFiles(componentId,aCompIterator->iComponentFiles); + AddComponentDependencies(componentId, aCompIterator->iComponentDependency, aPreProvisionDetailList.iSoftwareTypeName); + } + AddApplicationRegistrationInfo(componentId,aCompIterator->iApplicationRegistrationInfo); std::string commitTransaction("COMMIT;"); ExecuteStatement(commitTransaction); } + LOGEXIT("CDbLayer::AddPreProvisionDetails()"); } -void CDbLayer::AddComponentDetails(const XmlDetails::TScrPreProvisionDetail::TComponent& aComponent, const std::wstring& aSoftwareTypeName) +bool CDbLayer::AddComponentDetails(const XmlDetails::TScrPreProvisionDetail::TComponent& aComponent, const std::wstring& aSoftwareTypeName) { + LOGENTER("CDbLayer::AddComponentDetails()"); std::string insertComponents; XmlDetails::TScrPreProvisionDetail::TComponentDetails componentDetail = aComponent.iComponentDetails; + if (aComponent.iComponentDetails.iIsRomApplication) + { + LOGINFO("Is rom app"); + return true; + } + LOGINFO("Not rom app"); - unsigned int swTypeId = Util::Crc32(aSoftwareTypeName.c_str(),aSoftwareTypeName.length()*2); + // To maintain the consistency of CRC value across the platforms(WINDOWS and LINUX), we are + // using UTF-16 string in CRC generation. + utf16WString utf16Ws = utf32WString2utf16WString(aSoftwareTypeName); + unsigned int swTypeId = Util::Crc32(utf16Ws.c_str(),aSoftwareTypeName.length()*2); + + std::wstring strGlobalId = componentDetail.iGlobalId; if(!strGlobalId.empty()) @@ -211,7 +326,12 @@ if(!strGlobalId.empty()) { std::wstring concatGlobalId = aSoftwareTypeName + L'\0' + strGlobalId; - unsigned int globalIdHash = Util::Crc32(concatGlobalId.c_str(),concatGlobalId.length()*2); + + // To maintain the consistency of CRC value across the platforms(WINDOWS and LINUX), we are + // using UTF-16 string in CRC generation. + utf16WString utf16Ws = utf32WString2utf16WString(concatGlobalId); + unsigned int globalIdHash = Util::Crc32(utf16Ws.c_str(),concatGlobalId.length()*2); + stmtComponents->BindInt(9, globalIdHash); stmtComponents->BindStr(10, concatGlobalId); stmtComponents->BindStr(11, version); @@ -225,7 +345,8 @@ stmtComponents->ExecuteStatement(); stmtComponents->Reset(); - + LOGEXIT("CDbLayer::AddComponentDetails()"); + return false; } int CDbLayer::GetInstalledDrives(const std::vector& aComponentFiles ) @@ -277,6 +398,7 @@ void CDbLayer::AddComponentLocalizables( int aComponentId, const std::vector& aComponentLocalizable) { + LOGENTER("CDbLayer::AddComponentLocalizables()"); std::string insertComponentLocalizable("INSERT INTO ComponentLocalizables(ComponentId,Locale,Name,Vendor) VALUES(?,?,?,?);"); std::auto_ptr stmtComponentLocalizable(iScrDbHandler->PrepareStatement(insertComponentLocalizable)); @@ -289,13 +411,14 @@ stmtComponentLocalizable->ExecuteStatement(); stmtComponentLocalizable->Reset(); } + LOGEXIT("CDbLayer::AddComponentLocalizables()"); } void CDbLayer::AddComponentProperties( int aComponentId, const std::vector& aComponentProperty) { - + LOGENTER("CDbLayer::AddComponentProperties()"); std::string insertComponentProperties; for(CompPropIterator compPropIter = aComponentProperty.begin(); compPropIter != aComponentProperty.end() ; ++compPropIter ) @@ -322,9 +445,9 @@ { if(compPropIter->iIsStr8Bit) { - std::string str = Util::wstring2string(compPropIter->iValue); + std::string str = wstring2string(compPropIter->iValue); std::string decodedString = Util::Base64Decode(str); - stmtComponentProperty->BindBinary(4, str); + stmtComponentProperty->BindBinary(4, decodedString); } else { @@ -338,18 +461,19 @@ stmtComponentProperty->ExecuteStatement(); stmtComponentProperty->Reset(); } - + LOGEXIT("CDbLayer::AddComponentProperties()"); } void CDbLayer::AddComponentFiles(int aComponentId, const std::vector& aComponentFiles) { + LOGENTER("CDbLayer::AddComponentFiles()"); for(CompFileIter compFile = aComponentFiles.begin() ; compFile != aComponentFiles.end() ; ++compFile) { AddLocation(aComponentId,compFile->iLocation); int cmpFileId = iScrDbHandler->LastInsertedId(); AddFileProperties(cmpFileId,compFile->iFileProperties); - } + LOGEXIT("CDbLayer::AddComponentFiles()"); } @@ -358,6 +482,7 @@ const std::wstring& aSoftwareTypeName ) { + LOGENTER("CDbLayer::AddComponentDependencies()"); std::wstring dependentId = aComponentDependency.iDependentId; if(dependentId.empty()) @@ -373,11 +498,19 @@ for(compDepIter = aComponentDependencyDetails.begin() ; compDepIter != aComponentDependencyDetails.end() ; ++compDepIter) { std::wstring concatGlobalId = dependantGlobalId + compDepIter->iSupplierId; - - unsigned int globalIdHash = Util::Crc32(concatGlobalId.c_str(),concatGlobalId.length()*2); - unsigned int dependantIdHash = Util::Crc32(dependantGlobalId.c_str(),dependantGlobalId.length()*2); - unsigned int supplierIdHash = Util::Crc32(compDepIter->iSupplierId.c_str(),compDepIter->iSupplierId.length()*2); - + + // To maintain the consistency of CRC value across the platforms(WINDOWS and LINUX), we are + // using UTF-16 string in CRC generation. + utf16WString utf16Ws = utf32WString2utf16WString(concatGlobalId); + unsigned int globalIdHash = Util::Crc32(utf16Ws.c_str(),concatGlobalId.length()*2); + + utf16Ws = utf32WString2utf16WString(dependantGlobalId); + unsigned int dependantIdHash = Util::Crc32(utf16Ws.c_str(),dependantGlobalId.length()*2); + + utf16Ws = utf32WString2utf16WString(compDepIter->iSupplierId); + unsigned int supplierIdHash = Util::Crc32(utf16Ws.c_str(),compDepIter->iSupplierId.length()*2); + + std::string insertComponentDeps("INSERT INTO ComponentDependencies(GlobalIdHash,DependantGlobalIdHash, SupplierGlobalIdHash, DependantGlobalId,SupplierGlobalId,VersionFrom,VersionTo) VALUES(?,?,?,?,?,?,?);"); std::auto_ptr stmtComponentDeps(iScrDbHandler->PrepareStatement(insertComponentDeps)); @@ -393,6 +526,7 @@ stmtComponentDeps->Reset(); } + LOGEXIT("CDbLayer::AddComponentDependencies()"); } @@ -403,14 +537,40 @@ stmtComponentFileDetails->BindInt(1,aComponentId); - // size does not return the actual binary size of the object int length = aLocation.length()*2 ; + // generate hash for location std::wstring location = aLocation; std::transform( location.begin(), location.end(), location.begin(), tolower); - unsigned int hash = Util::Crc32(location.c_str(),length); - + #ifdef __TOOLS2_LINUX__ + + // To maintain the consistency of the LocationHash value(essentially the CRC of + // Location string) across the WINDOWS and LINUX platforms, we reconstruct the + // location to have WINDOWS specific path. + + std::wstring::size_type idx = 0; + while( (idx = location.find(L"//", idx)) != std::wstring::npos) + { + location.replace( idx, 2, L"\\\\" ); + } + + idx = 0; + + while( (idx = location.find(L"/", idx)) != std::wstring::npos) + { + location.replace( idx, 1, L"\\" ); + } + + #endif + + + // To maintain the consistency of CRC value across the platforms(WINDOWS and LINUX), we are + // using UTF-16 string in CRC generation. + + utf16WString utf16Ws = utf32WString2utf16WString(location); + unsigned int hash = Util::Crc32(utf16Ws.c_str(),length); + stmtComponentFileDetails->BindInt(2,hash); stmtComponentFileDetails->BindStr(3,aLocation); stmtComponentFileDetails->ExecuteStatement(); @@ -447,9 +607,9 @@ } else { - std::string str = Util::wstring2string(filePropIter->iValue); + std::string str = wstring2string(filePropIter->iValue); std::string decodedString = Util::Base64Decode(str); - stmtFileProperty->BindBinary(3, str); + stmtFileProperty->BindBinary(3, decodedString); stmtFileProperty->BindInt(4, 1); } @@ -458,6 +618,442 @@ } } + +void CDbLayer::AddApplicationRegistrationInfo( int aComponentId, const std::vector& aApplicationRegistrationInfo) + { + LOGENTER("CDbLayer::AddApplicationRegistrationInfo()"); + int appflag = 0; + int appUid = 0; + int error = 0; + + for(CompApplicationRegistrationInfoIterator compApplicationRegistrationInfoIter = aApplicationRegistrationInfo.begin(); compApplicationRegistrationInfoIter != aApplicationRegistrationInfo.end() ; ++compApplicationRegistrationInfoIter ) + { + try { + appflag = 0; + appUid = AddAppAttribute(aComponentId, compApplicationRegistrationInfoIter->iApplicationAttribute); + } + catch(CException& aException) + { + LOGERROR(aException.GetMessageA()); + LOGERROR("one of AddAppAttribute is already present in database"); + appflag = 1; + error = 1; + } + + if(appflag) + continue; + + if (appUid != 0) + { + AddFileOwnershipInfo(appUid, compApplicationRegistrationInfoIter->iFileOwnershipInfo); + AddServiceInfo(appUid, compApplicationRegistrationInfoIter->iApplicationServiceInfo); + AddAppLocalizableInfo(appUid, compApplicationRegistrationInfoIter->iApplicationLocalizableInfo); + AddProperty(appUid, compApplicationRegistrationInfoIter->iApplicationProperty); + } + else + { + std::string errMsg = "AppUid is null."; + LOGERROR(errMsg); + throw CException(errMsg,ExceptionCodes::ESqlArgumentError); + } + } + + if(error) + { + std::string errMsg = "Duplicate entry present in database."; + LOGERROR(errMsg); + throw CException(errMsg,ExceptionCodes::EFileExists); + } + + LOGEXIT("CDbLayer::AddApplicationRegistrationInfo()"); + } + +int CDbLayer::AddAppAttribute( int aComponentId, const std::vector& aAppAttribute) + { + LOGENTER("CDbLayer::AddAppAttribute()"); + std::string insertAppAttributes; + + insertAppAttributes = "INSERT INTO AppRegistrationInfo(AppUid,ComponentId,AppFile,TypeId,Attributes,Hidden,Embeddable,Newfile,Launch,GroupName,DefaultScreenNumber) VALUES(?,?,?,?,?,?,?,?,?,?,?);"; + std::auto_ptr stmtAppAttribute(iScrDbHandler->PrepareStatement(insertAppAttributes)); + + stmtAppAttribute->BindInt64(2, aComponentId); + + //Assigning Default Values + TInt64 intVal = 0; + stmtAppAttribute->BindInt64(1, intVal); //AppUid + stmtAppAttribute->BindInt64(4, intVal); //TypeId + stmtAppAttribute->BindInt64(5, intVal); //Attributes + stmtAppAttribute->BindInt64(6, intVal); //Hidden + stmtAppAttribute->BindInt64(7, intVal); //Embeddable + stmtAppAttribute->BindInt64(8, intVal); //Newfile + stmtAppAttribute->BindInt64(9, intVal); //Launch + stmtAppAttribute->BindInt64(11, intVal); //DefaultScreenNumber + std::wstring strVal(L""); + stmtAppAttribute->BindStr(3, strVal); //AppFile + stmtAppAttribute->BindStr(10, strVal); //GroupName + + int appUid = 0; + std::string appfile; + for(ApplicationAttributeIterator applicationAttributeIter = aAppAttribute.begin(); applicationAttributeIter != aAppAttribute.end() ; ++applicationAttributeIter ) + { + if (applicationAttributeIter->iName == L"AppUid") + { + LOGINFO("CDbLayer::AddAppAttribute()- appuid"); + TInt64 intValue = Util::WideCharToInt64(applicationAttributeIter->iValue.c_str()); + stmtAppAttribute->BindInt64(1, intValue); + appUid = intValue; + } + else if (applicationAttributeIter->iName == L"AppFile") + { + stmtAppAttribute->BindStr(3, applicationAttributeIter->iValue); + if (applicationAttributeIter->iValue.length() == 0) + { + std::string errMsg = "Invalid app file."; + LOGERROR(errMsg); + throw CException(errMsg,ExceptionCodes::ESqlArgumentError); + } + + } + else if (applicationAttributeIter->iName == L"TypeId") + { + TInt64 intValue = Util::WideCharToInt64(applicationAttributeIter->iValue.c_str()); + stmtAppAttribute->BindInt64(4, intValue); + } + else if (applicationAttributeIter->iName == L"Attributes") + { + TInt64 intValue = Util::WideCharToInt64(applicationAttributeIter->iValue.c_str()); + stmtAppAttribute->BindInt64(5, intValue); + } + else if (applicationAttributeIter->iName == L"Hidden") + { + TInt64 intValue = Util::WideCharToInt64(applicationAttributeIter->iValue.c_str()); + stmtAppAttribute->BindInt64(6, intValue); + } + else if (applicationAttributeIter->iName == L"Embeddable") + { + TInt64 intValue = Util::WideCharToInt64(applicationAttributeIter->iValue.c_str()); + stmtAppAttribute->BindInt64(7, intValue); + } + else if (applicationAttributeIter->iName == L"Newfile") + { + TInt64 intValue = Util::WideCharToInt64(applicationAttributeIter->iValue.c_str()); + stmtAppAttribute->BindInt64(8, intValue); + } + else if (applicationAttributeIter->iName == L"Launch") + { + TInt64 intValue = Util::WideCharToInt64(applicationAttributeIter->iValue.c_str()); + stmtAppAttribute->BindInt64(9, intValue); + } + else if (applicationAttributeIter->iName == L"GroupName") + { + stmtAppAttribute->BindStr(10, applicationAttributeIter->iValue); + } + else if (applicationAttributeIter->iName == L"DefaultScreenNumber") + { + TInt64 intValue = Util::WideCharToInt64(applicationAttributeIter->iValue.c_str()); + stmtAppAttribute->BindInt64(11, intValue); + } + else + { + std::string errMsg = "Invalid application attribute."; + LOGERROR(errMsg); + throw CException(errMsg,ExceptionCodes::ESqlArgumentError); + } + } + + try + { + stmtAppAttribute->ExecuteStatement(); + stmtAppAttribute->Reset(); + } + catch(CException& aException) + { + LOGERROR(aException.GetMessageA()); + LOGERROR("AppUid Already Present in Database"); + } + + LOGEXIT("CDbLayer::AddAppAttribute()"); + return appUid; + } + +void CDbLayer::AddFileOwnershipInfo( int aAppUid, const std::vector& aFileOwnershipInfo) + { + LOGENTER("CDbLayer::AddFileOwnershipInfo()"); + std::string insertFileOwnershipInfo; + + for(ConstWstringIterator cWstringIter = aFileOwnershipInfo.begin(); cWstringIter != aFileOwnershipInfo.end() ; ++cWstringIter ) + { + insertFileOwnershipInfo = "INSERT INTO FileOwnershipInfo(AppUid,FileName) VALUES(?,?);"; + std::auto_ptr stmtFileOwnershipInfo(iScrDbHandler->PrepareStatement(insertFileOwnershipInfo)); + + stmtFileOwnershipInfo->BindInt64(1, aAppUid); + stmtFileOwnershipInfo->BindStr(2, *cWstringIter); + + stmtFileOwnershipInfo->ExecuteStatement(); + stmtFileOwnershipInfo->Reset(); + } + LOGEXIT("CDbLayer::AddFileOwnershipInfo()"); + } + +void CDbLayer::AddServiceInfo( int aAppUid, const std::vector& aApplicationServiceInfo) + { + LOGENTER("CDbLayer::AddServiceInfo()"); + std::string insertServiceInfo; + + for(ApplicationServiceInfoIterator serviceInfoIter = aApplicationServiceInfo.begin(); serviceInfoIter != aApplicationServiceInfo.end() ; ++serviceInfoIter ) + { + insertServiceInfo = "INSERT INTO ServiceInfo(AppUid,Uid) VALUES(?,?);"; + std::auto_ptr stmtServiceInfo(iScrDbHandler->PrepareStatement(insertServiceInfo)); + + stmtServiceInfo->BindInt64(1, aAppUid); + stmtServiceInfo->BindInt64(2, serviceInfoIter->iUid); + stmtServiceInfo->ExecuteStatement(); + stmtServiceInfo->Reset(); + + int serviceId = iScrDbHandler->LastInsertedId(); + std::string insertDataType; + + const std::vector& datatype = serviceInfoIter->iDataType; + for(ApplicationDataTypeIterator dataTypeIter = datatype.begin(); dataTypeIter != datatype.end() ; ++dataTypeIter ) + { + insertDataType = "INSERT INTO DataType(ServiceId,Priority,Type) VALUES(?,?,?);"; + std::auto_ptr stmtDataType(iScrDbHandler->PrepareStatement(insertDataType)); + + stmtDataType->BindInt64(1, serviceId); + stmtDataType->BindInt64(2, dataTypeIter->iPriority); + #ifdef __TOOLS2_LINUX__ + stmtDataType->BindStr(3, dataTypeIter->iType, avoidSlashConversion); + #else + stmtDataType->BindStr(3, dataTypeIter->iType); + #endif + + stmtDataType->ExecuteStatement(); + stmtDataType->Reset(); + } + } + LOGEXIT("CDbLayer::AddServiceInfo()"); + } + +void CDbLayer::AddAppLocalizableInfo( int aAppUid, const std::vector& aApplicationLocalizableInfo) +{ + LOGENTER("CDbLayer::AddAppLocalizableInfo()"); + for(ApplicationLocalizableInfoIterator localizableInfoIter = aApplicationLocalizableInfo.begin(); localizableInfoIter != aApplicationLocalizableInfo.end() ; ++localizableInfoIter ) + { + AddLocalizableAttribute(aAppUid, localizableInfoIter->iLocalizableAttribute); + int localAppInfoId = iScrDbHandler->LastInsertedId(); + AddViewData(localAppInfoId, localizableInfoIter->iViewData); + } + LOGEXIT("CDbLayer::AddAppLocalizableInfo()"); +} + +void CDbLayer::AddLocalizableAttribute( int aAppUid, const std::vector& aApplicationLocalizableAttribute) +{ + LOGENTER("CDbLayer::AddLocalizableAttribute()"); + std::string insertAppLocalizableInfo; + + insertAppLocalizableInfo = "INSERT INTO LocalizableAppInfo(AppUid,ShortCaption,GroupName,Locale,CaptionAndIconId) VALUES(?,?,?,?,?);"; + std::auto_ptr stmtAppLocalizableInfo(iScrDbHandler->PrepareStatement(insertAppLocalizableInfo)); + + //Assigning default value + TInt64 intVal = 0; + stmtAppLocalizableInfo->BindInt64(4, intVal); //Locale + stmtAppLocalizableInfo->BindInt64(5, intVal); //CaptionAndIconId + std::wstring strVal(L""); + stmtAppLocalizableInfo->BindStr(2, strVal); //ShortCaption + stmtAppLocalizableInfo->BindStr(3, strVal); //GroupName + + std::string insertCaptionAndIconInfo; + + insertCaptionAndIconInfo = "INSERT INTO CaptionAndIconInfo(Caption,NumberOfIcons,IconFile) VALUES(?,?,?);"; + std::auto_ptr stmtCaptionAndIconInfo(iScrDbHandler->PrepareStatement(insertCaptionAndIconInfo)); + + //Assigning default value + stmtCaptionAndIconInfo->BindStr(1, strVal); //Caption + stmtCaptionAndIconInfo->BindInt64(2, intVal); //NumberOfIcons + stmtCaptionAndIconInfo->BindStr(3, strVal); //IconFile + + + bool captionAndIconInfoPresent = 0; + //for every TLocalizableAttribute + stmtAppLocalizableInfo->BindInt64(1, aAppUid); + for(LocalizableAttributeIterator localizableAttributeIter = aApplicationLocalizableAttribute.begin(); localizableAttributeIter != aApplicationLocalizableAttribute.end() ; ++localizableAttributeIter ) + { + if (localizableAttributeIter->iName == L"ShortCaption") + { + stmtAppLocalizableInfo->BindStr(2, localizableAttributeIter->iValue); + } + else if(localizableAttributeIter->iName == L"GroupName") + { + stmtAppLocalizableInfo->BindStr(3, localizableAttributeIter->iValue); + } + else if(localizableAttributeIter->iName == L"Locale") + { + TInt64 intValue = Util::WideCharToInt64(localizableAttributeIter->iValue.c_str()); + stmtAppLocalizableInfo->BindInt64(4, intValue); + } + else if(localizableAttributeIter->iName == L"Caption") + { + stmtCaptionAndIconInfo->BindStr(1, localizableAttributeIter->iValue); + captionAndIconInfoPresent = 1; + } + else if(localizableAttributeIter->iName == L"NumberOfIcons") + { + TInt64 intValue = Util::WideCharToInt64(localizableAttributeIter->iValue.c_str()); + stmtCaptionAndIconInfo->BindInt64(2, intValue); + captionAndIconInfoPresent = 1; + } + else if(localizableAttributeIter->iName == L"IconFile") + { + stmtCaptionAndIconInfo->BindStr(3, localizableAttributeIter->iValue); + captionAndIconInfoPresent = 1; + } + else + { + std::string errMsg = "Invalid localizable attribute."; + LOGERROR(errMsg); + throw CException(errMsg,ExceptionCodes::ESqlArgumentError); + } + } + if (captionAndIconInfoPresent) + { + stmtCaptionAndIconInfo->ExecuteStatement(); + stmtCaptionAndIconInfo->Reset(); + int captionAndIconIdForLocalizableInfo = iScrDbHandler->LastInsertedId(); + stmtAppLocalizableInfo->BindInt64(5, captionAndIconIdForLocalizableInfo); + } + stmtAppLocalizableInfo->ExecuteStatement(); + stmtAppLocalizableInfo->Reset(); + LOGEXIT("CDbLayer::AddLocalizableAttribute()"); +} + + +void CDbLayer::AddViewData( int alocalAppInfoId, const std::vector& aViewData) +{ + LOGENTER("CDbLayer::AddViewData()"); + + for(ViewDataIterator viewDataIter = aViewData.begin(); viewDataIter != aViewData.end() ; ++viewDataIter ) + { + AddViewDataAttributes(alocalAppInfoId, viewDataIter->iViewDataAttributes); + } + + LOGEXIT("CDbLayer::AddViewData()"); +} + + +void CDbLayer::AddViewDataAttributes( int alocalAppInfoId, const std::vector& aViewDataAttribute) + { + LOGENTER("CDbLayer::AddViewData()"); + std::string insertViewData; + + insertViewData = "INSERT INTO ViewData(LocalAppInfoId,Uid,ScreenMode,CaptionAndIconId) VALUES(?,?,?,?);"; + std::auto_ptr stmtViewData(iScrDbHandler->PrepareStatement(insertViewData)); + + + //Assigning Default Value + TInt64 intVal = 0; + stmtViewData->BindInt64(2, intVal); //Uid + stmtViewData->BindInt64(3, intVal); //ScreenMode + stmtViewData->BindInt64(4, intVal); //CaptionAndIconId + + std::string insertCaptionAndIconInfo; + + insertCaptionAndIconInfo = "INSERT INTO CaptionAndIconInfo(Caption,NumberOfIcons,IconFile) VALUES(?,?,?);"; + std::auto_ptr stmtCaptionAndIconInfo(iScrDbHandler->PrepareStatement(insertCaptionAndIconInfo)); + + //Assigning Default Value + stmtCaptionAndIconInfo->BindInt64(2, intVal); //NumberOfIcons + std::wstring strVal(L""); + stmtCaptionAndIconInfo->BindStr(1, strVal); //Caption + stmtCaptionAndIconInfo->BindStr(3, strVal); //IconFile + + bool captionAndIconInfoPresent = 0; + //for every TViewData + stmtViewData->BindInt64(1, alocalAppInfoId); + + for(ViewDataAttributeIterator viewDataIter = aViewDataAttribute.begin(); viewDataIter != aViewDataAttribute.end() ; ++viewDataIter ) + { + if (viewDataIter->iName == L"Uid") + { + TInt64 intValue = Util::WideCharToInt64(viewDataIter->iValue.c_str()); + stmtViewData->BindInt64(2, intValue); + } + else if(viewDataIter->iName == L"ScreenMode") + { + TInt64 intValue = Util::WideCharToInt64(viewDataIter->iValue.c_str()); + stmtViewData->BindInt64(3, intValue); + } + else if(viewDataIter->iName == L"Caption") + { + stmtCaptionAndIconInfo->BindStr(1, viewDataIter->iValue); + captionAndIconInfoPresent = 1; + } + else if(viewDataIter->iName == L"NumberOfIcons") + { + TInt64 intValue = Util::WideCharToInt64(viewDataIter->iValue.c_str()); + stmtCaptionAndIconInfo->BindInt64(2, intValue); + captionAndIconInfoPresent = 1; + } + else if(viewDataIter->iName == L"IconFile") + { + stmtCaptionAndIconInfo->BindStr(3, viewDataIter->iValue); + captionAndIconInfoPresent = 1; + } + else + { + std::string errMsg = "Invalid view data attribute."; + LOGERROR(errMsg); + throw CException(errMsg,ExceptionCodes::ESqlArgumentError); + } + } + if (captionAndIconInfoPresent) + { + stmtCaptionAndIconInfo->ExecuteStatement(); + stmtCaptionAndIconInfo->Reset(); + int captionAndIconIdForViewData = iScrDbHandler->LastInsertedId(); + stmtViewData->BindInt64(4, captionAndIconIdForViewData); + } + stmtViewData->ExecuteStatement(); + stmtViewData->Reset(); + LOGEXIT("CDbLayer::AddViewData()"); + } + +void CDbLayer::AddProperty( int aAppUid, const std::vector& aApplicationProperty) + { + LOGENTER("CDbLayer::AddProperty()"); + std::string insertApplicationProperty; + + for(ApplicationPropertyIterator appPropertyIter = aApplicationProperty.begin(); appPropertyIter != aApplicationProperty.end() ; ++appPropertyIter ) + { + + insertApplicationProperty = "INSERT INTO AppProperties(AppUid,Locale,Name,ServiceUid,IntValue,StrValue,IsStr8Bit) VALUES(?,?,?,?,?,?,?);"; + std::auto_ptr stmtAppProperty(iScrDbHandler->PrepareStatement(insertApplicationProperty)); + + stmtAppProperty->BindInt64(1, aAppUid); + stmtAppProperty->BindInt(2, appPropertyIter->iLocale); + stmtAppProperty->BindStr(3, appPropertyIter->iName); + stmtAppProperty->BindInt(4, appPropertyIter->iServiceUid); + stmtAppProperty->BindInt(5, appPropertyIter->iIntValue); + + if(appPropertyIter->iIsStr8Bit) + { + std::string str; + int len = appPropertyIter->iStrValue.length(); + str.assign(appPropertyIter->iStrValue.c_str(),appPropertyIter->iStrValue.c_str()+len); + stmtAppProperty->BindBinary(6, str); + } + else + { + stmtAppProperty->BindStr(6, appPropertyIter->iStrValue); + } + + stmtAppProperty->BindInt(7, appPropertyIter->iIsStr8Bit); + + stmtAppProperty->ExecuteStatement(); + stmtAppProperty->Reset(); + } + LOGEXIT("CDbLayer::AddProperty()"); + } + void CDbLayer::ExecuteStatement(const std::string& aStmtStr) { std::auto_ptr stmt(iScrDbHandler->PrepareStatement(aStmtStr));