secureswitools/swisistools/source/interpretsislib/dbhelper.cpp
changeset 25 98b66e4fb0be
parent 0 ba25891c3a9e
child 42 d17dc5398051
equal deleted inserted replaced
24:84a16765cd86 25:98b66e4fb0be
    29 #include <sstream>
    29 #include <sstream>
    30 #include <stdexcept>
    30 #include <stdexcept>
    31 
    31 
    32 const int DbHelper::Absent = -1;
    32 const int DbHelper::Absent = -1;
    33 
    33 
       
    34 DbHelper::~DbHelper()
       
    35 	{
       
    36 	delete iScrDbHandler;
       
    37 	}
       
    38 
    34 DbHelper::DbHelper( const std::wstring& aDrivePath, bool aIsSystemDrive)
    39 DbHelper::DbHelper( const std::wstring& aDrivePath, bool aIsSystemDrive)
    35 	{
    40 	{
    36 	std::string dllName = "sqlite3.dll";
    41 	std::string dllName = "sqlite3.dll";
    37 	std::string dbName; 
    42 	std::string dbName; 
    38 	
    43 	
    67 		
    72 		
    68 	TInt32 uid = stmtUid->IntColumn(0);
    73 	TInt32 uid = stmtUid->IntColumn(0);
    69 	return (uid == aUid);
    74 	return (uid == aUid);
    70 	}
    75 	}
    71 
    76 
       
    77 TBool DbHelper::IsAppUidInstalled(TUint32 aAppUid) const
       
    78 	{
       
    79 	std::string selectUid("SELECT AppFile FROM AppRegistrationInfo WHERE AppUid=?;");
       
    80 	std::auto_ptr<CStatement> stmtUid(iScrDbHandler->PrepareStatement(selectUid));
       
    81 		
       
    82 	stmtUid->BindInt(1, aAppUid);
       
    83 	
       
    84 	if(!stmtUid->ProcessNextRow())
       
    85 		return false;
       
    86 		
       
    87 	return true;
       
    88 	}
       
    89 
    72 TInt32 DbHelper::GetComponentId(TInt32 aUid, const std::wstring aPackageName, const std::wstring aVendorName ) const
    90 TInt32 DbHelper::GetComponentId(TInt32 aUid, const std::wstring aPackageName, const std::wstring aVendorName ) const
    73 	{
    91 	{
    74 	std::string selectUid("SELECT ComponentId from ComponentProperties where Name='CompUid' and IntValue=? and ComponentId IN (SELECT ComponentId FROM \
    92 	std::string selectUid("SELECT ComponentId from ComponentProperties where Name='CompUid' and IntValue=? and ComponentId IN (SELECT ComponentId FROM \
    75 	ComponentProperties WHERE Name='CompUniqueVendorName' and StrValue=? and ComponentId IN (SELECT ComponentId FROM ComponentLocalizables WHERE Name=?));");
    93 	ComponentProperties WHERE Name='CompUniqueVendorName' and StrValue=? and ComponentId IN (SELECT ComponentId FROM ComponentLocalizables WHERE Name=?));");
    76 	std::auto_ptr<CStatement> stmtCompid(iScrDbHandler->PrepareStatement(selectUid));
    94 	std::auto_ptr<CStatement> stmtCompid(iScrDbHandler->PrepareStatement(selectUid));
   248 	return GetComponentPropertyIntValue(aComponentId,DbConstants::CompIndex);
   266 	return GetComponentPropertyIntValue(aComponentId,DbConstants::CompIndex);
   249 	}
   267 	}
   250 
   268 
   251 void DbHelper::RemoveEntry( TInt32 aComponentId ) const
   269 void DbHelper::RemoveEntry( TInt32 aComponentId ) const
   252 	{
   270 	{
       
   271 
       
   272 	std::vector<TInt32> appUidList = GetAppRegistrationInfoAppUid(aComponentId);
       
   273 	std::vector<TInt32> ::iterator appUidIter;
       
   274 	for( appUidIter = appUidList.begin(); appUidIter != appUidList.end() ; ++appUidIter )
       
   275 	{
       
   276 		// delete FileOwnershipInfo
       
   277 		std::string delFileOwnerInfo("DELETE FROM FileOwnershipInfo WHERE AppUid=?;");
       
   278 		std::auto_ptr<CStatement> stmtdelFileOwnerInfo(iScrDbHandler->PrepareStatement(delFileOwnerInfo));
       
   279 		stmtdelFileOwnerInfo->BindInt(1, *appUidIter);
       
   280 		stmtdelFileOwnerInfo->ExecuteStatement();
       
   281 
       
   282 		// delete AppProperties
       
   283 		std::string delAppProperties("DELETE FROM AppProperties WHERE AppUid=?;");
       
   284 		std::auto_ptr<CStatement> stmtAppProperties(iScrDbHandler->PrepareStatement(delAppProperties));
       
   285 		stmtAppProperties->BindInt(1, *appUidIter);
       
   286 		stmtAppProperties->ExecuteStatement();
       
   287 
       
   288 		std::vector<TInt32> serviceIdList = GetServiceInfoServiceID(*appUidIter);
       
   289 		
       
   290 		std::vector<TInt32> ::iterator serviceIdIter;
       
   291 		for( serviceIdIter = serviceIdList.begin(); serviceIdIter != serviceIdList.end() ; ++serviceIdIter )
       
   292 		{
       
   293 			// delete DataType
       
   294 			std::string delDataType("DELETE FROM DataType WHERE ServiceId=?;");
       
   295 			std::auto_ptr<CStatement> stmtDataType(iScrDbHandler->PrepareStatement(delDataType));
       
   296 			stmtDataType->BindInt(1, *serviceIdIter);
       
   297 			stmtDataType->ExecuteStatement();
       
   298 		}
       
   299 
       
   300 		// delete ServiceInfo
       
   301 		std::string delServiceInfo("DELETE FROM ServiceInfo WHERE AppUid=?;");
       
   302 		std::auto_ptr<CStatement> stmtServiceInfo(iScrDbHandler->PrepareStatement(delServiceInfo));
       
   303 		stmtServiceInfo->BindInt(1, *appUidIter);
       
   304 		stmtServiceInfo->ExecuteStatement();
       
   305 
       
   306 		std::vector<TInt32> localAppInfoIdList = GetLocalAppInfoID(*appUidIter);
       
   307 		
       
   308 		std::vector<TInt32> ::iterator localAppInfoIdIter;
       
   309 		for( localAppInfoIdIter = localAppInfoIdList.begin(); localAppInfoIdIter != localAppInfoIdList.end() ; ++localAppInfoIdIter )
       
   310 		{
       
   311 			std::vector<TInt32> viewDataCaptionIdList = GetViewDataCaptionAndIconID(*localAppInfoIdIter);
       
   312 			
       
   313 			std::vector<TInt32> ::iterator viewDataCaptionIdIter;
       
   314 			for( viewDataCaptionIdIter = viewDataCaptionIdList.begin(); viewDataCaptionIdIter != viewDataCaptionIdList.end() ; ++viewDataCaptionIdIter )
       
   315 			{
       
   316 				// delete CaptionAndIconInfo
       
   317 				std::string delCaptionInfo("DELETE FROM CaptionAndIconInfo WHERE CaptionAndIconId=?;");
       
   318 				std::auto_ptr<CStatement> stmtCaptionInfo(iScrDbHandler->PrepareStatement(delCaptionInfo));
       
   319 				stmtCaptionInfo->BindInt(1, *viewDataCaptionIdIter);
       
   320 				stmtCaptionInfo->ExecuteStatement();
       
   321 			}
       
   322 
       
   323 			// delete ViewData
       
   324 			std::string delViewData("DELETE FROM ViewData WHERE LocalAppInfoId=?;");
       
   325 			std::auto_ptr<CStatement> stmtViewData(iScrDbHandler->PrepareStatement(delViewData));
       
   326 			stmtViewData->BindInt(1, *localAppInfoIdIter);
       
   327 			stmtViewData->ExecuteStatement();
       
   328 		}
       
   329 
       
   330 		std::vector<TInt32> LocalCaptionIdList = GetLocalCaptionAndIconID(*appUidIter);
       
   331 		std::vector<TInt32> ::iterator LocalCaptionIdIter;
       
   332 		for( LocalCaptionIdIter = LocalCaptionIdList.begin(); LocalCaptionIdIter != LocalCaptionIdList.end() ; ++LocalCaptionIdIter )
       
   333 		{
       
   334 			// delete CaptionAndIconInfo
       
   335 			std::string delCaptionInfo("DELETE FROM CaptionAndIconInfo WHERE CaptionAndIconId=?;");
       
   336 			std::auto_ptr<CStatement> stmtCaptionInfo(iScrDbHandler->PrepareStatement(delCaptionInfo));
       
   337 			stmtCaptionInfo->BindInt(1, *LocalCaptionIdIter);
       
   338 			stmtCaptionInfo->ExecuteStatement();
       
   339 		}
       
   340 
       
   341 		// delete LocalizableAppInfo
       
   342 		std::string delLocalizableAppInfo("DELETE FROM LocalizableAppInfo WHERE AppUid=?;");
       
   343 		std::auto_ptr<CStatement> stmtLocalizableAppInfo(iScrDbHandler->PrepareStatement(delLocalizableAppInfo));
       
   344 		stmtLocalizableAppInfo->BindInt(1, *appUidIter);
       
   345 		stmtLocalizableAppInfo->ExecuteStatement();
       
   346 
       
   347 	}
       
   348 
       
   349 	// delete AppRegistrationInfo
       
   350 	std::string delAppRegistrationInfo("DELETE FROM AppRegistrationInfo WHERE ComponentId=?;");
       
   351 	std::auto_ptr<CStatement> stmtAppRegistrationInfo(iScrDbHandler->PrepareStatement(delAppRegistrationInfo));
       
   352 	stmtAppRegistrationInfo->BindInt(1, aComponentId);
       
   353 	stmtAppRegistrationInfo->ExecuteStatement();
       
   354 
       
   355 	
   253 	// delete component properties
   356 	// delete component properties
   254 	std::string delCompProps("DELETE FROM ComponentProperties WHERE ComponentId=?;");
   357 	std::string delCompProps("DELETE FROM ComponentProperties WHERE ComponentId=?;");
   255 	std::auto_ptr<CStatement> stmtDelCompProps(iScrDbHandler->PrepareStatement(delCompProps));
   358 	std::auto_ptr<CStatement> stmtDelCompProps(iScrDbHandler->PrepareStatement(delCompProps));
   256 	stmtDelCompProps->BindInt(1, aComponentId);
   359 	stmtDelCompProps->BindInt(1, aComponentId);
   257 	stmtDelCompProps->ExecuteStatement();
   360 	stmtDelCompProps->ExecuteStatement();
   842 		return aDefaultValue;
   945 		return aDefaultValue;
   843 
   946 
   844 	return stmtCompProperty->IntColumn(0);
   947 	return stmtCompProperty->IntColumn(0);
   845 	}
   948 	}
   846 
   949 
       
   950 std::vector<TInt32> DbHelper::GetServiceInfoServiceID(TInt32 aAppUid) const
       
   951 {
       
   952 	std::vector<TInt32> serviceIdList;
       
   953 	std::string selectServiceId("SELECT ServiceId FROM ServiceInfo WHERE AppUid=?;");
       
   954 	std::auto_ptr<CStatement> stmtServiceId(iScrDbHandler->PrepareStatement(selectServiceId));
       
   955 	
       
   956 	stmtServiceId->BindInt(1, aAppUid);
       
   957 	while(stmtServiceId->ProcessNextRow())
       
   958 	{
       
   959 		serviceIdList.push_back(stmtServiceId->IntColumn(0));
       
   960 	}
       
   961 	
       
   962 	return serviceIdList;
       
   963 }
       
   964 
       
   965 
       
   966 std::vector<TInt32> DbHelper::GetLocalAppInfoID(TInt32 aAppUid) const
       
   967 {
       
   968 	std::vector<TInt32> localAppInfoIdList;
       
   969 	std::string selectLocalAppInfoId("SELECT LocalAppInfoId FROM LocalizableAppInfo WHERE AppUid=?;");
       
   970 	std::auto_ptr<CStatement> stmtLocalAppInfoId(iScrDbHandler->PrepareStatement(selectLocalAppInfoId));
       
   971 	
       
   972 	stmtLocalAppInfoId->BindInt(1, aAppUid);
       
   973 	while(stmtLocalAppInfoId->ProcessNextRow())
       
   974 	{
       
   975 		localAppInfoIdList.push_back(stmtLocalAppInfoId->IntColumn(0));
       
   976 	}
       
   977 	
       
   978 	return localAppInfoIdList;
       
   979 }
       
   980 
       
   981 
       
   982 std::vector<TInt32> DbHelper::GetLocalCaptionAndIconID(TInt32 aAppUid) const
       
   983 {
       
   984 	std::vector<TInt32> localCaptionAndIconIdList;
       
   985 	std::string selectLocalCaptionAndIconId("SELECT CaptionAndIconId FROM LocalizableAppInfo WHERE AppUid=?;");
       
   986 	std::auto_ptr<CStatement> stmtLocalCaptionAndIconId(iScrDbHandler->PrepareStatement(selectLocalCaptionAndIconId));
       
   987 	
       
   988 	stmtLocalCaptionAndIconId->BindInt(1, aAppUid);
       
   989 	while(stmtLocalCaptionAndIconId->ProcessNextRow())
       
   990 	{
       
   991 		localCaptionAndIconIdList.push_back(stmtLocalCaptionAndIconId->IntColumn(0));
       
   992 	}
       
   993 	
       
   994 	return localCaptionAndIconIdList;
       
   995 }
       
   996 
       
   997 
       
   998 std::vector<TInt32> DbHelper::GetViewDataCaptionAndIconID(TInt32 aLocalAppInfoID) const
       
   999 {
       
  1000 	std::vector<TInt32> viewCaptionIdList;
       
  1001 	std::string selectViewCaptionId("SELECT CaptionAndIconId FROM ViewData WHERE LocalAppInfoId=?;");
       
  1002 	std::auto_ptr<CStatement> stmtViewCaptionId(iScrDbHandler->PrepareStatement(selectViewCaptionId));
       
  1003 	
       
  1004 	stmtViewCaptionId->BindInt(1, aLocalAppInfoID);
       
  1005 	while(stmtViewCaptionId->ProcessNextRow())
       
  1006 	{
       
  1007 		viewCaptionIdList.push_back(stmtViewCaptionId->IntColumn(0));
       
  1008 	}
       
  1009 	
       
  1010 	return viewCaptionIdList;
       
  1011 }
       
  1012 
       
  1013 
       
  1014 std::vector<TInt32> DbHelper::GetAppRegistrationInfoAppUid(TInt32 aComponentId) const
       
  1015 {
       
  1016 	std::vector<TInt32> appUidList;
       
  1017 	std::string selectAppUid("SELECT AppUid FROM AppRegistrationInfo WHERE ComponentId=?;");
       
  1018 	std::auto_ptr<CStatement> stmtAppUid(iScrDbHandler->PrepareStatement(selectAppUid));
       
  1019 
       
  1020 	stmtAppUid->BindInt(1, aComponentId);
       
  1021 	while(stmtAppUid->ProcessNextRow())
       
  1022 	{
       
  1023 		appUidList.push_back(stmtAppUid->IntColumn(0));
       
  1024 	}
       
  1025 
       
  1026 	return appUidList;
       
  1027 }
       
  1028 
   847 TInt32 DbHelper::GetComponentPropertyIntFormattedValue(TInt32 aComponentId, std::wstring aComponentPropertyName, TInt32 aIntFormatter) const
  1029 TInt32 DbHelper::GetComponentPropertyIntFormattedValue(TInt32 aComponentId, std::wstring aComponentPropertyName, TInt32 aIntFormatter) const
   848 	{
  1030 	{
   849 	TInt32 propertyValue = 0;
  1031 	TInt32 propertyValue = 0;
   850 	
  1032 	
   851 	std::string selectIntProperty("SELECT IntValue FROM ComponentProperties WHERE ComponentId=? and Name=?;");
  1033 	std::string selectIntProperty("SELECT IntValue FROM ComponentProperties WHERE ComponentId=? and Name=?;");