Update contrib.
1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // The file-store database which provides the default format
21 EXPORT_C CDbFileStoreDatabase::CDbFileStoreDatabase(RFs& aFs)
25 EXPORT_C CDbFileStoreDatabase::~CDbFileStoreDatabase()
29 delete iStore; // must be destroyed before the file is deleted
32 // If a debug build - record error
33 (void)iFs.Delete(*iName);
38 CDbFileStoreDatabase* CDbFileStoreDatabase::NewLC(RFs& aFs)
40 CDbFileStoreDatabase* self=new(ELeave) CDbFileStoreDatabase(aFs);
41 CleanupStack::PushL(self);
46 // over-ride the store database and just mark the file for deletion
48 EXPORT_C void CDbFileStoreDatabase::DestroyL()
54 // Provide the "size" and "usage" properties
56 EXPORT_C TInt CDbFileStoreDatabase::Property(CDbDatabase::TProperty aProperty)
60 case CDbDatabase::EUpdateStats:
62 case CDbDatabase::ESize:
63 case CDbDatabase::EUsage:
66 TInt r=STATIC_CAST(CFileStore&,Store()).File().Size(size);
69 if (aProperty==CDbDatabase::ESize)
74 return 100-(r*100)/size; // usage in %
77 return CDbStoreDatabase::Property(aProperty);
82 //SYMBIAN_REMOVE_TRIVIAL_ENCRYPTION version of the method.
83 EXPORT_C void CDbFileStoreDatabase::CreateL(const TDesC& aName, TDbFormat::TCreate aMode,
84 const TUidType& aType)
86 __ASSERT(!iName); // check construction phase
93 __LEAVE(KErrNotSupported);
94 case TDbFormat::ECreate:
95 store=CPermanentFileStore::CreateL(iFs,aName,EFileRead|EFileWrite);
97 case TDbFormat::EReplace:
98 store=CPermanentFileStore::ReplaceL(iFs,aName,EFileRead|EFileWrite);
102 iDelete=ETrue; // cleanup fully in case of failure
103 store->SetTypeL(aType);
104 store->SetRootL(CreateRootL(CDbStoreDatabase::ConstructL()));
106 iDelete=EFalse; // file is now good
109 // SYMBIAN_REMOVE_TRIVIAL_ENCRYPTION version of the method.
110 // Create the standard file database. The database is the root stream
112 EXPORT_C CDbDatabase* CDbFileStoreDatabase::CreateL(RFs& aFs, const TDesC& aName,
113 TDbFormat::TCreate aMode, const TUidType& aType)
115 CDbFileStoreDatabase* self=NewLC(aFs);
116 self->CreateL(aName,aMode,aType);
117 CDbDatabase* db=self->InterfaceL();
118 CleanupStack::Pop(self);
124 // default implementation. Database _is_ the root
126 EXPORT_C TStreamId CDbFileStoreDatabase::CreateRootL(TStreamId aDatabaseId)
133 // open the file-store and return the root stream id
135 EXPORT_C void CDbFileStoreDatabase::OpenL(const TDesC& aName,TDbFormat::TOpen aMode)
137 __ASSERT(!iName); // check construction phase
139 iName=aName.AllocL();
140 const TUint mode=aMode==TDbFormat::EReadOnly ? EFileShareReadersOnly : EFileWrite;
141 CFileStore* store=CPermanentFileStore::OpenL(iFs,*iName,mode);
143 CDbStoreDatabase::RestoreL(DatabaseIdL(store->Root()));
147 // default implementation. Database _is_ the root
149 EXPORT_C TStreamId CDbFileStoreDatabase::DatabaseIdL(TStreamId aRootId)
155 // Create the standard file database. The database is the root stream
157 EXPORT_C CDbSource* CDbFileStoreDatabase::OpenL(RFs& aFs,const TDesC& aName,TDbFormat::TOpen aMode)
159 CDbFileStoreDatabase* self=NewLC(aFs);
160 self->OpenL(aName,aMode);
161 CDbSource* src=self->SourceL();
162 CleanupStack::Pop(); // self
166 const TDbFormat KBuiltinFormat=
168 _S("epoc"),&CDbFileStoreDatabase::CreateL,&CDbFileStoreDatabase::OpenL,
169 {KPermanentFileStoreLayoutUidValue,KDbmsFileDatabaseUidValue}
172 GLDEF_D const TDbDriver KBuiltinDriver={1,&KBuiltinFormat};