|
1 /* |
|
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "dbhelper.h" |
|
20 #include "dbprocessor.h" |
|
21 #include "dbconstants.h" |
|
22 #include "is_utils.h" |
|
23 #include "sisregistryobject.h" |
|
24 #include "sisregistrytoken.h" |
|
25 #include "sisregistrypackage.h" |
|
26 #include "errors.h" |
|
27 #include "../common/exception.h" |
|
28 |
|
29 #include <sstream> |
|
30 #include <stdexcept> |
|
31 |
|
32 const int DbHelper::Absent = -1; |
|
33 |
|
34 DbHelper::DbHelper( const std::wstring& aDrivePath, bool aIsSystemDrive) |
|
35 { |
|
36 std::string dllName = "sqlite3.dll"; |
|
37 std::string dbName; |
|
38 |
|
39 if (aIsSystemDrive) |
|
40 dbName = wstring2string(aDrivePath) + "\\sys\\install\\scr\\scr.db"; |
|
41 else |
|
42 dbName = wstring2string(aDrivePath) + "\\sys\\install\\scr\\provisioned\\scr.db"; |
|
43 |
|
44 try |
|
45 { |
|
46 iScrDbHandler = new CDbProcessor(dllName, dbName); |
|
47 } |
|
48 catch(CException& aException) |
|
49 { |
|
50 int returnCode = aException.GetCode(); |
|
51 std::wstring emessage = Utf8ToUcs2( aException.GetMessageA() ); |
|
52 |
|
53 returnCode = (returnCode == ExceptionCodes::ELibraryLoadError) ? LIBRARYLOAD_ERROR : returnCode; |
|
54 throw InterpretSisError(emessage,returnCode); |
|
55 } |
|
56 } |
|
57 |
|
58 TBool DbHelper::IsInstalled(TInt32 aUid) const |
|
59 { |
|
60 std::string selectUid("SELECT IntValue FROM ComponentProperties WHERE Name='CompUid' and IntValue=?;"); |
|
61 std::auto_ptr<CStatement> stmtUid(iScrDbHandler->PrepareStatement(selectUid)); |
|
62 |
|
63 stmtUid->BindInt(1, aUid); |
|
64 |
|
65 if(!stmtUid->ProcessNextRow()) |
|
66 return false; |
|
67 |
|
68 TInt32 uid = stmtUid->IntColumn(0); |
|
69 return (uid == aUid); |
|
70 } |
|
71 |
|
72 TInt32 DbHelper::GetComponentId(TInt32 aUid, const std::wstring aPackageName, const std::wstring aVendorName ) const |
|
73 { |
|
74 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=?));"); |
|
76 std::auto_ptr<CStatement> stmtCompid(iScrDbHandler->PrepareStatement(selectUid)); |
|
77 |
|
78 stmtCompid->BindInt(1, aUid); |
|
79 stmtCompid->BindStr(2, aVendorName); |
|
80 stmtCompid->BindStr(3, aPackageName); |
|
81 |
|
82 TInt32 componentId = DbHelper::Absent; |
|
83 if(stmtCompid->ProcessNextRow()) |
|
84 { |
|
85 componentId = stmtCompid->IntColumn(0); |
|
86 } |
|
87 return componentId; |
|
88 } |
|
89 |
|
90 TInt32 DbHelper::GetComponentId(TInt32 aUid, TInt32 aInstallType ) const |
|
91 { |
|
92 std::string selectUid("SELECT ComponentId from ComponentProperties where Name='CompUid' and IntValue=? and ComponentId IN (SELECT ComponentId FROM \ |
|
93 ComponentProperties WHERE Name='CompInstallType' and IntValue=?) "); |
|
94 std::auto_ptr<CStatement> stmtCompid(iScrDbHandler->PrepareStatement(selectUid)); |
|
95 |
|
96 stmtCompid->BindInt(1, aUid); |
|
97 stmtCompid->BindInt(2, aInstallType); |
|
98 |
|
99 TInt32 componentId = DbHelper::Absent; |
|
100 if( stmtCompid->ProcessNextRow()) |
|
101 { |
|
102 componentId = stmtCompid->IntColumn(0); |
|
103 } |
|
104 |
|
105 return componentId; |
|
106 } |
|
107 |
|
108 TInt32 DbHelper::GetComponentId( TInt32 aUid ) const |
|
109 { |
|
110 std::string selectCompId( "SELECT ComponentId FROM ComponentProperties WHERE Name='CompUid' \ |
|
111 AND IntValue=? AND ComponentId IN (SELECT ComponentId from \ |
|
112 ComponentProperties WHERE Name='CompIndex' AND IntValue='0');" |
|
113 ); |
|
114 |
|
115 std::auto_ptr<CStatement> stmtCompId(iScrDbHandler->PrepareStatement(selectCompId)); |
|
116 |
|
117 stmtCompId->BindInt(1, aUid); |
|
118 |
|
119 // this might contain multiple entries for the specific uid but as it has been |
|
120 // ordered by propertyid the first entry would be of the first installation. |
|
121 if(stmtCompId->ProcessNextRow()) |
|
122 { |
|
123 return stmtCompId->IntColumn(0); |
|
124 } |
|
125 |
|
126 return DbHelper::Absent; |
|
127 } |
|
128 |
|
129 std::vector<TInt32> DbHelper::GetComponentIdList( TInt32 aUid ) const |
|
130 { |
|
131 std::vector<TInt32> componentIdList; |
|
132 std::string selectCompId("SELECT ComponentId FROM ComponentProperties WHERE Name='CompUid' and IntValue=? order by PropertyId;"); |
|
133 std::auto_ptr<CStatement> stmtCompId(iScrDbHandler->PrepareStatement(selectCompId)); |
|
134 |
|
135 stmtCompId->BindInt(1, aUid); |
|
136 |
|
137 // this might contain multiple entries for the specific uid but as it has been |
|
138 // ordered by propertyid the first entry would be of the first installtion. |
|
139 while(stmtCompId->ProcessNextRow()) |
|
140 { |
|
141 componentIdList.push_back(stmtCompId->IntColumn(0)); |
|
142 } |
|
143 |
|
144 return componentIdList; |
|
145 } |
|
146 |
|
147 bool DbHelper::GetIsRemovable( TInt32 aComponentId ) const |
|
148 { |
|
149 std::string selectIsRemovable("SELECT Removable FROM Components WHERE ComponentId=?;"); |
|
150 std::auto_ptr<CStatement> stmtIsRemovable(iScrDbHandler->PrepareStatement(selectIsRemovable)); |
|
151 |
|
152 stmtIsRemovable->BindInt(1, aComponentId); |
|
153 |
|
154 if(!stmtIsRemovable->ProcessNextRow()) |
|
155 return false; |
|
156 |
|
157 return (stmtIsRemovable->IntColumn(0) == 1); |
|
158 } |
|
159 |
|
160 bool DbHelper::GetInRom( TInt32 aComponentId ) const |
|
161 { |
|
162 std::string selectInRom("SELECT IntValue FROM ComponentProperties WHERE ComponentId=? and Name='CompInRom';"); |
|
163 std::auto_ptr<CStatement> stmtInRom(iScrDbHandler->PrepareStatement(selectInRom)); |
|
164 |
|
165 stmtInRom->BindInt(1, aComponentId); |
|
166 |
|
167 if(!stmtInRom->ProcessNextRow()) |
|
168 return DbConstants::KDefaultIsInRom; |
|
169 |
|
170 return (stmtInRom->IntColumn(0) == 1); |
|
171 } |
|
172 |
|
173 std::wstring DbHelper::GetPackageName( TInt32 aComponentId ) const |
|
174 { |
|
175 std::string selectPckgName("SELECT Name FROM ComponentLocalizables WHERE ComponentId=?;"); |
|
176 std::auto_ptr<CStatement> stmtPckgName(iScrDbHandler->PrepareStatement(selectPckgName)); |
|
177 |
|
178 stmtPckgName->BindInt(1, aComponentId); |
|
179 |
|
180 if(stmtPckgName->ProcessNextRow()) |
|
181 { |
|
182 return stmtPckgName->StrColumn(0); |
|
183 } |
|
184 |
|
185 return NULL; |
|
186 } |
|
187 |
|
188 TUint32 DbHelper::GetUid( TInt32 aComponentId ) const |
|
189 { |
|
190 std::string selectUid("SELECT IntValue FROM ComponentProperties WHERE ComponentId=? and Name='CompUid';"); |
|
191 std::auto_ptr<CStatement> stmtUid(iScrDbHandler->PrepareStatement(selectUid)); |
|
192 |
|
193 stmtUid->BindInt(1, aComponentId); |
|
194 |
|
195 if(stmtUid->ProcessNextRow()) |
|
196 { |
|
197 return stmtUid->IntColumn(0); |
|
198 } |
|
199 |
|
200 return DbHelper::Absent; |
|
201 } |
|
202 |
|
203 |
|
204 TUint32 DbHelper::GetUidFromFileName( const std::wstring& aFileName ) const |
|
205 { |
|
206 std::string selCompId("SELECT ComponentId FROM ComponentsFiles WHERE Location=?;"); |
|
207 std::auto_ptr<CStatement> stmtCompId(iScrDbHandler->PrepareStatement(selCompId)); |
|
208 |
|
209 stmtCompId->BindStr(1, aFileName); |
|
210 |
|
211 TInt32 componentId = 0; |
|
212 if(stmtCompId->ProcessNextRow()) |
|
213 { |
|
214 componentId = stmtCompId->IntColumn(0); |
|
215 return GetUid(componentId); |
|
216 } |
|
217 |
|
218 std::string selCompPropsId("SELECT ComponentId FROM ComponentProperties WHERE StrValue=? and Name like 'WCFile%';"); |
|
219 std::auto_ptr<CStatement> stmtCompPropsId(iScrDbHandler->PrepareStatement(selCompPropsId)); |
|
220 |
|
221 stmtCompPropsId->BindStr(1, aFileName); |
|
222 |
|
223 if(stmtCompPropsId->ProcessNextRow()) |
|
224 { |
|
225 componentId = stmtCompPropsId->IntColumn(0); |
|
226 return GetUid(componentId); |
|
227 } |
|
228 |
|
229 return 0; |
|
230 } |
|
231 |
|
232 |
|
233 TUint32 DbHelper::GetInstallType( TInt32 aComponentId ) const |
|
234 { |
|
235 std::string selectInstallType("SELECT IntValue FROM ComponentProperties WHERE ComponentId=? and Name='CompInstallType';"); |
|
236 std::auto_ptr<CStatement> stmtInstallType(iScrDbHandler->PrepareStatement(selectInstallType)); |
|
237 |
|
238 stmtInstallType->BindInt(1, aComponentId); |
|
239 |
|
240 if(stmtInstallType->ProcessNextRow()) |
|
241 return stmtInstallType->IntColumn(0); |
|
242 |
|
243 return DbConstants::KDefaultInstallType; |
|
244 } |
|
245 |
|
246 TInt DbHelper::GetIndex( TInt32 aComponentId) const |
|
247 { |
|
248 return GetComponentPropertyIntValue(aComponentId,DbConstants::CompIndex); |
|
249 } |
|
250 |
|
251 void DbHelper::RemoveEntry( TInt32 aComponentId ) const |
|
252 { |
|
253 // delete component properties |
|
254 std::string delCompProps("DELETE FROM ComponentProperties WHERE ComponentId=?;"); |
|
255 std::auto_ptr<CStatement> stmtDelCompProps(iScrDbHandler->PrepareStatement(delCompProps)); |
|
256 stmtDelCompProps->BindInt(1, aComponentId); |
|
257 stmtDelCompProps->ExecuteStatement(); |
|
258 |
|
259 // delete component file properties |
|
260 std::string delFileProps("DELETE from FileProperties WHERE CmpFileId IN \ |
|
261 (SELECT CmpFileId FROM ComponentsFiles WHERE ComponentId=?);"); |
|
262 std::auto_ptr<CStatement> stmtDelFileProps(iScrDbHandler->PrepareStatement(delFileProps)); |
|
263 stmtDelFileProps->BindInt(1, aComponentId); |
|
264 stmtDelFileProps->ExecuteStatement(); |
|
265 |
|
266 // delete component files |
|
267 std::string delCompFiles("DELETE FROM ComponentsFiles WHERE ComponentId=?;"); |
|
268 std::auto_ptr<CStatement> stmtCompFiles(iScrDbHandler->PrepareStatement(delCompFiles)); |
|
269 stmtCompFiles->BindInt(1, aComponentId); |
|
270 stmtCompFiles->ExecuteStatement(); |
|
271 |
|
272 // delete component localizables |
|
273 std::string delCompLocs("DELETE FROM ComponentLocalizables WHERE ComponentId=?;"); |
|
274 std::auto_ptr<CStatement> stmtCompLocs(iScrDbHandler->PrepareStatement(delCompLocs)); |
|
275 stmtCompLocs->BindInt(1, aComponentId); |
|
276 stmtCompLocs->ExecuteStatement(); |
|
277 |
|
278 // delete component dependencies |
|
279 std::string delCompDeps("DELETE FROM ComponentDependencies WHERE GlobalIdHash IN \ |
|
280 (SELECT GlobalIdHash FROM Components WHERE ComponentId=?);"); |
|
281 std::auto_ptr<CStatement> stmtCompDeps(iScrDbHandler->PrepareStatement(delCompDeps)); |
|
282 stmtCompDeps->BindInt(1, aComponentId); |
|
283 stmtCompDeps->ExecuteStatement(); |
|
284 |
|
285 // delete components |
|
286 std::string delComps("DELETE FROM Components WHERE ComponentId=?;"); |
|
287 std::auto_ptr<CStatement> stmtComps(iScrDbHandler->PrepareStatement(delComps)); |
|
288 stmtComps->BindInt(1, aComponentId); |
|
289 stmtComps->ExecuteStatement(); |
|
290 |
|
291 } |
|
292 |
|
293 int DbHelper::GetSelectedDrive( TInt32 aComponentId ) |
|
294 { |
|
295 std::string selectDrive("SELECT IntValue FROM ComponentProperties WHERE ComponentId=? and Name='CompSelectedDrive';"); |
|
296 std::auto_ptr<CStatement> stmtDrive(iScrDbHandler->PrepareStatement(selectDrive)); |
|
297 |
|
298 stmtDrive->BindInt(1, aComponentId); |
|
299 |
|
300 if(stmtDrive->ProcessNextRow()) |
|
301 return stmtDrive->IntColumn(0); |
|
302 |
|
303 return DbConstants::KDefaultInstalledDrive; |
|
304 } |
|
305 |
|
306 bool DbHelper::InternalizeIfExists(SisRegistryObject& aSisRegistryObject, const TUint32 aUid ) const |
|
307 { |
|
308 TInt32 componentId = GetComponentId(aUid); |
|
309 if(componentId == DbHelper::Absent) |
|
310 { |
|
311 return false; |
|
312 } |
|
313 |
|
314 // retrieve all details from componentproperties |
|
315 GetComponentDetails(componentId, aSisRegistryObject); |
|
316 |
|
317 GetComponentLocalizables(componentId, aSisRegistryObject); |
|
318 |
|
319 // retrieve all files for this component Id from the componentfiles table |
|
320 GetFileDescriptions(componentId, aSisRegistryObject); |
|
321 |
|
322 GetComponentProperties(componentId, aSisRegistryObject); |
|
323 |
|
324 return true; |
|
325 } |
|
326 |
|
327 bool DbHelper::SidExists(const TUint32 aSid) const |
|
328 { |
|
329 std::string selectSid("SELECT IntValue FROM ComponentProperties WHERE Name like 'CompSid%' and IntValue=?;"); |
|
330 std::auto_ptr<CStatement> stmtSid(iScrDbHandler->PrepareStatement(selectSid)); |
|
331 |
|
332 stmtSid->BindInt(1, aSid); |
|
333 if(!stmtSid->ProcessNextRow()) |
|
334 return false; |
|
335 |
|
336 TInt32 sid = stmtSid->IntColumn(0); |
|
337 |
|
338 return ( sid == aSid ); |
|
339 } |
|
340 |
|
341 TUint32 DbHelper::GetUid(const TUint32 aSid) const |
|
342 { |
|
343 std::string selectUid("SELECT IntValue FROM ComponentProperties WHERE ComponentId in \ |
|
344 (SELECT ComponentId from ComponentProperties where Name like 'CompSid%' and IntValue=?) and Name='CompUid';"); |
|
345 std::auto_ptr<CStatement> stmtUid(iScrDbHandler->PrepareStatement(selectUid)); |
|
346 |
|
347 stmtUid->BindInt(1, aSid); |
|
348 if(stmtUid->ProcessNextRow()) |
|
349 return stmtUid->IntColumn(0); |
|
350 |
|
351 return DbHelper::Absent; |
|
352 } |
|
353 |
|
354 |
|
355 TUint32 DbHelper::GetUid( const std::wstring& aSidFile ) const |
|
356 { |
|
357 std::string selectCompId("SELECT ComponentId FROM ComponentProperties WHERE StrValue=? and Name like 'CompSidFileName%';"); |
|
358 std::auto_ptr<CStatement> stmtCompId(iScrDbHandler->PrepareStatement(selectCompId)); |
|
359 |
|
360 stmtCompId->BindStr(1, aSidFile); |
|
361 if(!stmtCompId->ProcessNextRow()) |
|
362 return DbHelper::Absent; |
|
363 |
|
364 TInt32 componentId = stmtCompId->IntColumn(0); |
|
365 |
|
366 return GetUid(componentId); |
|
367 |
|
368 } |
|
369 |
|
370 std::wstring DbHelper::SidToFileName(TUint32 aSid) const |
|
371 { |
|
372 std::string selectCompId("SELECT ComponentId,Name FROM ComponentProperties WHERE Name like 'CompSid%' and IntValue=?;"); |
|
373 std::auto_ptr<CStatement> stmtCompId(iScrDbHandler->PrepareStatement(selectCompId)); |
|
374 |
|
375 stmtCompId->BindInt(1, aSid); |
|
376 if(!stmtCompId->ProcessNextRow()) |
|
377 return NULL; |
|
378 |
|
379 int componentId = stmtCompId->IntColumn(0); |
|
380 |
|
381 std::wstring sidName = stmtCompId->StrColumn(1); |
|
382 |
|
383 std::wstring finalString(DbConstants::CompSidFileName); |
|
384 finalString += sidName.substr(DbConstants::CompSid.length() ); |
|
385 |
|
386 std::string selectFile("SELECT StrValue FROM ComponentProperties WHERE ComponentId=? and Name=?;"); |
|
387 |
|
388 std::auto_ptr<CStatement> stmtFile(iScrDbHandler->PrepareStatement(selectFile)); |
|
389 |
|
390 stmtFile->BindInt(1, componentId); |
|
391 stmtFile->BindStr(2, finalString); |
|
392 |
|
393 if(!stmtFile->ProcessNextRow()) |
|
394 return NULL; |
|
395 |
|
396 return stmtFile->StrColumn(0); |
|
397 |
|
398 |
|
399 } |
|
400 |
|
401 void DbHelper::GetComponentDetails(TInt32 aComponentId, SisRegistryObject& aSisRegistryObject) const |
|
402 { |
|
403 |
|
404 std::string selectComponents( "SELECT Removable, Hidden, Version FROM Components WHERE ComponentId=?;"); |
|
405 std::auto_ptr<CStatement> stmtSelectComponents(iScrDbHandler->PrepareStatement(selectComponents)); |
|
406 |
|
407 stmtSelectComponents->BindInt(1, aComponentId); |
|
408 if(!stmtSelectComponents->ProcessNextRow()) |
|
409 return; |
|
410 |
|
411 // isRemovable |
|
412 TBool isRemovable = false; |
|
413 if(stmtSelectComponents->IntColumn(0) == 1) |
|
414 { |
|
415 isRemovable = true; |
|
416 } |
|
417 aSisRegistryObject.SetIsRemovable(isRemovable); |
|
418 |
|
419 // isHidden |
|
420 TBool isHidden = false; |
|
421 if(stmtSelectComponents->IntColumn(1) == 1) |
|
422 { |
|
423 isHidden = true; |
|
424 } |
|
425 aSisRegistryObject.SetIsHidden(isHidden); |
|
426 |
|
427 std::wstring textVersion = stmtSelectComponents->StrColumn(2); |
|
428 |
|
429 std::wstringstream strMajor(textVersion.substr(0,1)); |
|
430 int major = 0; |
|
431 strMajor >> major; |
|
432 std::wstringstream strMinor(textVersion.substr(2,3)); |
|
433 int minor = 0; |
|
434 strMinor >> minor; |
|
435 std::wstringstream strBuild(textVersion.substr(4,4)); |
|
436 int build = 0; |
|
437 strBuild >> build; |
|
438 |
|
439 Version version(major,minor,build); |
|
440 |
|
441 // sisregistrytoken |
|
442 aSisRegistryObject.SetVersion(version); |
|
443 } |
|
444 |
|
445 void DbHelper::GetComponentLocalizables(TInt32 aComponentId, SisRegistryObject& aSisRegistryObject) const |
|
446 { |
|
447 // do we need to specify locale |
|
448 std::string selectCompLocalizables( "SELECT Name,Vendor FROM ComponentLocalizables WHERE ComponentId=?;"); |
|
449 std::auto_ptr<CStatement> stmtCompLocalizables(iScrDbHandler->PrepareStatement(selectCompLocalizables)); |
|
450 |
|
451 stmtCompLocalizables->BindInt(1, aComponentId); |
|
452 if(!stmtCompLocalizables->ProcessNextRow()) |
|
453 return; |
|
454 |
|
455 std::wstring pckgName = stmtCompLocalizables->StrColumn(0); |
|
456 std::wstring vendor = stmtCompLocalizables->StrColumn(1); |
|
457 |
|
458 // sisregistrypackage |
|
459 aSisRegistryObject.SetPackageName(pckgName); |
|
460 // sisregistryobject |
|
461 aSisRegistryObject.SetVendorLocalizedName(vendor); |
|
462 |
|
463 } |
|
464 |
|
465 void DbHelper::GetFileDescriptions( TInt32 aComponentId, SisRegistryObject& aSisRegistryObject ) const |
|
466 { |
|
467 std::vector<FileDescription*> fileDescriptions; |
|
468 GetFileDescriptionFromComponentProperties( aComponentId, fileDescriptions ); |
|
469 GetFileDescriptionFromFileProperties( aComponentId, fileDescriptions ); |
|
470 |
|
471 aSisRegistryObject.SetFileDescriptions(fileDescriptions); |
|
472 |
|
473 } |
|
474 |
|
475 std::vector<FileDescription*> DbHelper::GetFileDescriptions( TInt32 aComponentId ) const |
|
476 { |
|
477 std::vector<FileDescription*> fileDescriptions; |
|
478 GetFileDescriptionFromComponentProperties( aComponentId, fileDescriptions ); |
|
479 GetFileDescriptionFromFileProperties( aComponentId, fileDescriptions ); |
|
480 return fileDescriptions; |
|
481 } |
|
482 |
|
483 void DbHelper::GetFileDescriptionFromComponentProperties( int aComponentId, std::vector<FileDescription*>& aFileDescriptions) const |
|
484 { |
|
485 std::string selectWildCardCount( "SELECT IntValue FROM ComponentProperties WHERE ComponentId=? and Name='CompWildCardFileCount';"); |
|
486 std::auto_ptr<CStatement> stmtWildCardCount(iScrDbHandler->PrepareStatement(selectWildCardCount)); |
|
487 |
|
488 stmtWildCardCount->BindInt(1, aComponentId); |
|
489 if(!stmtWildCardCount->ProcessNextRow()) |
|
490 return; |
|
491 |
|
492 int wildCardCount = stmtWildCardCount->IntColumn(0); |
|
493 |
|
494 for(int count=0; count < wildCardCount; ++count) |
|
495 { |
|
496 |
|
497 FileDescription* fileDescription = new FileDescription(); |
|
498 |
|
499 std::string selectWildCardCount( "SELECT Name,Locale,IntValue,StrValue,IsStr8Bit FROM ComponentProperties WHERE ComponentId=? and Name like ? order by PropertyId;"); |
|
500 std::auto_ptr<CStatement> stmtWildCardCount(iScrDbHandler->PrepareStatement(selectWildCardCount)); |
|
501 |
|
502 std::wstring namePattern = L"WCFile%"; |
|
503 std::wstringstream strNamePattern; |
|
504 strNamePattern << namePattern << count; |
|
505 |
|
506 stmtWildCardCount->BindInt(1, aComponentId); |
|
507 stmtWildCardCount->BindStr(2, strNamePattern.str()); |
|
508 |
|
509 AddFileDescription(stmtWildCardCount.get(), *fileDescription, count); |
|
510 |
|
511 aFileDescriptions.push_back(fileDescription); |
|
512 } |
|
513 } |
|
514 |
|
515 void DbHelper::GetFileDescriptionFromFileProperties( int aComponentId, std::vector<FileDescription*>& aFileDescriptions) const |
|
516 { |
|
517 // retrieve the location form the component files table |
|
518 std::string selLocation( "SELECT CmpFileId,Location FROM ComponentsFiles WHERE ComponentId=?;"); |
|
519 std::auto_ptr<CStatement> stmtLocation(iScrDbHandler->PrepareStatement(selLocation)); |
|
520 |
|
521 stmtLocation->BindInt(1, aComponentId); |
|
522 |
|
523 while( stmtLocation->ProcessNextRow() ) |
|
524 { |
|
525 FileDescription* fileDescription = new FileDescription(); |
|
526 fileDescription->SetTarget(stmtLocation->StrColumn(1)); |
|
527 |
|
528 int cmpFileId = stmtLocation->IntColumn(0); |
|
529 |
|
530 std::string selFileProps( "SELECT Name,IntValue,StrValue FROM FileProperties WHERE CmpFileId=?;"); |
|
531 std::auto_ptr<CStatement> stmtFileProps(iScrDbHandler->PrepareStatement(selFileProps)); |
|
532 stmtFileProps->BindInt(1, cmpFileId); |
|
533 |
|
534 AddFileDescription(stmtFileProps.get(), *fileDescription, -1); |
|
535 aFileDescriptions.push_back(fileDescription); |
|
536 } |
|
537 } |
|
538 |
|
539 void DbHelper::AddFileDescription(CStatement* aStatement, FileDescription& aFileDescription, TInt aCount ) const |
|
540 { |
|
541 bool hashId = false; |
|
542 bool hashData = false; |
|
543 HashContainer hashContainer; |
|
544 |
|
545 if( aCount == -1 ) |
|
546 { |
|
547 while(aStatement->ProcessNextRow()) |
|
548 { |
|
549 std::wstring name = aStatement->StrColumn(0); |
|
550 |
|
551 if(name == DbConstants::FileMimeType ) |
|
552 { |
|
553 aFileDescription.SetMimeType(aStatement->StrColumn(2)); |
|
554 } |
|
555 else if(name == DbConstants::FileSisFileOperation ) |
|
556 { |
|
557 int sisFileOperation = aStatement->IntColumn(1); |
|
558 aFileDescription.SetOperation(sisFileOperation); |
|
559 } |
|
560 else if( name == DbConstants::FileFileOperationOptions) |
|
561 { |
|
562 int fileOperationOptions = aStatement->IntColumn(1); |
|
563 aFileDescription.SetOperationOptions(fileOperationOptions); |
|
564 } |
|
565 else if( name == DbConstants::FileUncompressedLength ) |
|
566 { |
|
567 TInt64 uncompressedLength = aStatement->Int64Column(1); |
|
568 aFileDescription.SetUncompressedLength( uncompressedLength ); |
|
569 } |
|
570 else if( name == DbConstants::FileIndex ) |
|
571 { |
|
572 int fileIndex = aStatement->IntColumn(1); |
|
573 aFileDescription.SetIndex( fileIndex ); |
|
574 } |
|
575 else if( name == DbConstants::FileSid ) |
|
576 { |
|
577 int fileSid = aStatement->IntColumn(1); |
|
578 aFileDescription.SetSid( fileSid ); |
|
579 } |
|
580 else if( name == DbConstants::FileHashAlgorithm ) |
|
581 { |
|
582 hashContainer.SetHashId(aStatement->IntColumn(1)); |
|
583 hashId = true; |
|
584 if(hashData) |
|
585 { |
|
586 aFileDescription.SetHash(hashContainer); |
|
587 hashId = hashData = false; |
|
588 } |
|
589 } |
|
590 else if( name == DbConstants::FileHashData ) |
|
591 { |
|
592 hashContainer.SetData(wstring2string(aStatement->StrColumn(2))); |
|
593 hashData = true; |
|
594 if(hashId) |
|
595 { |
|
596 aFileDescription.SetHash(hashContainer); |
|
597 hashId = hashData = false; |
|
598 } |
|
599 } |
|
600 } // while |
|
601 } |
|
602 else |
|
603 { |
|
604 while(aStatement->ProcessNextRow() ) |
|
605 { |
|
606 std::wstring name = aStatement->StrColumn(0); |
|
607 |
|
608 if(name == FormatDbString(DbConstants::WCFileName,aCount) ) |
|
609 { |
|
610 aFileDescription.SetTarget(aStatement->StrColumn(3)); |
|
611 } |
|
612 } // while |
|
613 } |
|
614 } |
|
615 |
|
616 |
|
617 void DbHelper::GetComponentProperties( TInt32 aComponentId, SisRegistryObject& aSisRegistryObject ) const |
|
618 { |
|
619 TUint32 installType = GetComponentPropertyIntValue(aComponentId, DbConstants::CompInstallType, DbConstants::KDefaultInstallType); |
|
620 aSisRegistryObject.SetInstallType(installType); |
|
621 aSisRegistryObject.SetDependencies(GetDependencies(aComponentId)); |
|
622 aSisRegistryObject.SetEmbeddedPackages(GetEmbeddedPackages(aComponentId)); |
|
623 aSisRegistryObject.SetProperties(GetProperties(aComponentId)); |
|
624 |
|
625 // inrom |
|
626 bool status = GetComponentPropertyIntValue(aComponentId,DbConstants::CompInRom, DbConstants::KDefaultIsInRom); |
|
627 aSisRegistryObject.SetInRom(status); |
|
628 |
|
629 // issigned |
|
630 status = GetComponentPropertyIntValue(aComponentId,DbConstants::CompIsSigned, DbConstants::KDefaultIsSigned); |
|
631 aSisRegistryObject.SetSigned(status); |
|
632 |
|
633 // signedbysucert |
|
634 status = GetComponentPropertyIntValue(aComponentId,DbConstants::CompSignedBySuCert, DbConstants::KDefaultIsSignedBySuCert); |
|
635 aSisRegistryObject.SetSigned(status); |
|
636 |
|
637 // deletepreinstalled |
|
638 status = GetComponentPropertyIntValue(aComponentId,DbConstants::CompDeletablePreinstalled, DbConstants::KDefaultIsDeletablePreInstalled); |
|
639 aSisRegistryObject.SetPreInstalled(status); |
|
640 |
|
641 // trust |
|
642 int trust = GetComponentPropertyIntValue(aComponentId,DbConstants::CompTrust, DbConstants::KDefaultTrustValue); |
|
643 aSisRegistryObject.SetTrust(trust); |
|
644 |
|
645 // isRemoveWithLastDependent |
|
646 int removeWithLastDep = GetComponentPropertyIntValue(aComponentId,DbConstants::CompIsRemoveWithLastDependent, DbConstants::KDefaultRemoveWithLastDependent); |
|
647 aSisRegistryObject.SetRemoveWithLastDependent(removeWithLastDep); |
|
648 |
|
649 // trustTimeStamp |
|
650 TInt64 timeStamp = 0; |
|
651 aSisRegistryObject.SetTrustTimeStamp(timeStamp); |
|
652 |
|
653 // trustStatus |
|
654 aSisRegistryObject.SetTrustStatus(GetTrustStatus(aComponentId)); |
|
655 |
|
656 // installchain indices |
|
657 aSisRegistryObject.SetInstallChainIndices(GetInstallChainIndices(aComponentId)); |
|
658 |
|
659 //////// sisregistrytoken /////////////////////// |
|
660 |
|
661 aSisRegistryObject.SetSids(GetSids(aComponentId)); |
|
662 |
|
663 aSisRegistryObject.SetControllerInfo(GetControllerInfo(aComponentId)); |
|
664 |
|
665 // language |
|
666 TInt language = GetComponentPropertyIntValue( aComponentId, DbConstants::CompLanguage, DbConstants::KDefaultInstalledLanguage ); |
|
667 aSisRegistryObject.SetLanguage(language); |
|
668 |
|
669 //selected drive |
|
670 TInt selectedDrive = GetComponentPropertyIntValue( aComponentId, DbConstants::CompSelectedDrive, DbConstants::KDefaultInstalledDrive ); |
|
671 aSisRegistryObject.SetSelectedDrive(selectedDrive); |
|
672 |
|
673 //////// sisregistrypackage /////////////////////// |
|
674 |
|
675 // uid |
|
676 TUint32 uid = GetComponentPropertyIntValue( aComponentId, DbConstants::CompUid ); |
|
677 aSisRegistryObject.SetUid(uid); |
|
678 |
|
679 // unique vendor name |
|
680 std::wstring uniqueVendorName = GetComponentPropertyStrValue( aComponentId, DbConstants::CompUniqueVendorName ); |
|
681 aSisRegistryObject.SetVendorName(uniqueVendorName); |
|
682 |
|
683 // index |
|
684 TInt index = GetComponentPropertyIntValue( aComponentId, DbConstants::CompIndex ); |
|
685 aSisRegistryObject.SetIndex(index); |
|
686 |
|
687 } |
|
688 |
|
689 Dependencies DbHelper::GetDependencies( TInt32 aComponentId ) const |
|
690 { |
|
691 std::vector<SisRegistryDependency*> dependencyList; |
|
692 |
|
693 // retrieve the location form the component files table |
|
694 std::string selDependencies( "SELECT SupplierGlobalId,VersionFrom,VersionTo FROM ComponentDependencies WHERE GlobalIdHash IN \ |
|
695 (SELECT GlobalIdHash from Components where ComponentId=? );"); |
|
696 std::auto_ptr<CStatement> stmtDependencies(iScrDbHandler->PrepareStatement(selDependencies)); |
|
697 |
|
698 stmtDependencies->BindInt(1, aComponentId); |
|
699 |
|
700 while( stmtDependencies->ProcessNextRow() ) |
|
701 { |
|
702 std::wstring supplierId = stmtDependencies->StrColumn(0); |
|
703 TUint32 uid = Utils::WideStringToInteger(supplierId.substr(4,supplierId.length())); |
|
704 |
|
705 SisRegistryDependency* registryDependency = new SisRegistryDependency(); |
|
706 registryDependency->SetUid(uid); |
|
707 registryDependency->SetFromVersion(FormatStringToVersion(stmtDependencies->StrColumn(1))); |
|
708 registryDependency->SetToVersion(FormatStringToVersion(stmtDependencies->StrColumn(2))); |
|
709 dependencyList.push_back(registryDependency); |
|
710 } |
|
711 |
|
712 return dependencyList; |
|
713 } |
|
714 |
|
715 Packages DbHelper::GetEmbeddedPackages( TInt32 aComponentId ) const |
|
716 { |
|
717 std::vector<SisRegistryPackage*> packageList; |
|
718 |
|
719 int embPckgCount = GetComponentPropertyIntValue(aComponentId,DbConstants::CompEmbeddedPackageCount, DbConstants::KDefaultEmbeddedPackageCount); |
|
720 |
|
721 for(int count=0 ; count<embPckgCount ; ++count) |
|
722 { |
|
723 |
|
724 TUint32 uid = GetComponentPropertyIntFormattedValue(aComponentId, DbConstants::CompEmbeddedPackageUid, count); |
|
725 std::wstring name = GetComponentPropertyStrValue(aComponentId, DbConstants::CompEmbeddedPackageName, count); |
|
726 std::wstring vendor = GetComponentPropertyStrValue(aComponentId, DbConstants::CompEmbeddedPackageVendor, count); |
|
727 TUint32 pckgIndex = GetComponentPropertyIntFormattedValue(aComponentId, DbConstants::CompEmbeddedPackageIndex, count); |
|
728 SisRegistryPackage* registryPckg = new SisRegistryPackage(uid, name, vendor, pckgIndex); |
|
729 packageList.push_back(registryPckg); |
|
730 } |
|
731 |
|
732 return packageList; |
|
733 } |
|
734 |
|
735 Properties DbHelper::GetProperties( TInt32 aComponentId ) const |
|
736 { |
|
737 std::vector<SisRegistryProperty*> propList; |
|
738 |
|
739 int propCount = GetComponentPropertyIntValue(aComponentId,DbConstants::CompPropertyCount, DbConstants::KDefaultCompPropertyCount); |
|
740 |
|
741 for(int count=0 ; count<propCount ; ++count) |
|
742 { |
|
743 TUint32 key = GetComponentPropertyIntFormattedValue(aComponentId, DbConstants::CompPropertyKey, count); |
|
744 TUint32 value = GetComponentPropertyIntFormattedValue(aComponentId, DbConstants::CompPropertyValue, count); |
|
745 SisRegistryProperty* regProp = new SisRegistryProperty(); |
|
746 regProp->SetKey(key); |
|
747 regProp->SetValue(value); |
|
748 propList.push_back(regProp); |
|
749 } |
|
750 |
|
751 return propList; |
|
752 } |
|
753 |
|
754 TrustStatus DbHelper::GetTrustStatus( TInt32 aComponentId ) const |
|
755 { |
|
756 TrustStatus trustStatus; |
|
757 |
|
758 TUint32 validationStatus = GetComponentPropertyIntValue(aComponentId, DbConstants::CompTrustValidationStatus); |
|
759 |
|
760 trustStatus.SetValidationStatus(validationStatus); |
|
761 |
|
762 return trustStatus; |
|
763 } |
|
764 |
|
765 std::vector<TInt> DbHelper::GetInstallChainIndices( TInt32 aComponentId ) const |
|
766 { |
|
767 std::vector<TInt> installChainIndices; |
|
768 |
|
769 int installChainIndexCount = GetComponentPropertyIntValue(aComponentId,DbConstants::CompInstallChainIndexCount, |
|
770 DbConstants::KDefaultChainIndex); |
|
771 |
|
772 for(int count=0 ; count<installChainIndexCount ; ++count) |
|
773 { |
|
774 TInt chainValue = GetComponentPropertyIntFormattedValue(aComponentId, DbConstants::CompInstallChainIndex, count); |
|
775 installChainIndices.push_back(chainValue); |
|
776 } |
|
777 |
|
778 return installChainIndices; |
|
779 } |
|
780 |
|
781 Sids DbHelper::GetSids( TInt32 aComponentId ) const |
|
782 { |
|
783 std::vector<TUint32> sidList; |
|
784 |
|
785 int sidCount = GetComponentPropertyIntValue(aComponentId,DbConstants::CompSidCount, DbConstants::KDefaultSidCount); |
|
786 |
|
787 for(int count=0 ; count<sidCount ; ++count) |
|
788 { |
|
789 TUint32 sid = GetComponentPropertyIntFormattedValue(aComponentId, DbConstants::CompSid, count); |
|
790 sidList.push_back(sid); |
|
791 } |
|
792 |
|
793 return sidList; |
|
794 } |
|
795 |
|
796 Controllers DbHelper::GetControllerInfo( TInt32 aComponentId ) const |
|
797 { |
|
798 std::vector<ControllerInfo*> controllerInfoList; |
|
799 |
|
800 int controllerCount = GetComponentPropertyIntValue(aComponentId,DbConstants::CompControllerCount, DbConstants::KDefaultControllerCount); |
|
801 |
|
802 for(int count=0 ; count<controllerCount ; ++count) |
|
803 { |
|
804 ControllerInfo* controllerInfo = new ControllerInfo(); |
|
805 std::wstring strVersion = GetComponentPropertyStrValue(aComponentId, DbConstants::CompControllerVersion, count); |
|
806 Version version = FormatStringToVersion(strVersion); |
|
807 |
|
808 TInt offset = GetComponentPropertyIntFormattedValue(aComponentId, DbConstants::CompControllerOffset, count); |
|
809 TInt hashAlgo = GetComponentPropertyIntFormattedValue(aComponentId, DbConstants::CompControllerHashAlgorithm, count); |
|
810 std::string hashData(wstring2string(GetComponentPropertyStrValue(aComponentId, DbConstants::CompControllerHashData, count))); |
|
811 HashContainer hashContainer; |
|
812 hashContainer.SetHashId(hashAlgo); |
|
813 hashContainer.SetData(hashData); |
|
814 |
|
815 controllerInfo->SetVersion(version); |
|
816 controllerInfo->SetOffset(offset); |
|
817 controllerInfo->SetHashContainer(hashContainer); |
|
818 |
|
819 controllerInfoList.push_back(controllerInfo); |
|
820 } |
|
821 |
|
822 return controllerInfoList; |
|
823 } |
|
824 |
|
825 TInt DbHelper::GetIndex( TUint32 aPackageUid) const |
|
826 { |
|
827 TInt32 componentId = GetComponentId(aPackageUid); |
|
828 return GetComponentPropertyIntValue(componentId, DbConstants::CompIndex); |
|
829 } |
|
830 |
|
831 TInt32 DbHelper::GetComponentPropertyIntValue(TInt32 aComponentId, std::wstring aComponentPropertyName, TInt32 aDefaultValue) const |
|
832 { |
|
833 TInt32 propertyValue = 0; |
|
834 |
|
835 std::string selectIntProperty("SELECT IntValue FROM ComponentProperties WHERE ComponentId=? and Name=?;"); |
|
836 std::auto_ptr<CStatement> stmtCompProperty(iScrDbHandler->PrepareStatement(selectIntProperty)); |
|
837 |
|
838 stmtCompProperty->BindInt(1, aComponentId); |
|
839 stmtCompProperty->BindStr(2, aComponentPropertyName); |
|
840 |
|
841 if(!stmtCompProperty->ProcessNextRow()) |
|
842 return aDefaultValue; |
|
843 |
|
844 return stmtCompProperty->IntColumn(0); |
|
845 } |
|
846 |
|
847 TInt32 DbHelper::GetComponentPropertyIntFormattedValue(TInt32 aComponentId, std::wstring aComponentPropertyName, TInt32 aIntFormatter) const |
|
848 { |
|
849 TInt32 propertyValue = 0; |
|
850 |
|
851 std::string selectIntProperty("SELECT IntValue FROM ComponentProperties WHERE ComponentId=? and Name=?;"); |
|
852 std::auto_ptr<CStatement> stmtCompProperty(iScrDbHandler->PrepareStatement(selectIntProperty)); |
|
853 |
|
854 std::wstring formattedCompPropName = FormatDbString(aComponentPropertyName, aIntFormatter); |
|
855 |
|
856 stmtCompProperty->BindInt(1, aComponentId); |
|
857 stmtCompProperty->BindStr(2, formattedCompPropName); |
|
858 |
|
859 if(!stmtCompProperty->ProcessNextRow()) |
|
860 return DbHelper::Absent; |
|
861 |
|
862 return stmtCompProperty->IntColumn(0); |
|
863 } |
|
864 |
|
865 std::wstring DbHelper::GetComponentPropertyStrValue(TInt32 aComponentId, std::wstring aComponentPropertyName) const |
|
866 { |
|
867 TInt32 propertyValue = 0; |
|
868 |
|
869 std::string selectStrProperty("SELECT StrValue FROM ComponentProperties WHERE ComponentId=? and Name=?;"); |
|
870 std::auto_ptr<CStatement> stmtCompProperty(iScrDbHandler->PrepareStatement(selectStrProperty)); |
|
871 |
|
872 stmtCompProperty->BindInt(1, aComponentId); |
|
873 stmtCompProperty->BindStr(2, aComponentPropertyName); |
|
874 |
|
875 if(!stmtCompProperty->ProcessNextRow()) |
|
876 return NULL; |
|
877 |
|
878 return stmtCompProperty->StrColumn(0); |
|
879 } |
|
880 |
|
881 std::wstring DbHelper::GetComponentPropertyStrValue(TInt32 aComponentId, std::wstring aComponentPropertyName, TInt32 aIntFormatter) const |
|
882 { |
|
883 |
|
884 std::wstring formattedCompPropName = FormatDbString(aComponentPropertyName, aIntFormatter); |
|
885 |
|
886 return GetComponentPropertyStrValue(aComponentId, formattedCompPropName); |
|
887 } |
|
888 |
|
889 std::wstring DbHelper::FormatDbString(std::wstring aString, int aValue) const |
|
890 { |
|
891 std::wstringstream formatter; |
|
892 formatter << aString << aValue; |
|
893 return formatter.str(); |
|
894 } |
|
895 |
|
896 Version DbHelper::FormatStringToVersion(std::wstring aVersionStr) const |
|
897 { |
|
898 |
|
899 std::wstringstream strMajor(aVersionStr.substr(0,1)); |
|
900 int major = 0; |
|
901 strMajor >> major; |
|
902 std::wstringstream strMinor(aVersionStr.substr(2,3)); |
|
903 int minor = 0; |
|
904 strMinor >> minor; |
|
905 std::wstringstream strBuild(aVersionStr.substr(4,4)); |
|
906 int build = 0; |
|
907 strBuild >> build; |
|
908 |
|
909 return Version(major,minor,build); |
|
910 |
|
911 } |