40 // |
38 // |
41 // --------------------------------------------------------------------------- |
39 // --------------------------------------------------------------------------- |
42 // |
40 // |
43 void CCaSqLiteStorage::ConstructL() |
41 void CCaSqLiteStorage::ConstructL() |
44 { |
42 { |
45 RFs rfs; |
43 User::LeaveIfError( iRfs.Connect() ); |
46 CleanupClosePushL( rfs ); |
44 |
47 User::LeaveIfError( rfs.Connect() ); |
45 User::LeaveIfError( CreatePrivateDirPath( iPrivatePathCDriveDb, KCDrive, |
48 |
46 KDbName ) ); |
49 TFileName privatePathCDriveDb; |
47 |
50 User::LeaveIfError( CreatePrivateDirPath( privatePathCDriveDb, KCDrive, |
48 User::LeaveIfError( CreatePrivateDirPath( iPrivatePathZDriveDb, KZDrive, |
51 KDbName, rfs ) ); |
49 KDbName ) ); |
52 |
50 |
53 TFileName privatePathZDriveDb; |
51 User::LeaveIfError( CreatePrivateDirPath( iPrivatePathCDrive, KCDrive, |
54 User::LeaveIfError( CreatePrivateDirPath( privatePathZDriveDb, KZDrive, |
52 KNullDesC ) ); |
55 KDbName, rfs ) ); |
53 |
56 |
54 if( iSqlDb.Open( iPrivatePathCDriveDb, &KSqlDbConfig ) ) |
57 TFileName privatePathCDrive; |
55 { |
58 User::LeaveIfError( CreatePrivateDirPath( privatePathCDrive, KCDrive, |
56 //we could not load data base from C-drive lets try Rom |
59 KNullDesC, rfs ) ); |
57 LoadDataBaseFromRomL(); |
60 |
58 } |
61 if( iSqlDb.Open( privatePathCDriveDb, &KSqlDbConfig ) ) |
59 } |
62 { |
60 |
63 if( ( BaflUtils::FileExists( rfs, privatePathCDriveDb ) ) ) |
61 // --------------------------------------------------------------------------- |
64 { |
62 // CCASqLiteStorage::NewL() |
65 User::LeaveIfError( BaflUtils::DeleteFile( rfs, |
63 // |
66 privatePathCDriveDb ) ); |
64 // --------------------------------------------------------------------------- |
67 } |
65 // |
68 |
66 void CCaSqLiteStorage::LoadDataBaseFromRomL() |
69 if( !( BaflUtils::FileExists( rfs, privatePathZDriveDb ) ) ) |
67 { |
70 { |
68 if( ( BaflUtils::FileExists( iRfs, iPrivatePathCDriveDb ) ) ) |
71 User::Panic( _L("fatal error - castoragedb not exists in ROM"), |
69 { |
72 KErrNotFound ); |
70 iSqlDb.Close(); |
73 } |
71 User::LeaveIfError( BaflUtils::DeleteFile( iRfs, |
74 else |
72 iPrivatePathCDriveDb ) ); |
75 { |
73 } |
76 if( !( BaflUtils::FolderExists( rfs, privatePathCDrive ) ) ) |
74 |
77 { |
75 if( !( BaflUtils::FileExists( iRfs, iPrivatePathZDriveDb ) ) ) |
78 User::LeaveIfError( rfs.CreatePrivatePath( EDriveC ) ); |
76 { |
79 } |
77 User::Panic( _L("fatal error - castoragedb not exists in ROM"), |
80 User::LeaveIfError( BaflUtils::CopyFile( rfs, |
78 KErrNotFound ); |
81 privatePathZDriveDb, privatePathCDrive ) ); |
79 } |
82 User::LeaveIfError( rfs.SetAtt( privatePathCDriveDb, |
80 else |
83 KEntryAttNormal, KEntryAttReadOnly ) ); |
81 { |
84 User::LeaveIfError( iSqlDb.Open( privatePathCDriveDb, |
82 if( !( BaflUtils::FolderExists( iRfs, iPrivatePathCDrive ) ) ) |
85 &KSqlDbConfig ) ); |
83 { |
86 } |
84 User::LeaveIfError( iRfs.CreatePrivatePath( EDriveC ) ); |
87 } |
85 } |
88 |
86 User::LeaveIfError( BaflUtils::CopyFile( iRfs, |
89 CleanupStack::PopAndDestroy( &rfs ); |
87 iPrivatePathZDriveDb, iPrivatePathCDrive ) ); |
|
88 User::LeaveIfError( iRfs.SetAtt( iPrivatePathCDriveDb, |
|
89 KEntryAttNormal, KEntryAttReadOnly ) ); |
|
90 User::LeaveIfError( iSqlDb.Open( iPrivatePathCDriveDb, |
|
91 &KSqlDbConfig ) ); |
|
92 } |
90 } |
93 } |
91 |
94 |
92 // --------------------------------------------------------------------------- |
95 // --------------------------------------------------------------------------- |
93 // CCASqLiteStorage::NewL() |
96 // CCASqLiteStorage::NewL() |
94 // |
97 // |
120 // --------------------------------------------------------------------------- |
123 // --------------------------------------------------------------------------- |
121 // |
124 // |
122 CCaSqLiteStorage::~CCaSqLiteStorage() |
125 CCaSqLiteStorage::~CCaSqLiteStorage() |
123 { |
126 { |
124 iSqlDb.Close(); |
127 iSqlDb.Close(); |
|
128 iRfs.Close(); |
125 } |
129 } |
126 |
130 |
127 // --------------------------------------------------------------------------- |
131 // --------------------------------------------------------------------------- |
128 // CCaSqLiteStorage::CreatePrivateDirPath() |
132 // CCaSqLiteStorage::CreatePrivateDirPath() |
129 // |
133 // |
130 // --------------------------------------------------------------------------- |
134 // --------------------------------------------------------------------------- |
131 // |
135 // |
132 TInt CCaSqLiteStorage::CreatePrivateDirPath( TFileName& aPrivatePath, |
136 TInt CCaSqLiteStorage::CreatePrivateDirPath( TFileName& aPrivatePath, |
133 const TDesC& aDrive, const TDesC& aDbName, RFs& aFsSession ) |
137 const TDesC& aDrive, const TDesC& aDbName ) |
134 { |
138 { |
135 TInt error( KErrNone ); |
139 TInt error( KErrNone ); |
136 |
140 |
137 #ifdef CONTENT_ARSENAL_STORAGE_UT |
141 #ifdef CONTENT_ARSENAL_STORAGE_UT |
138 TFileName KPathWithoutDrive( KDoubleSlash ); |
142 TFileName KPathWithoutDrive( KDoubleSlash ); |
139 #else |
143 #else |
140 TFileName KPathWithoutDrive; |
144 TFileName KPathWithoutDrive; |
141 error = aFsSession.PrivatePath( KPathWithoutDrive ); |
145 error = iRfs.PrivatePath( KPathWithoutDrive ); |
142 if( error != KErrNone ) |
146 if( error != KErrNone ) |
143 { |
147 { |
144 return error; |
148 return error; |
145 } |
149 } |
146 #endif |
150 #endif |
195 sqlLocalizeEntryQuery->BindValuesForLocalizeL( aLocalization ); |
199 sqlLocalizeEntryQuery->BindValuesForLocalizeL( aLocalization ); |
196 sqlLocalizeEntryQuery->ExecuteL( ); |
200 sqlLocalizeEntryQuery->ExecuteL( ); |
197 CleanupStack::PopAndDestroy( sqlLocalizeEntryQuery ); |
201 CleanupStack::PopAndDestroy( sqlLocalizeEntryQuery ); |
198 } |
202 } |
199 |
203 |
200 void CCaSqLiteStorage::GetLocalizationsL( RPointerArray<CCaLocalizationEntry>& aResultContainer ) |
204 void CCaSqLiteStorage::GetLocalizationsL( |
|
205 RPointerArray<CCaLocalizationEntry>& aResultContainer ) |
201 { |
206 { |
202 CCaSqlQuery* sqlGetLocalizationsQuery = CCaSqlQuery::NewLC( iSqlDb ); |
207 CCaSqlQuery* sqlGetLocalizationsQuery = CCaSqlQuery::NewLC( iSqlDb ); |
203 CaSqlQueryCreator::CreateGetLocalizationsQueryL( sqlGetLocalizationsQuery ); |
208 CaSqlQueryCreator::CreateGetLocalizationsQueryL( |
204 |
209 sqlGetLocalizationsQuery ); |
|
210 |
205 sqlGetLocalizationsQuery->PrepareL(); |
211 sqlGetLocalizationsQuery->PrepareL(); |
206 sqlGetLocalizationsQuery->ExecuteLocalizationsL( aResultContainer ); |
212 sqlGetLocalizationsQuery->ExecuteLocalizationsL( aResultContainer ); |
207 CleanupStack::PopAndDestroy( sqlGetLocalizationsQuery ); |
213 CleanupStack::PopAndDestroy( sqlGetLocalizationsQuery ); |
208 } |
214 } |
209 |
215 |
210 // --------------------------------------------------------------------------- |
216 // --------------------------------------------------------------------------- |
211 // CCASqLiteStorage::GetEntriesIdsL |
217 // CCASqLiteStorage::GetEntriesIdsL |
212 // |
218 // |
213 // --------------------------------------------------------------------------- |
219 // --------------------------------------------------------------------------- |
214 // |
220 // |
215 void CCaSqLiteStorage::GetEntriesIdsL( const CCaInnerQuery* aQuery, |
221 void CCaSqLiteStorage::GetEntriesIdsL( const CCaInnerQuery* aQuery, |
216 RArray<TInt>& aResultIdArray ) |
222 RArray<TInt>& aResultIdArray ) |
217 { |
223 { |
218 CCaSqlQuery* sqlGetEntriesIdsQuery = CCaSqlQuery::NewLC( iSqlDb ); |
224 CCaSqlQuery* sqlGetEntriesIdsQuery = CCaSqlQuery::NewLC( iSqlDb ); |
219 CaSqlQueryCreator::CreateGetEntriesQueryL( aQuery, |
225 CaSqlQueryCreator::CreateGetEntriesQueryL( aQuery, |
220 sqlGetEntriesIdsQuery ); |
226 sqlGetEntriesIdsQuery ); |
296 } |
302 } |
297 ExecuteStatementL( KSqlStatementCommit ); |
303 ExecuteStatementL( KSqlStatementCommit ); |
298 } |
304 } |
299 |
305 |
300 // --------------------------------------------------------------------------- |
306 // --------------------------------------------------------------------------- |
301 // CCASqLiteStorage::OrganizeL( const RArray<TInt>& aEntryIds, |
307 // CCASqLiteStorage::OrganizeL( const RArray<TInt>& aEntryIds, |
302 // TCaOperationParams aParams ) |
308 // TCaOperationParams aParams ) |
303 // |
309 // |
304 // --------------------------------------------------------------------------- |
310 // --------------------------------------------------------------------------- |
305 // |
311 // |
306 void CCaSqLiteStorage::OrganizeL( const RArray<TInt>& aEntryIds, |
312 void CCaSqLiteStorage::OrganizeL( const RArray<TInt>& aEntryIds, |
332 } |
338 } |
333 ExecuteStatementL( KSqlStatementCommit ); |
339 ExecuteStatementL( KSqlStatementCommit ); |
334 } |
340 } |
335 |
341 |
336 // --------------------------------------------------------------------------- |
342 // --------------------------------------------------------------------------- |
337 // CCASqLiteStorage::DbPropertyL( ( const TDesC& aProperty, TDes& aPropertyValue ) |
343 // CCASqLiteStorage::DbPropertyL |
338 // |
344 // ( const TDesC& aProperty, TDes& aPropertyValue ) |
339 // --------------------------------------------------------------------------- |
345 // --------------------------------------------------------------------------- |
340 // |
346 // |
341 void CCaSqLiteStorage::DbPropertyL( const TDesC& aProperty, |
347 void CCaSqLiteStorage::DbPropertyL( const TDesC& aProperty, |
342 TDes& aPropertyValue ) |
348 TDes& aPropertyValue ) |
343 { |
349 { |
350 } |
356 } |
351 ExecuteStatementL( KSqlStatementCommit ); |
357 ExecuteStatementL( KSqlStatementCommit ); |
352 } |
358 } |
353 |
359 |
354 // --------------------------------------------------------------------------- |
360 // --------------------------------------------------------------------------- |
355 // CCASqLiteStorage::SetDBPropertyL( const TDesC& aProperty, const TDesC& aPropertyValue ) |
361 // CCASqLiteStorage::SetDBPropertyL |
356 // |
362 // ( const TDesC& aProperty, const TDesC& aPropertyValue ) |
357 // --------------------------------------------------------------------------- |
363 // --------------------------------------------------------------------------- |
358 // |
364 // |
359 void CCaSqLiteStorage::SetDBPropertyL( const TDesC& aProperty, |
365 void CCaSqLiteStorage::SetDBPropertyL( const TDesC& aProperty, |
360 const TDesC& aPropertyValue ) |
366 const TDesC& aPropertyValue ) |
361 { |
367 { |
384 User::Leave( err ); |
390 User::Leave( err ); |
385 } |
391 } |
386 ExecuteStatementL( KSqlStatementCommit ); |
392 ExecuteStatementL( KSqlStatementCommit ); |
387 } |
393 } |
388 |
394 |
389 |
395 // --------------------------------------------------------------------------- |
390 // --------------------------------------------------------------------------- |
396 // CCaSqLiteStorage::CustomSortL |
391 // CCaSqLiteStorage::CustomSortL( const RArray<TInt>& aEntryIds, const TInt aGroupId ) |
397 // ( const RArray<TInt>& aEntryIds, const TInt aGroupId ) |
392 // |
|
393 // --------------------------------------------------------------------------- |
398 // --------------------------------------------------------------------------- |
394 // |
399 // |
395 void CCaSqLiteStorage::CustomSortL( const RArray<TInt>& aEntryIds, |
400 void CCaSqLiteStorage::CustomSortL( const RArray<TInt>& aEntryIds, |
396 const TInt aGroupId ) |
401 const TInt aGroupId ) |
397 { |
402 { |
398 RPointerArray<CCaSqlQuery> sqlQueries; |
403 RPointerArray<CCaSqlQuery> sqlQueries; |
399 CleanupResetAndDestroyPushL( sqlQueries ); |
404 CleanupResetAndDestroyPushL( sqlQueries ); |
400 |
405 |
401 CaSqlQueryCreator::CreateCustomSortQueryL( aEntryIds, sqlQueries, iSqlDb ); |
406 CaSqlQueryCreator::CreateCustomSortQueryL( |
|
407 aEntryIds, sqlQueries, iSqlDb ); |
402 |
408 |
403 ExecuteStatementL( KSqlStatementBegin ); |
409 ExecuteStatementL( KSqlStatementBegin ); |
404 TRAPD( err, ExecuteCustomSortL( aEntryIds, aGroupId, sqlQueries ) ); |
410 TRAPD( err, ExecuteCustomSortL( aEntryIds, aGroupId, sqlQueries ) ); |
405 if( err ) |
411 if( err ) |
406 { |
412 { |
411 |
417 |
412 CleanupStack::PopAndDestroy( &sqlQueries ); |
418 CleanupStack::PopAndDestroy( &sqlQueries ); |
413 } |
419 } |
414 |
420 |
415 // --------------------------------------------------------------------------- |
421 // --------------------------------------------------------------------------- |
416 // CCaSqLiteStorage::ExecuteCustomSortL( const RArray<TInt>& aEntryIds, const TInt aGroupId ) |
422 // CCaSqLiteStorage::ExecuteCustomSortL |
417 // |
423 // ( const RArray<TInt>& aEntryIds, const TInt aGroupId ) |
418 // --------------------------------------------------------------------------- |
424 // --------------------------------------------------------------------------- |
419 // |
425 // |
420 void CCaSqLiteStorage::ExecuteCustomSortL( const RArray<TInt>& aEntryIds, |
426 void CCaSqLiteStorage::ExecuteCustomSortL( const RArray<TInt>& aEntryIds, |
421 const TInt aGroupId , RPointerArray<CCaSqlQuery>& aSqlQuery ) |
427 const TInt aGroupId , RPointerArray<CCaSqlQuery>& aSqlQuery ) |
422 { |
428 { |
423 for( TInt i = 0; i < aSqlQuery.Count(); i++ ) |
429 for( TInt i = 0; i < aSqlQuery.Count(); i++ ) |
424 { |
430 { |
425 TInt newPosition = i + 1; |
431 TInt newPosition = i + 1; |
426 TInt entryId = aEntryIds[i]; |
432 TInt entryId = aEntryIds[i]; |
427 |
433 |
428 aSqlQuery[i]->PrepareL(); |
434 aSqlQuery[i]->PrepareL(); |
429 aSqlQuery[i]->BindValuesForCustomSortL( aGroupId, entryId, newPosition ); |
435 aSqlQuery[i]->BindValuesForCustomSortL( aGroupId, entryId, newPosition ); |
430 aSqlQuery[i]->ExecuteL(); |
436 aSqlQuery[i]->ExecuteL(); |
431 aSqlQuery[i]->CloseStatement(); |
437 aSqlQuery[i]->CloseStatement(); |
432 } |
438 } |
460 query->ExecuteL(); |
466 query->ExecuteL(); |
461 CleanupStack::PopAndDestroy( query ); |
467 CleanupStack::PopAndDestroy( query ); |
462 } |
468 } |
463 |
469 |
464 // --------------------------------------------------------------------------- |
470 // --------------------------------------------------------------------------- |
465 // CCASqLiteStorage::ExecuteAddL(CCaInnerEntry* aEntry, |
471 // CCASqLiteStorage::ExecuteAddL(CCaInnerEntry* aEntry, |
466 // RPointerArray<CCASqlQuery>& sqlQuery) |
472 // RPointerArray<CCASqlQuery>& sqlQuery) |
467 // |
473 // |
468 // --------------------------------------------------------------------------- |
474 // --------------------------------------------------------------------------- |
469 // |
475 // |
470 void CCaSqLiteStorage::ExecuteAddL( CCaInnerEntry* aEntry, |
476 void CCaSqLiteStorage::ExecuteAddL( CCaInnerEntry* aEntry, |
471 RPointerArray<CCaSqlQuery>& aSqlQuery ) |
477 RPointerArray<CCaSqlQuery>& aSqlQuery ) |
472 { |
478 { |
473 TBool isAttributeDeleted( EFalse ); |
479 TBool isAttributeDeleted( EFalse ); |
474 for( TInt i = 0; i < aSqlQuery.Count(); i++ ) |
480 for( TInt i = 0; i < aSqlQuery.Count(); i++ ) |
475 { |
481 { |
482 query->PrepareL(); |
488 query->PrepareL(); |
483 query->BindValuesForGetIconL( aEntry ); |
489 query->BindValuesForGetIconL( aEntry ); |
484 CCaInnerEntry::TIconAttributes iconAttributes; |
490 CCaInnerEntry::TIconAttributes iconAttributes; |
485 TInt countIcons = query->ExecuteL( iconAttributes ); |
491 TInt countIcons = query->ExecuteL( iconAttributes ); |
486 CleanupStack::PopAndDestroy( query ); |
492 CleanupStack::PopAndDestroy( query ); |
487 |
493 |
488 aSqlQuery[i]->PrepareL(); |
494 aSqlQuery[i]->PrepareL(); |
489 aSqlQuery[i]->BindValuesForAddL( aEntry ); |
495 aSqlQuery[i]->BindValuesForAddL( aEntry ); |
490 TInt tmpId( 0 ); |
496 TInt tmpId( 0 ); |
491 TRAPD( err, tmpId = aSqlQuery[i]->ExecuteL() ); |
497 TRAPD( err, tmpId = aSqlQuery[i]->ExecuteL() ); |
492 aSqlQuery[i]->CloseStatement(); |
498 aSqlQuery[i]->CloseStatement(); |
637 case CCaSqlQuery::EGroupTableInsert: |
643 case CCaSqlQuery::EGroupTableInsert: |
638 { |
644 { |
639 sqlQueries[i]->PrepareL(); |
645 sqlQueries[i]->PrepareL(); |
640 for( TInt j = 0; j < aEntryIds.Count(); j++ ) |
646 for( TInt j = 0; j < aEntryIds.Count(); j++ ) |
641 { |
647 { |
642 TInt k = (revereseInsertOrder) ? |
648 TInt k = (revereseInsertOrder) ? |
643 (aEntryIds.Count() - 1) - j : j; |
649 (aEntryIds.Count() - 1) - j : j; |
644 sqlQueries[i]->BindValuesForOrganizeL( |
650 sqlQueries[i]->BindValuesForOrganizeL( |
645 aEntryIds, aParams, aEntryIds[k] ); |
651 aEntryIds, aParams, aEntryIds[k] ); |
646 sqlQueries[i]->ExecuteL(); |
652 sqlQueries[i]->ExecuteL(); |
647 sqlQueries[i]->ResetStatement(); |
653 sqlQueries[i]->ResetStatement(); |
648 } |
654 } |
649 sqlQueries[i]->CloseStatement(); |
655 sqlQueries[i]->CloseStatement(); |