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 |
|
42 #ifdef __LINUX__ |
|
43 std::string dllName = "sqlite-3.6.1.so"; |
|
44 #else |
|
45 std::string dllName = "sqlite3.dll"; |
|
46 #endif |
37 std::string dbName; |
47 std::string dbName; |
38 |
48 |
39 if (aIsSystemDrive) |
49 if (aIsSystemDrive) |
|
50 #ifdef __TOOLS2_LINUX__ |
|
51 dbName = wstring2string(aDrivePath) + "/sys/install/scr/scr.db"; |
|
52 #else |
40 dbName = wstring2string(aDrivePath) + "\\sys\\install\\scr\\scr.db"; |
53 dbName = wstring2string(aDrivePath) + "\\sys\\install\\scr\\scr.db"; |
|
54 #endif |
41 else |
55 else |
|
56 #ifdef __TOOLS2_LINUX__ |
|
57 dbName = wstring2string(aDrivePath) + "/sys/install/scr/provisioned/scr.db"; |
|
58 #else |
42 dbName = wstring2string(aDrivePath) + "\\sys\\install\\scr\\provisioned\\scr.db"; |
59 dbName = wstring2string(aDrivePath) + "\\sys\\install\\scr\\provisioned\\scr.db"; |
|
60 #endif |
|
61 |
|
62 std::wstring wdbname(string2wstring(dbName)); |
|
63 //Create the SCR DB if not present in the System Drive |
|
64 if(!FileExists(wdbname)) |
|
65 { |
|
66 const char* epocRoot = getenv("EPOCROOT"); |
|
67 if(NULL == epocRoot) |
|
68 { |
|
69 std::string emsg(" EPOCROOT environment variable not specified."); |
|
70 int retCode = ExceptionCodes::EEnvNotSpecified; |
|
71 throw InterpretSisError(emsg,retCode); |
|
72 } |
|
73 std::string epocRootStr(epocRoot); |
|
74 |
|
75 #ifndef __TOOLS2_LINUX__ |
|
76 std::wstring swEnvInfo = string2wstring(epocRootStr) + L"epoc32\\tools\\create_db.xml"; |
|
77 #else |
|
78 std::wstring swEnvInfo = string2wstring(epocRootStr) + L"epoc32/tools/create_db.xml"; |
|
79 #endif |
|
80 |
|
81 if(FileExists(swEnvInfo)) |
|
82 { |
|
83 #ifdef __TOOLS2_LINUX__ |
|
84 std::string executable = "scrtool"; |
|
85 #else |
|
86 std::string executable = "scrtool.exe"; |
|
87 #endif |
|
88 std::string command; |
|
89 |
|
90 command = executable + " -c " + dbName + " -f " + wstring2string(swEnvInfo); |
|
91 |
|
92 std::cout << "Creating DB : " << command << std::endl; |
|
93 |
|
94 int error = system(command.c_str()); |
|
95 if(error != 0) |
|
96 { |
|
97 std::string err = "Scrtool failed to create the database."; |
|
98 throw InterpretSisError(err, DATABASE_UPDATE_FAILED); |
|
99 } |
|
100 } |
|
101 else |
|
102 { |
|
103 LERROR(L"Failed to create the database."); |
|
104 std::string emessage(" XML file /epoc32/tools/create_db.xml which contains software environment information is not found."); |
|
105 int returnCode = ExceptionCodes::EFileNotPresent; |
|
106 throw InterpretSisError(emessage,returnCode); |
|
107 } |
|
108 } |
43 |
109 |
44 try |
110 try |
45 { |
111 { |
46 iScrDbHandler = new CDbProcessor(dllName, dbName); |
112 iScrDbHandler = new CDbProcessor(dllName, dbName); |
47 } |
113 } |
48 catch(CException& aException) |
114 catch(CException& aException) |
49 { |
115 { |
50 int returnCode = aException.GetCode(); |
116 int returnCode = aException.GetCode(); |
51 std::wstring emessage = Utf8ToUcs2( aException.GetMessageA() ); |
117 std::wstring emessage = string2wstring( aException.GetMessageA() ); |
52 |
118 |
53 returnCode = (returnCode == ExceptionCodes::ELibraryLoadError) ? LIBRARYLOAD_ERROR : returnCode; |
119 returnCode = (returnCode == ExceptionCodes::ELibraryLoadError) ? LIBRARYLOAD_ERROR : returnCode; |
54 throw InterpretSisError(emessage,returnCode); |
120 throw InterpretSisError(emessage,returnCode); |
55 } |
121 } |
56 } |
122 } |
65 if(!stmtUid->ProcessNextRow()) |
131 if(!stmtUid->ProcessNextRow()) |
66 return false; |
132 return false; |
67 |
133 |
68 TInt32 uid = stmtUid->IntColumn(0); |
134 TInt32 uid = stmtUid->IntColumn(0); |
69 return (uid == aUid); |
135 return (uid == aUid); |
|
136 } |
|
137 |
|
138 TBool DbHelper::IsAppUidInstalled(TUint32 aAppUid) const |
|
139 { |
|
140 std::string selectUid("SELECT AppFile FROM AppRegistrationInfo WHERE AppUid=?;"); |
|
141 std::auto_ptr<CStatement> stmtUid(iScrDbHandler->PrepareStatement(selectUid)); |
|
142 |
|
143 stmtUid->BindInt(1, aAppUid); |
|
144 |
|
145 if(!stmtUid->ProcessNextRow()) |
|
146 return false; |
|
147 |
|
148 return true; |
70 } |
149 } |
71 |
150 |
72 TInt32 DbHelper::GetComponentId(TInt32 aUid, const std::wstring aPackageName, const std::wstring aVendorName ) const |
151 TInt32 DbHelper::GetComponentId(TInt32 aUid, const std::wstring aPackageName, const std::wstring aVendorName ) const |
73 { |
152 { |
74 std::string selectUid("SELECT ComponentId from ComponentProperties where Name='CompUid' and IntValue=? and ComponentId IN (SELECT ComponentId FROM \ |
153 std::string selectUid("SELECT ComponentId from ComponentProperties where Name='CompUid' and IntValue=? and ComponentId IN (SELECT ComponentId FROM \ |
248 return GetComponentPropertyIntValue(aComponentId,DbConstants::CompIndex); |
327 return GetComponentPropertyIntValue(aComponentId,DbConstants::CompIndex); |
249 } |
328 } |
250 |
329 |
251 void DbHelper::RemoveEntry( TInt32 aComponentId ) const |
330 void DbHelper::RemoveEntry( TInt32 aComponentId ) const |
252 { |
331 { |
|
332 |
|
333 std::vector<TInt32> appUidList = GetAppRegistrationInfoAppUid(aComponentId); |
|
334 std::vector<TInt32> ::iterator appUidIter; |
|
335 for( appUidIter = appUidList.begin(); appUidIter != appUidList.end() ; ++appUidIter ) |
|
336 { |
|
337 // delete FileOwnershipInfo |
|
338 std::string delFileOwnerInfo("DELETE FROM FileOwnershipInfo WHERE AppUid=?;"); |
|
339 std::auto_ptr<CStatement> stmtdelFileOwnerInfo(iScrDbHandler->PrepareStatement(delFileOwnerInfo)); |
|
340 stmtdelFileOwnerInfo->BindInt(1, *appUidIter); |
|
341 stmtdelFileOwnerInfo->ExecuteStatement(); |
|
342 |
|
343 // delete AppProperties |
|
344 std::string delAppProperties("DELETE FROM AppProperties WHERE AppUid=?;"); |
|
345 std::auto_ptr<CStatement> stmtAppProperties(iScrDbHandler->PrepareStatement(delAppProperties)); |
|
346 stmtAppProperties->BindInt(1, *appUidIter); |
|
347 stmtAppProperties->ExecuteStatement(); |
|
348 |
|
349 std::vector<TInt32> serviceIdList = GetServiceInfoServiceID(*appUidIter); |
|
350 |
|
351 std::vector<TInt32> ::iterator serviceIdIter; |
|
352 for( serviceIdIter = serviceIdList.begin(); serviceIdIter != serviceIdList.end() ; ++serviceIdIter ) |
|
353 { |
|
354 // delete DataType |
|
355 std::string delDataType("DELETE FROM DataType WHERE ServiceId=?;"); |
|
356 std::auto_ptr<CStatement> stmtDataType(iScrDbHandler->PrepareStatement(delDataType)); |
|
357 stmtDataType->BindInt(1, *serviceIdIter); |
|
358 stmtDataType->ExecuteStatement(); |
|
359 } |
|
360 |
|
361 // delete ServiceInfo |
|
362 std::string delServiceInfo("DELETE FROM ServiceInfo WHERE AppUid=?;"); |
|
363 std::auto_ptr<CStatement> stmtServiceInfo(iScrDbHandler->PrepareStatement(delServiceInfo)); |
|
364 stmtServiceInfo->BindInt(1, *appUidIter); |
|
365 stmtServiceInfo->ExecuteStatement(); |
|
366 |
|
367 std::vector<TInt32> localAppInfoIdList = GetLocalAppInfoID(*appUidIter); |
|
368 |
|
369 std::vector<TInt32> ::iterator localAppInfoIdIter; |
|
370 for( localAppInfoIdIter = localAppInfoIdList.begin(); localAppInfoIdIter != localAppInfoIdList.end() ; ++localAppInfoIdIter ) |
|
371 { |
|
372 std::vector<TInt32> viewDataCaptionIdList = GetViewDataCaptionAndIconID(*localAppInfoIdIter); |
|
373 |
|
374 std::vector<TInt32> ::iterator viewDataCaptionIdIter; |
|
375 for( viewDataCaptionIdIter = viewDataCaptionIdList.begin(); viewDataCaptionIdIter != viewDataCaptionIdList.end() ; ++viewDataCaptionIdIter ) |
|
376 { |
|
377 // delete CaptionAndIconInfo |
|
378 std::string delCaptionInfo("DELETE FROM CaptionAndIconInfo WHERE CaptionAndIconId=?;"); |
|
379 std::auto_ptr<CStatement> stmtCaptionInfo(iScrDbHandler->PrepareStatement(delCaptionInfo)); |
|
380 stmtCaptionInfo->BindInt(1, *viewDataCaptionIdIter); |
|
381 stmtCaptionInfo->ExecuteStatement(); |
|
382 } |
|
383 |
|
384 // delete ViewData |
|
385 std::string delViewData("DELETE FROM ViewData WHERE LocalAppInfoId=?;"); |
|
386 std::auto_ptr<CStatement> stmtViewData(iScrDbHandler->PrepareStatement(delViewData)); |
|
387 stmtViewData->BindInt(1, *localAppInfoIdIter); |
|
388 stmtViewData->ExecuteStatement(); |
|
389 } |
|
390 |
|
391 std::vector<TInt32> LocalCaptionIdList = GetLocalCaptionAndIconID(*appUidIter); |
|
392 std::vector<TInt32> ::iterator LocalCaptionIdIter; |
|
393 for( LocalCaptionIdIter = LocalCaptionIdList.begin(); LocalCaptionIdIter != LocalCaptionIdList.end() ; ++LocalCaptionIdIter ) |
|
394 { |
|
395 // delete CaptionAndIconInfo |
|
396 std::string delCaptionInfo("DELETE FROM CaptionAndIconInfo WHERE CaptionAndIconId=?;"); |
|
397 std::auto_ptr<CStatement> stmtCaptionInfo(iScrDbHandler->PrepareStatement(delCaptionInfo)); |
|
398 stmtCaptionInfo->BindInt(1, *LocalCaptionIdIter); |
|
399 stmtCaptionInfo->ExecuteStatement(); |
|
400 } |
|
401 |
|
402 // delete LocalizableAppInfo |
|
403 std::string delLocalizableAppInfo("DELETE FROM LocalizableAppInfo WHERE AppUid=?;"); |
|
404 std::auto_ptr<CStatement> stmtLocalizableAppInfo(iScrDbHandler->PrepareStatement(delLocalizableAppInfo)); |
|
405 stmtLocalizableAppInfo->BindInt(1, *appUidIter); |
|
406 stmtLocalizableAppInfo->ExecuteStatement(); |
|
407 |
|
408 } |
|
409 |
|
410 // delete AppRegistrationInfo |
|
411 std::string delAppRegistrationInfo("DELETE FROM AppRegistrationInfo WHERE ComponentId=?;"); |
|
412 std::auto_ptr<CStatement> stmtAppRegistrationInfo(iScrDbHandler->PrepareStatement(delAppRegistrationInfo)); |
|
413 stmtAppRegistrationInfo->BindInt(1, aComponentId); |
|
414 stmtAppRegistrationInfo->ExecuteStatement(); |
|
415 |
|
416 |
253 // delete component properties |
417 // delete component properties |
254 std::string delCompProps("DELETE FROM ComponentProperties WHERE ComponentId=?;"); |
418 std::string delCompProps("DELETE FROM ComponentProperties WHERE ComponentId=?;"); |
255 std::auto_ptr<CStatement> stmtDelCompProps(iScrDbHandler->PrepareStatement(delCompProps)); |
419 std::auto_ptr<CStatement> stmtDelCompProps(iScrDbHandler->PrepareStatement(delCompProps)); |
256 stmtDelCompProps->BindInt(1, aComponentId); |
420 stmtDelCompProps->BindInt(1, aComponentId); |
257 stmtDelCompProps->ExecuteStatement(); |
421 stmtDelCompProps->ExecuteStatement(); |
842 return aDefaultValue; |
1006 return aDefaultValue; |
843 |
1007 |
844 return stmtCompProperty->IntColumn(0); |
1008 return stmtCompProperty->IntColumn(0); |
845 } |
1009 } |
846 |
1010 |
|
1011 std::vector<TInt32> DbHelper::GetServiceInfoServiceID(TInt32 aAppUid) const |
|
1012 { |
|
1013 std::vector<TInt32> serviceIdList; |
|
1014 std::string selectServiceId("SELECT ServiceId FROM ServiceInfo WHERE AppUid=?;"); |
|
1015 std::auto_ptr<CStatement> stmtServiceId(iScrDbHandler->PrepareStatement(selectServiceId)); |
|
1016 |
|
1017 stmtServiceId->BindInt(1, aAppUid); |
|
1018 while(stmtServiceId->ProcessNextRow()) |
|
1019 { |
|
1020 serviceIdList.push_back(stmtServiceId->IntColumn(0)); |
|
1021 } |
|
1022 |
|
1023 return serviceIdList; |
|
1024 } |
|
1025 |
|
1026 |
|
1027 std::vector<TInt32> DbHelper::GetLocalAppInfoID(TInt32 aAppUid) const |
|
1028 { |
|
1029 std::vector<TInt32> localAppInfoIdList; |
|
1030 std::string selectLocalAppInfoId("SELECT LocalAppInfoId FROM LocalizableAppInfo WHERE AppUid=?;"); |
|
1031 std::auto_ptr<CStatement> stmtLocalAppInfoId(iScrDbHandler->PrepareStatement(selectLocalAppInfoId)); |
|
1032 |
|
1033 stmtLocalAppInfoId->BindInt(1, aAppUid); |
|
1034 while(stmtLocalAppInfoId->ProcessNextRow()) |
|
1035 { |
|
1036 localAppInfoIdList.push_back(stmtLocalAppInfoId->IntColumn(0)); |
|
1037 } |
|
1038 |
|
1039 return localAppInfoIdList; |
|
1040 } |
|
1041 |
|
1042 |
|
1043 std::vector<TInt32> DbHelper::GetLocalCaptionAndIconID(TInt32 aAppUid) const |
|
1044 { |
|
1045 std::vector<TInt32> localCaptionAndIconIdList; |
|
1046 std::string selectLocalCaptionAndIconId("SELECT CaptionAndIconId FROM LocalizableAppInfo WHERE AppUid=?;"); |
|
1047 std::auto_ptr<CStatement> stmtLocalCaptionAndIconId(iScrDbHandler->PrepareStatement(selectLocalCaptionAndIconId)); |
|
1048 |
|
1049 stmtLocalCaptionAndIconId->BindInt(1, aAppUid); |
|
1050 while(stmtLocalCaptionAndIconId->ProcessNextRow()) |
|
1051 { |
|
1052 localCaptionAndIconIdList.push_back(stmtLocalCaptionAndIconId->IntColumn(0)); |
|
1053 } |
|
1054 |
|
1055 return localCaptionAndIconIdList; |
|
1056 } |
|
1057 |
|
1058 |
|
1059 std::vector<TInt32> DbHelper::GetViewDataCaptionAndIconID(TInt32 aLocalAppInfoID) const |
|
1060 { |
|
1061 std::vector<TInt32> viewCaptionIdList; |
|
1062 std::string selectViewCaptionId("SELECT CaptionAndIconId FROM ViewData WHERE LocalAppInfoId=?;"); |
|
1063 std::auto_ptr<CStatement> stmtViewCaptionId(iScrDbHandler->PrepareStatement(selectViewCaptionId)); |
|
1064 |
|
1065 stmtViewCaptionId->BindInt(1, aLocalAppInfoID); |
|
1066 while(stmtViewCaptionId->ProcessNextRow()) |
|
1067 { |
|
1068 viewCaptionIdList.push_back(stmtViewCaptionId->IntColumn(0)); |
|
1069 } |
|
1070 |
|
1071 return viewCaptionIdList; |
|
1072 } |
|
1073 |
|
1074 |
|
1075 std::vector<TInt32> DbHelper::GetAppRegistrationInfoAppUid(TInt32 aComponentId) const |
|
1076 { |
|
1077 std::vector<TInt32> appUidList; |
|
1078 std::string selectAppUid("SELECT AppUid FROM AppRegistrationInfo WHERE ComponentId=?;"); |
|
1079 std::auto_ptr<CStatement> stmtAppUid(iScrDbHandler->PrepareStatement(selectAppUid)); |
|
1080 |
|
1081 stmtAppUid->BindInt(1, aComponentId); |
|
1082 while(stmtAppUid->ProcessNextRow()) |
|
1083 { |
|
1084 appUidList.push_back(stmtAppUid->IntColumn(0)); |
|
1085 } |
|
1086 |
|
1087 return appUidList; |
|
1088 } |
|
1089 |
847 TInt32 DbHelper::GetComponentPropertyIntFormattedValue(TInt32 aComponentId, std::wstring aComponentPropertyName, TInt32 aIntFormatter) const |
1090 TInt32 DbHelper::GetComponentPropertyIntFormattedValue(TInt32 aComponentId, std::wstring aComponentPropertyName, TInt32 aIntFormatter) const |
848 { |
1091 { |
849 TInt32 propertyValue = 0; |
1092 TInt32 propertyValue = 0; |
850 |
1093 |
851 std::string selectIntProperty("SELECT IntValue FROM ComponentProperties WHERE ComponentId=? and Name=?;"); |
1094 std::string selectIntProperty("SELECT IntValue FROM ComponentProperties WHERE ComponentId=? and Name=?;"); |