51 KDbName ) ); |
51 KDbName ) ); |
52 |
52 |
53 User::LeaveIfError( CreatePrivateDirPath( iPrivatePathCDrive, KCDrive, |
53 User::LeaveIfError( CreatePrivateDirPath( iPrivatePathCDrive, KCDrive, |
54 KNullDesC ) ); |
54 KNullDesC ) ); |
55 |
55 |
|
56 User::LeaveIfError( CreatePrivateDirPath( iPrivatePathCDriveDbBackup, KCDrive, |
|
57 KDbNameBackup ) ); |
|
58 |
56 |
59 |
57 if( iSqlDb.Open( iPrivatePathCDriveDb, &KSqlDbConfig ) ) |
60 if( iSqlDb.Open( iPrivatePathCDriveDb, &KSqlDbConfig ) ) |
58 { |
61 { |
59 //we could not load data base from C-drive lets try Rom |
62 //we could not load data base from C-drive lets try Rom |
60 LoadDataBaseFromRomL(); |
63 LoadDataBaseFromRomL(); |
100 } |
103 } |
101 User::LeaveIfError( BaflUtils::CopyFile( iRfs, |
104 User::LeaveIfError( BaflUtils::CopyFile( iRfs, |
102 iPrivatePathZDriveDb, iPrivatePathCDrive ) ); |
105 iPrivatePathZDriveDb, iPrivatePathCDrive ) ); |
103 User::LeaveIfError( iRfs.SetAtt( iPrivatePathCDriveDb, |
106 User::LeaveIfError( iRfs.SetAtt( iPrivatePathCDriveDb, |
104 KEntryAttNormal, KEntryAttReadOnly ) ); |
107 KEntryAttNormal, KEntryAttReadOnly ) ); |
|
108 User::LeaveIfError( iSqlDb.Open( iPrivatePathCDriveDb, |
|
109 &KSqlDbConfig ) ); |
|
110 } |
|
111 } |
|
112 |
|
113 // --------------------------------------------------------------------------- |
|
114 // |
|
115 // |
|
116 // --------------------------------------------------------------------------- |
|
117 // |
|
118 void CCaSqLiteStorage::SaveDatabaseL() |
|
119 { |
|
120 if( ( BaflUtils::FileExists( iRfs, iPrivatePathCDriveDb ) ) ) |
|
121 { |
|
122 iSqlDb.Close(); |
|
123 User::LeaveIfError( BaflUtils::CopyFile( iRfs, |
|
124 iPrivatePathCDriveDb, iPrivatePathCDriveDbBackup ) ); |
|
125 User::LeaveIfError( iSqlDb.Open( iPrivatePathCDriveDb, |
|
126 &KSqlDbConfig ) ); |
|
127 } |
|
128 } |
|
129 |
|
130 // --------------------------------------------------------------------------- |
|
131 // |
|
132 // |
|
133 // --------------------------------------------------------------------------- |
|
134 // |
|
135 void CCaSqLiteStorage::RestoreDatabaseL() |
|
136 { |
|
137 if( ( BaflUtils::FileExists( iRfs, iPrivatePathCDriveDbBackup ) ) ) |
|
138 { |
|
139 iSqlDb.Close(); |
|
140 User::LeaveIfError( BaflUtils::CopyFile( iRfs, |
|
141 iPrivatePathCDriveDbBackup, iPrivatePathCDriveDb ) ); |
105 User::LeaveIfError( iSqlDb.Open( iPrivatePathCDriveDb, |
142 User::LeaveIfError( iSqlDb.Open( iPrivatePathCDriveDb, |
106 &KSqlDbConfig ) ); |
143 &KSqlDbConfig ) ); |
107 } |
144 } |
108 } |
145 } |
109 |
146 |
212 // --------------------------------------------------------------------------- |
249 // --------------------------------------------------------------------------- |
213 // |
250 // |
214 void CCaSqLiteStorage::LocalizeEntryL( CCaLocalizationEntry& aLocalization ) |
251 void CCaSqLiteStorage::LocalizeEntryL( CCaLocalizationEntry& aLocalization ) |
215 { |
252 { |
216 CCaSqlQuery* sqlLocalizeEntryQuery = CCaSqlQuery::NewLC( iSqlDb ); |
253 CCaSqlQuery* sqlLocalizeEntryQuery = CCaSqlQuery::NewLC( iSqlDb ); |
217 if( aLocalization.GetAttributeName().Compare( KColumnEnText ) == 0 ) |
254 if ( aLocalization.GetAttributeName().Compare( KColumnEnText ) == 0 ) |
218 { |
255 { |
219 CaSqlQueryCreator::CreateLocalizationTableQueryL( sqlLocalizeEntryQuery, |
256 CaSqlQueryCreator::CreateLocalizationTableQueryL( sqlLocalizeEntryQuery, |
220 KSQLLocalizeTextEntry ); |
257 KSQLLocalizeTextEntry ); |
221 } |
258 } |
222 else if ( aLocalization.GetAttributeName().Compare( |
259 else if ( aLocalization.GetAttributeName().Compare( |
223 KColumnEnDescription ) == 0 ) |
260 KColumnEnDescription ) == 0 ) |
224 { |
261 { |
225 CaSqlQueryCreator::CreateLocalizationTableQueryL( sqlLocalizeEntryQuery, |
262 CaSqlQueryCreator::CreateLocalizationTableQueryL( sqlLocalizeEntryQuery, |
226 KSQLLocalizeDescriptionEntry ); |
263 KSQLLocalizeDescriptionEntry ); |
|
264 } |
|
265 else if ( aLocalization.GetAttributeName().Compare( KShortName ) == 0 ) |
|
266 { |
|
267 CaSqlQueryCreator::CreateLocalizationTableQueryL( sqlLocalizeEntryQuery, |
|
268 KSQLLocalizeShortNameAttribute ); |
|
269 } |
|
270 else if ( aLocalization.GetAttributeName().Compare( KTitleName ) == 0 ) |
|
271 { |
|
272 CaSqlQueryCreator::CreateLocalizationTableQueryL( sqlLocalizeEntryQuery, |
|
273 KSQLLocalizeTitleNameAttribute ); |
227 } |
274 } |
228 sqlLocalizeEntryQuery->PrepareL(); |
275 sqlLocalizeEntryQuery->PrepareL(); |
229 sqlLocalizeEntryQuery->BindValuesForLocalizeL( aLocalization ); |
276 sqlLocalizeEntryQuery->BindValuesForLocalizeL( aLocalization ); |
230 sqlLocalizeEntryQuery->ExecuteL( ); |
277 sqlLocalizeEntryQuery->ExecuteL( ); |
231 CleanupStack::PopAndDestroy( sqlLocalizeEntryQuery ); |
278 CleanupStack::PopAndDestroy( sqlLocalizeEntryQuery ); |
408 // --------------------------------------------------------------------------- |
455 // --------------------------------------------------------------------------- |
409 // CCASqLiteStorage::TouchL( const TInt aEntryId ) |
456 // CCASqLiteStorage::TouchL( const TInt aEntryId ) |
410 // |
457 // |
411 // --------------------------------------------------------------------------- |
458 // --------------------------------------------------------------------------- |
412 // |
459 // |
413 void CCaSqLiteStorage::TouchL( const TInt aEntryId ) |
460 void CCaSqLiteStorage::TouchL( const TInt aEntryId, TBool aRemovable ) |
414 { |
461 { |
415 ExecuteStatementL( KSqlStatementBegin ); |
462 ExecuteStatementL( KSqlStatementBegin ); |
416 TRAPD( err, ExecuteTouchL( aEntryId ) ); |
463 TRAPD( err, ExecuteTouchL( aEntryId, aRemovable ) ); |
417 if( err ) |
464 if( err ) |
418 { |
465 { |
419 ExecuteStatementL( KSqlStatementRollback ); |
466 ExecuteStatementL( KSqlStatementRollback ); |
420 User::Leave( err ); |
467 User::Leave( err ); |
421 } |
468 } |
481 // --------------------------------------------------------------------------- |
528 // --------------------------------------------------------------------------- |
482 // |
529 // |
483 void CCaSqLiteStorage::CustomSortL( const RArray<TInt>& aEntryIds, |
530 void CCaSqLiteStorage::CustomSortL( const RArray<TInt>& aEntryIds, |
484 const TInt aGroupId ) |
531 const TInt aGroupId ) |
485 { |
532 { |
|
533 RArray<TInt> entryIds; |
|
534 CleanupClosePushL( entryIds ); |
|
535 for( TInt j=0; j<aEntryIds.Count(); j++ ) |
|
536 { |
|
537 entryIds.AppendL(aEntryIds[j]); |
|
538 } |
|
539 |
|
540 RArray<TInt> oldIds; |
|
541 CleanupClosePushL( oldIds ); |
|
542 CCaInnerQuery* innerQuery = CCaInnerQuery::NewLC(); |
|
543 innerQuery->SetParentId( aGroupId ); |
|
544 |
|
545 GetEntriesIdsL( innerQuery, oldIds ); |
|
546 |
|
547 if( oldIds.Count() != entryIds.Count() ) |
|
548 { |
|
549 for( TInt i=0; i<oldIds.Count(); i++ ) |
|
550 { |
|
551 TInt oldId = oldIds[i]; |
|
552 if( entryIds.Find( oldId ) == KErrNotFound ) |
|
553 { |
|
554 // instert apps with visible set on false on old positions |
|
555 entryIds.InsertL( oldId, i ); |
|
556 } |
|
557 } |
|
558 } |
|
559 |
|
560 const RArray<TInt> constEntryIds( entryIds ); |
|
561 |
486 RPointerArray<CCaSqlQuery> sqlQueries; |
562 RPointerArray<CCaSqlQuery> sqlQueries; |
487 CleanupResetAndDestroyPushL( sqlQueries ); |
563 CleanupResetAndDestroyPushL( sqlQueries ); |
488 |
564 |
489 CaSqlQueryCreator::CreateCustomSortQueryL( |
565 CaSqlQueryCreator::CreateCustomSortQueryL( |
490 aEntryIds, sqlQueries, iSqlDb ); |
566 constEntryIds, sqlQueries, iSqlDb ); |
491 |
567 |
492 ExecuteStatementL( KSqlStatementBegin ); |
568 ExecuteStatementL( KSqlStatementBegin ); |
493 TRAPD( err, ExecuteCustomSortL( aEntryIds, aGroupId, sqlQueries ) ); |
569 TRAPD( err, ExecuteCustomSortL( constEntryIds, aGroupId, sqlQueries ) ); |
494 if( err ) |
570 if( err ) |
495 { |
571 { |
496 ExecuteStatementL( KSqlStatementRollback ); |
572 ExecuteStatementL( KSqlStatementRollback ); |
497 User::Leave( err ); |
573 User::Leave( err ); |
498 } |
574 } |
499 ExecuteStatementL( KSqlStatementCommit ); |
575 ExecuteStatementL( KSqlStatementCommit ); |
500 |
576 |
501 CleanupStack::PopAndDestroy( &sqlQueries ); |
577 CleanupStack::PopAndDestroy( &sqlQueries ); |
|
578 CleanupStack::PopAndDestroy( innerQuery ); |
|
579 CleanupStack::PopAndDestroy( &oldIds ); |
|
580 CleanupStack::PopAndDestroy( &entryIds ); |
502 } |
581 } |
503 |
582 |
504 // --------------------------------------------------------------------------- |
583 // --------------------------------------------------------------------------- |
505 // CCaSqLiteStorage::ExecuteCustomSortL |
584 // CCaSqLiteStorage::ExecuteCustomSortL |
506 // ( const RArray<TInt>& aEntryIds, const TInt aGroupId ) |
585 // ( const RArray<TInt>& aEntryIds, const TInt aGroupId ) |
746 // --------------------------------------------------------------------------- |
825 // --------------------------------------------------------------------------- |
747 // CCASqLiteStorage::ExecuteTouchL( const TInt aEntryId ) |
826 // CCASqLiteStorage::ExecuteTouchL( const TInt aEntryId ) |
748 // |
827 // |
749 // --------------------------------------------------------------------------- |
828 // --------------------------------------------------------------------------- |
750 // |
829 // |
751 void CCaSqLiteStorage::ExecuteTouchL( const TInt aEntryId ) |
830 void CCaSqLiteStorage::ExecuteTouchL( const TInt aEntryId, TBool aRemovable ) |
752 { |
831 { |
753 RPointerArray<CCaSqlQuery> sqlQuery; |
832 RPointerArray<CCaSqlQuery> sqlQuery; |
754 CleanupResetAndDestroyPushL( sqlQuery ); |
833 CleanupResetAndDestroyPushL( sqlQuery ); |
755 |
834 |
756 CaSqlQueryCreator::CreateTouchQueryL( sqlQuery, iSqlDb ); |
835 CaSqlQueryCreator::CreateTouchQueryL( sqlQuery, iSqlDb, aRemovable ); |
757 |
836 |
758 TTime time; |
837 TTime time; |
759 time.UniversalTime(); |
838 time.UniversalTime(); |
760 |
839 |
761 for( TInt i = 0; i < sqlQuery.Count(); i++ ) |
840 for( TInt i = 0; i < sqlQuery.Count(); i++ ) |