|
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 "dblayer.h" |
|
20 #include "exception.h" |
|
21 #include "logs.h" |
|
22 #include "util.h" |
|
23 #include "symbiantypes.h" |
|
24 |
|
25 #include <string> |
|
26 #include <vector> |
|
27 #include <algorithm> |
|
28 #include <sstream> |
|
29 #include <ctime> |
|
30 #include <iostream> |
|
31 |
|
32 #include <memory> |
|
33 #include "toolsconf.h" |
|
34 |
|
35 typedef std::vector<std::string>::iterator StringIterator; |
|
36 typedef std::vector<std::string>::const_iterator ConstStringIterator; |
|
37 typedef std::vector<std::wstring>::const_iterator ConstWstringIterator; |
|
38 typedef std::vector<XmlDetails::TScrEnvironmentDetails>::const_iterator ScrEnvIterator; |
|
39 typedef std::vector<XmlDetails::TScrEnvironmentDetails::TLocalizedSoftwareTypeName>::const_iterator ScrEnvLocSwTypeNameIterator; |
|
40 typedef std::vector<XmlDetails::TScrPreProvisionDetail::TComponent>::const_iterator CompIterator; |
|
41 typedef std::vector<XmlDetails::TScrPreProvisionDetail::TComponentLocalizable>::const_iterator CompLocIterator; |
|
42 typedef std::vector<XmlDetails::TScrPreProvisionDetail::TComponentProperty>::const_iterator CompPropIterator; |
|
43 typedef std::vector<XmlDetails::TScrPreProvisionDetail::TComponentFile>::const_iterator CompFileIter; |
|
44 typedef std::vector<XmlDetails::TScrPreProvisionDetail::TComponentFile::TFileProperty>::const_iterator FilePropIterator; |
|
45 |
|
46 const int KMaxDrives=26; |
|
47 |
|
48 CDbLayer::CDbLayer(const std::string& aDllPath, const std::string& aSqlDbName) |
|
49 { |
|
50 iScrDbHandler = new CDbProcessor(aDllPath, aSqlDbName); |
|
51 } |
|
52 |
|
53 CDbLayer::~CDbLayer() |
|
54 { |
|
55 delete iScrDbHandler; |
|
56 } |
|
57 |
|
58 void CDbLayer::CreateScrDatabase(const std::vector<std::string>& aCreateDbQueries) |
|
59 { |
|
60 for (ConstStringIterator schemaIterator=aCreateDbQueries.begin() ; schemaIterator < aCreateDbQueries.end(); ++schemaIterator ) |
|
61 { |
|
62 ExecuteStatement(*schemaIterator); |
|
63 } |
|
64 } |
|
65 |
|
66 void CDbLayer::PopulateScrDatabase(const std::vector<XmlDetails::TScrEnvironmentDetails>& aScrEnvDetails) |
|
67 { |
|
68 try |
|
69 { |
|
70 std::string beginTransaction("BEGIN;"); |
|
71 ExecuteStatement(beginTransaction); |
|
72 PopulateDatabase(aScrEnvDetails); |
|
73 std::string commitTransaction("COMMIT;"); |
|
74 ExecuteStatement(commitTransaction); |
|
75 } |
|
76 catch(CException& /*aException*/) |
|
77 { |
|
78 std::string rollbackTransaction("ROLLBACK;"); |
|
79 ExecuteStatement(rollbackTransaction); |
|
80 std::string errMsg = "Failed to populate SCR database with environment details."; |
|
81 LOGERROR(errMsg); |
|
82 throw CException(errMsg,ExceptionCodes::ESqlCorrupt); |
|
83 } |
|
84 } |
|
85 |
|
86 void CDbLayer::PopulatePreProvisionDetails(const XmlDetails::TScrPreProvisionDetail& aPreProvisionDetailList) |
|
87 { |
|
88 try |
|
89 { |
|
90 AddPreProvisionDetails(aPreProvisionDetailList); |
|
91 } |
|
92 catch(CException& aException) |
|
93 { |
|
94 std::string rollbackTransaction("ROLLBACK;"); |
|
95 ExecuteStatement(rollbackTransaction); |
|
96 std::string errMsg = "Failed to populate SCR database with environment details."; |
|
97 LOGERROR(aException.GetMessageA()); |
|
98 throw CException(errMsg,ExceptionCodes::ESqlCorrupt); |
|
99 } |
|
100 } |
|
101 |
|
102 void ExecuteSwTypeNameStatement(const std::auto_ptr<CStatement>& aStatement, unsigned long aSwTypeId, TInt aLocale, const std::wstring& aSwTypeName) |
|
103 { |
|
104 aStatement->BindInt(1, aSwTypeId); |
|
105 aStatement->BindInt(2, aLocale); |
|
106 aStatement->BindStr(3, aSwTypeName); |
|
107 aStatement->ExecuteStatement(); |
|
108 aStatement->Reset(); |
|
109 } |
|
110 |
|
111 void CDbLayer::PopulateDatabase(const std::vector<XmlDetails::TScrEnvironmentDetails>& aScrEnvDetails) |
|
112 { |
|
113 std::string insertSoftwareType("INSERT INTO SoftwareTypes(SoftwareTypeId,SifPluginUid,InstallerSecureId,ExecutionLayerSecureId) VALUES(?,?,?,?);"); |
|
114 std::auto_ptr<CStatement> stmtSwType(iScrDbHandler->PrepareStatement(insertSoftwareType)); |
|
115 |
|
116 std::string insertSwTypeName("INSERT INTO SoftwareTypeNames(SoftwareTypeId,Locale,Name) VALUES(?,?,?);"); |
|
117 std::auto_ptr<CStatement> stmtSwTypeName(iScrDbHandler->PrepareStatement(insertSwTypeName)); |
|
118 |
|
119 std::string insertMimeType("INSERT INTO MimeTypes(SoftwareTypeId,MimeType) VALUES(?,?);"); |
|
120 std::auto_ptr<CStatement> stmtMimeType(iScrDbHandler->PrepareStatement(insertMimeType)); |
|
121 |
|
122 for(ScrEnvIterator aScrEnvIterator = aScrEnvDetails.begin(); aScrEnvIterator != aScrEnvDetails.end(); ++aScrEnvIterator) |
|
123 { |
|
124 unsigned int swTypeId = Util::Crc32(aScrEnvIterator->iUniqueSoftwareTypeName.c_str(),aScrEnvIterator->iUniqueSoftwareTypeName.length()*2); |
|
125 stmtSwType->BindInt(1, swTypeId); |
|
126 stmtSwType->BindInt(2, aScrEnvIterator->iSifPluginUid); |
|
127 stmtSwType->BindInt(3, aScrEnvIterator->iInstallerSid); |
|
128 stmtSwType->BindInt(4, aScrEnvIterator->iExecutionLayerSid); |
|
129 stmtSwType->ExecuteStatement(); |
|
130 stmtSwType->Reset(); |
|
131 // First insert unique sw type name |
|
132 const TInt uniqueSwTypeNameLocale = 0; |
|
133 ExecuteSwTypeNameStatement(stmtSwTypeName, swTypeId, uniqueSwTypeNameLocale, aScrEnvIterator->iUniqueSoftwareTypeName); |
|
134 // Then, insert localized sw type names. |
|
135 for(ScrEnvLocSwTypeNameIterator swTypeNameIter = aScrEnvIterator->iLocalizedSoftwareTypeNames.begin(); swTypeNameIter != aScrEnvIterator->iLocalizedSoftwareTypeNames.end(); ++swTypeNameIter) |
|
136 { |
|
137 ExecuteSwTypeNameStatement(stmtSwTypeName, swTypeId, swTypeNameIter->iLocale, swTypeNameIter->iName); |
|
138 } |
|
139 for(ConstWstringIterator mimeIter= aScrEnvIterator->iMIMEDetails.begin(); mimeIter != aScrEnvIterator->iMIMEDetails.end(); ++mimeIter) |
|
140 { |
|
141 stmtMimeType->BindInt(1, swTypeId); |
|
142 stmtMimeType->BindStr(2, *mimeIter); |
|
143 stmtMimeType->ExecuteStatement(); |
|
144 stmtMimeType->Reset(); |
|
145 } |
|
146 } |
|
147 |
|
148 } |
|
149 |
|
150 void CDbLayer::AddPreProvisionDetails(const XmlDetails::TScrPreProvisionDetail& aPreProvisionDetailList) |
|
151 { |
|
152 for(CompIterator aCompIterator = aPreProvisionDetailList.iComponents.begin(); aCompIterator != aPreProvisionDetailList.iComponents.end(); ++aCompIterator) |
|
153 { |
|
154 std::string beginTransaction("BEGIN;"); |
|
155 ExecuteStatement(beginTransaction); |
|
156 |
|
157 AddComponentDetails(*aCompIterator, aPreProvisionDetailList.iSoftwareTypeName); |
|
158 int componentId = iScrDbHandler->LastInsertedId(); |
|
159 AddComponentLocalizables(componentId,aCompIterator->iComponentLocalizables); |
|
160 AddComponentProperties(componentId,aCompIterator->iComponentProperties); |
|
161 AddComponentFiles(componentId,aCompIterator->iComponentFiles); |
|
162 AddComponentDependencies(componentId, aCompIterator->iComponentDependency, aPreProvisionDetailList.iSoftwareTypeName); |
|
163 |
|
164 std::string commitTransaction("COMMIT;"); |
|
165 ExecuteStatement(commitTransaction); |
|
166 |
|
167 } |
|
168 } |
|
169 |
|
170 void CDbLayer::AddComponentDetails(const XmlDetails::TScrPreProvisionDetail::TComponent& aComponent, const std::wstring& aSoftwareTypeName) |
|
171 { |
|
172 std::string insertComponents; |
|
173 XmlDetails::TScrPreProvisionDetail::TComponentDetails |
|
174 componentDetail = aComponent.iComponentDetails; |
|
175 |
|
176 unsigned int swTypeId = Util::Crc32(aSoftwareTypeName.c_str(),aSoftwareTypeName.length()*2); |
|
177 std::wstring strGlobalId = componentDetail.iGlobalId; |
|
178 |
|
179 if(!strGlobalId.empty()) |
|
180 { |
|
181 insertComponents = "INSERT INTO Components(SoftwareTypeId, SoftwareTypeName, Removable, Size, ScomoState, InstalledDrives, OriginVerified, Hidden, GlobalIdHash, GlobalId, Version, InstallTime) VALUES(?,?,?,?,?,?,?,?,?,?,?,?);"; |
|
182 } |
|
183 else |
|
184 { |
|
185 insertComponents = "INSERT INTO Components(SoftwareTypeId, SoftwareTypeName, Removable, Size, ScomoState, InstalledDrives, OriginVerified, Hidden, Version, InstallTime) VALUES(?,?,?,?,?,?,?,?,?,?);"; |
|
186 } |
|
187 |
|
188 std::auto_ptr<CStatement> stmtComponents(iScrDbHandler->PrepareStatement(insertComponents)); |
|
189 |
|
190 |
|
191 stmtComponents->BindInt(1, swTypeId); |
|
192 stmtComponents->BindStr(2, aSoftwareTypeName); |
|
193 stmtComponents->BindInt(3, componentDetail.iIsRemovable); |
|
194 stmtComponents->BindInt64(4, componentDetail.iSize); |
|
195 stmtComponents->BindInt(5, componentDetail.iScomoState); |
|
196 |
|
197 // the installed drives has to be retrieved and calculated from the list of files |
|
198 int installedDrives = GetInstalledDrives(aComponent.iComponentFiles); |
|
199 |
|
200 stmtComponents->BindInt(6, installedDrives); |
|
201 stmtComponents->BindInt(7, componentDetail.iOriginVerified); |
|
202 stmtComponents->BindInt(8, componentDetail.iIsHidden); |
|
203 |
|
204 std::wstring version; |
|
205 version = componentDetail.iVersion.iMajor+L"." \ |
|
206 + componentDetail.iVersion.iMinor+L"." \ |
|
207 + componentDetail.iVersion.iBuild ; |
|
208 |
|
209 std::wstring localTime = GetLocalTime(); |
|
210 |
|
211 if(!strGlobalId.empty()) |
|
212 { |
|
213 std::wstring concatGlobalId = aSoftwareTypeName + L'\0' + strGlobalId; |
|
214 unsigned int globalIdHash = Util::Crc32(concatGlobalId.c_str(),concatGlobalId.length()*2); |
|
215 stmtComponents->BindInt(9, globalIdHash); |
|
216 stmtComponents->BindStr(10, concatGlobalId); |
|
217 stmtComponents->BindStr(11, version); |
|
218 stmtComponents->BindStr(12, localTime); |
|
219 } |
|
220 else |
|
221 { |
|
222 stmtComponents->BindStr(9, version); |
|
223 stmtComponents->BindStr(10, localTime); |
|
224 } |
|
225 |
|
226 stmtComponents->ExecuteStatement(); |
|
227 stmtComponents->Reset(); |
|
228 |
|
229 } |
|
230 |
|
231 int CDbLayer::GetInstalledDrives(const std::vector<XmlDetails::TScrPreProvisionDetail::TComponentFile>& aComponentFiles ) |
|
232 { |
|
233 int installedDrives = 0; |
|
234 for(CompFileIter compFileIter = aComponentFiles.begin(); compFileIter != aComponentFiles.end(); ++compFileIter) |
|
235 { |
|
236 if(compFileIter->iLocation.empty()) |
|
237 continue; |
|
238 |
|
239 char drive = static_cast<char>(compFileIter->iLocation[0]); |
|
240 drive = tolower(drive); |
|
241 |
|
242 if(drive < 'a' || drive > 'z' ) |
|
243 { |
|
244 throw CException("Invalid drive specified in file location.",ExceptionCodes::EInvalidArgument); |
|
245 } |
|
246 |
|
247 installedDrives |= 1 << (drive-'a'); |
|
248 |
|
249 } |
|
250 return installedDrives; |
|
251 } |
|
252 |
|
253 const std::wstring CDbLayer::GetLocalTime() |
|
254 { |
|
255 time_t localTime; |
|
256 localTime = time(NULL); |
|
257 tm* ttm = localtime(&localTime); |
|
258 |
|
259 const std::wstring year = Util::IntegerToWideString(ttm->tm_year + 1900); |
|
260 const std::wstring month = Util::IntegerToWideString(ttm->tm_mon+1); |
|
261 const std::wstring day = Util::IntegerToWideString(ttm->tm_mday); |
|
262 const std::wstring hour = Util::IntegerToWideString(ttm->tm_hour); |
|
263 const std::wstring minute = Util::IntegerToWideString(ttm->tm_min); |
|
264 const std::wstring second = Util::IntegerToWideString(ttm->tm_sec); |
|
265 |
|
266 wchar_t result[16]={0}; |
|
267 result[16] = '0'; |
|
268 |
|
269 #ifdef GCC_COMPILER |
|
270 swprintf(result,(sizeof(result)/sizeof(wchar_t)),L"%04s%02s%02s:%02s%02s%02s",year.c_str(),month.c_str(),day.c_str(),hour.c_str(),minute.c_str(),second.c_str()); |
|
271 #else |
|
272 swprintf(result,L"%04s%02s%02s:%02s%02s%02s",year.c_str(),month.c_str(),day.c_str(),hour.c_str(),minute.c_str(),second.c_str()); |
|
273 #endif |
|
274 std::wstring wstr(result); |
|
275 return wstr; |
|
276 } |
|
277 |
|
278 void CDbLayer::AddComponentLocalizables( int aComponentId, const std::vector<XmlDetails::TScrPreProvisionDetail::TComponentLocalizable>& aComponentLocalizable) |
|
279 { |
|
280 std::string insertComponentLocalizable("INSERT INTO ComponentLocalizables(ComponentId,Locale,Name,Vendor) VALUES(?,?,?,?);"); |
|
281 std::auto_ptr<CStatement> stmtComponentLocalizable(iScrDbHandler->PrepareStatement(insertComponentLocalizable)); |
|
282 |
|
283 for(CompLocIterator compLocIter = aComponentLocalizable.begin(); compLocIter != aComponentLocalizable.end() ; ++compLocIter ) |
|
284 { |
|
285 stmtComponentLocalizable->BindInt(1, aComponentId); |
|
286 stmtComponentLocalizable->BindInt(2, compLocIter->iLocale); |
|
287 stmtComponentLocalizable->BindStr(3, compLocIter->iName); |
|
288 stmtComponentLocalizable->BindStr(4, compLocIter->iVendor); |
|
289 stmtComponentLocalizable->ExecuteStatement(); |
|
290 stmtComponentLocalizable->Reset(); |
|
291 } |
|
292 } |
|
293 |
|
294 void CDbLayer::AddComponentProperties( |
|
295 int aComponentId, |
|
296 const std::vector<XmlDetails::TScrPreProvisionDetail::TComponentProperty>& aComponentProperty) |
|
297 { |
|
298 |
|
299 std::string insertComponentProperties; |
|
300 |
|
301 for(CompPropIterator compPropIter = aComponentProperty.begin(); compPropIter != aComponentProperty.end() ; ++compPropIter ) |
|
302 { |
|
303 if(compPropIter->iIsIntValue == 1) |
|
304 { |
|
305 insertComponentProperties = "INSERT INTO ComponentProperties(Name,Locale,ComponentId,IntValue,IsStr8Bit) VALUES(?,?,?,?,?);"; |
|
306 } |
|
307 else |
|
308 { |
|
309 insertComponentProperties = "INSERT INTO ComponentProperties(Name,Locale,ComponentId,StrValue,IsStr8Bit) VALUES(?,?,?,?,?);"; |
|
310 } |
|
311 std::auto_ptr<CStatement> stmtComponentProperty(iScrDbHandler->PrepareStatement(insertComponentProperties)); |
|
312 |
|
313 stmtComponentProperty->BindStr(1, compPropIter->iName); |
|
314 stmtComponentProperty->BindInt(2, compPropIter->iLocale); |
|
315 stmtComponentProperty->BindInt(3, aComponentId); |
|
316 if(compPropIter->iIsIntValue == 1) |
|
317 { |
|
318 TInt64 intValue = Util::WideCharToInt64(compPropIter->iValue.c_str()); |
|
319 stmtComponentProperty->BindInt64(4, intValue); |
|
320 } |
|
321 else |
|
322 { |
|
323 if(compPropIter->iIsStr8Bit) |
|
324 { |
|
325 std::string str = Util::wstring2string(compPropIter->iValue); |
|
326 std::string decodedString = Util::Base64Decode(str); |
|
327 stmtComponentProperty->BindBinary(4, str); |
|
328 } |
|
329 else |
|
330 { |
|
331 stmtComponentProperty->BindStr(4, compPropIter->iValue); |
|
332 } |
|
333 } |
|
334 |
|
335 |
|
336 stmtComponentProperty->BindInt(5, compPropIter->iIsStr8Bit); |
|
337 |
|
338 stmtComponentProperty->ExecuteStatement(); |
|
339 stmtComponentProperty->Reset(); |
|
340 } |
|
341 |
|
342 } |
|
343 |
|
344 void CDbLayer::AddComponentFiles(int aComponentId, const std::vector<XmlDetails::TScrPreProvisionDetail::TComponentFile>& aComponentFiles) |
|
345 { |
|
346 for(CompFileIter compFile = aComponentFiles.begin() ; compFile != aComponentFiles.end() ; ++compFile) |
|
347 { |
|
348 AddLocation(aComponentId,compFile->iLocation); |
|
349 int cmpFileId = iScrDbHandler->LastInsertedId(); |
|
350 AddFileProperties(cmpFileId,compFile->iFileProperties); |
|
351 |
|
352 } |
|
353 } |
|
354 |
|
355 |
|
356 void CDbLayer::AddComponentDependencies ( int aComponentId, |
|
357 const XmlDetails::TScrPreProvisionDetail::TComponentDependency& aComponentDependency, |
|
358 const std::wstring& aSoftwareTypeName |
|
359 ) |
|
360 { |
|
361 std::wstring dependentId = aComponentDependency.iDependentId; |
|
362 |
|
363 if(dependentId.empty()) |
|
364 return; |
|
365 |
|
366 std::wstring dependantGlobalId = aSoftwareTypeName + L'\0' + dependentId; |
|
367 |
|
368 const std::vector<XmlDetails::TScrPreProvisionDetail::TComponentDependency::TComponentDependencyDetail> |
|
369 aComponentDependencyDetails = aComponentDependency.iComponentDependencyList; |
|
370 |
|
371 std::vector<XmlDetails::TScrPreProvisionDetail::TComponentDependency::TComponentDependencyDetail>::const_iterator compDepIter; |
|
372 |
|
373 for(compDepIter = aComponentDependencyDetails.begin() ; compDepIter != aComponentDependencyDetails.end() ; ++compDepIter) |
|
374 { |
|
375 std::wstring concatGlobalId = dependantGlobalId + compDepIter->iSupplierId; |
|
376 |
|
377 unsigned int globalIdHash = Util::Crc32(concatGlobalId.c_str(),concatGlobalId.length()*2); |
|
378 unsigned int dependantIdHash = Util::Crc32(dependantGlobalId.c_str(),dependantGlobalId.length()*2); |
|
379 unsigned int supplierIdHash = Util::Crc32(compDepIter->iSupplierId.c_str(),compDepIter->iSupplierId.length()*2); |
|
380 |
|
381 std::string insertComponentDeps("INSERT INTO ComponentDependencies(GlobalIdHash,DependantGlobalIdHash, SupplierGlobalIdHash, DependantGlobalId,SupplierGlobalId,VersionFrom,VersionTo) VALUES(?,?,?,?,?,?,?);"); |
|
382 std::auto_ptr<CStatement> stmtComponentDeps(iScrDbHandler->PrepareStatement(insertComponentDeps)); |
|
383 |
|
384 stmtComponentDeps->BindInt( 1 ,globalIdHash); |
|
385 stmtComponentDeps->BindInt( 2 ,dependantIdHash); |
|
386 stmtComponentDeps->BindInt( 3 ,supplierIdHash); |
|
387 stmtComponentDeps->BindStr( 4 ,dependentId); |
|
388 stmtComponentDeps->BindStr( 5 ,compDepIter->iSupplierId); |
|
389 stmtComponentDeps->BindStr( 6 ,compDepIter->iFromVersion); |
|
390 stmtComponentDeps->BindStr( 7 ,compDepIter->iToVersion); |
|
391 |
|
392 stmtComponentDeps->ExecuteStatement(); |
|
393 stmtComponentDeps->Reset(); |
|
394 |
|
395 } |
|
396 } |
|
397 |
|
398 |
|
399 void CDbLayer::AddLocation(int aComponentId, const std::wstring& aLocation) |
|
400 { |
|
401 std::string insertComponentFileDetails("INSERT INTO ComponentsFiles(ComponentId,LocationHash,Location) VALUES(?,?,?);"); |
|
402 std::auto_ptr<CStatement> stmtComponentFileDetails(iScrDbHandler->PrepareStatement(insertComponentFileDetails)); |
|
403 |
|
404 stmtComponentFileDetails->BindInt(1,aComponentId); |
|
405 |
|
406 // size does not return the actual binary size of the object |
|
407 int length = aLocation.length()*2 ; |
|
408 // generate hash for location |
|
409 std::wstring location = aLocation; |
|
410 std::transform( location.begin(), location.end(), location.begin(), tolower); |
|
411 |
|
412 unsigned int hash = Util::Crc32(location.c_str(),length); |
|
413 |
|
414 stmtComponentFileDetails->BindInt(2,hash); |
|
415 stmtComponentFileDetails->BindStr(3,aLocation); |
|
416 stmtComponentFileDetails->ExecuteStatement(); |
|
417 stmtComponentFileDetails->Reset(); |
|
418 |
|
419 } |
|
420 |
|
421 void CDbLayer::AddFileProperties(int aCmpFileId, const std::vector<XmlDetails::TScrPreProvisionDetail::TComponentFile::TFileProperty>& aFileProperty) |
|
422 { |
|
423 std::string insertFileProperties; |
|
424 |
|
425 for(FilePropIterator filePropIter = aFileProperty.begin(); filePropIter != aFileProperty.end() ; ++filePropIter ) |
|
426 { |
|
427 if(filePropIter->iIsIntValue == 1) |
|
428 { |
|
429 insertFileProperties = "INSERT INTO FileProperties(Name,CmpFileId,IntValue) VALUES(?,?,?);"; |
|
430 } |
|
431 else |
|
432 { |
|
433 insertFileProperties = "INSERT INTO FileProperties(Name,CmpFileId,StrValue,IsStr8Bit) VALUES(?,?,?,?);"; |
|
434 } |
|
435 std::auto_ptr<CStatement> stmtFileProperty(iScrDbHandler->PrepareStatement(insertFileProperties)); |
|
436 |
|
437 stmtFileProperty->BindStr(1, filePropIter->iName); |
|
438 stmtFileProperty->BindInt(2, aCmpFileId); |
|
439 |
|
440 // we know by default the locale is 0 for file properties |
|
441 // hence for setting the IsStr8Bit all we need to check is whether |
|
442 // IntValue is present or not |
|
443 if(filePropIter->iIsIntValue) |
|
444 { |
|
445 int intValue = Util::WideCharToInteger(filePropIter->iValue.c_str()); |
|
446 stmtFileProperty->BindInt(3, intValue); |
|
447 } |
|
448 else |
|
449 { |
|
450 std::string str = Util::wstring2string(filePropIter->iValue); |
|
451 std::string decodedString = Util::Base64Decode(str); |
|
452 stmtFileProperty->BindBinary(3, str); |
|
453 stmtFileProperty->BindInt(4, 1); |
|
454 } |
|
455 |
|
456 stmtFileProperty->ExecuteStatement(); |
|
457 stmtFileProperty->Reset(); |
|
458 } |
|
459 } |
|
460 |
|
461 void CDbLayer::ExecuteStatement(const std::string& aStmtStr) |
|
462 { |
|
463 std::auto_ptr<CStatement> stmt(iScrDbHandler->PrepareStatement(aStmtStr)); |
|
464 stmt->ExecuteStatement(); |
|
465 } |