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.
22 inline void CDbContext::Open()
28 // Attach an object to this context
30 void CDbContext::Attach(CDbObject* aObject)
32 if (aObject && aObject->iContext!=this)
34 __ASSERT(!aObject->iContext);
35 aObject->iContext=this;
41 // self destruct when we are no longer referenced
43 void CDbContext::Close()
51 // default implementation is to delete ourself
53 void CDbContext::Idle()
61 // Attach aObject to the same context as it's factory
63 CDbObject* CDbObject::Attach(CDbObject* aObject)
65 CDbContext* context=iContext;
67 context->Attach(aObject);
72 // Library safe destruction of a implementation object
73 // This ensures that all objects from a Driver are deleted BEFORE the library is unloaded
75 void CDbObject::Destroy(CDbObject* aObject)
79 CDbContext* context=aObject->iContext;
87 // Library safe cleanup-stack function
89 void CDbObject::PushL()
91 CleanupStack::PushL(TCleanupItem(TCleanupOperation(Destroy),this));
97 //SYMBIAN_REMOVE_TRIVIAL_ENCRYPTION version of the method.
98 // Encapsulate the 2-phase construction for client access
100 CDbDatabase* CDbSource::OpenL()
102 return AuthenticateL();
105 // Class RDbNamedDatabase
107 //SYMBIAN_REMOVE_TRIVIAL_ENCRYPTION version of the method.
108 LOCAL_C CDbDatabase* OpenDatabaseL(TDbFormat::TOpen aMode, RFs& aFs, const TDesC& aSource,
109 const TDesC& /*aFormat*/)
111 CDbSource* source=KBuiltinDriver.iFormats[0].OpenL(aFs,aSource,aMode);
112 CleanupStack::PushL(source);
113 CDbDatabase* db=source->OpenL();
114 CleanupStack::PopAndDestroy(); // source (not needed)
118 //SYMBIAN_REMOVE_TRIVIAL_ENCRYPTION version of the method.
119 //The method may be used in the other cpp files too
120 CDbDatabase* CreateDatabaseL(TDbFormat::TCreate aMode, RFs& aFs, const TDesC& aSource,
121 const TDesC& aFormat)
123 const TDbFormat& fmt=KBuiltinDriver.iFormats[0];
125 TUid policyId = KNullUid;
128 ::ExtractUidAndName(aFormat, policyId, uidName);
130 CDbDatabase* db=fmt.CreateL(aFs,aSource,aMode,
131 TUidType(TUid::Uid(fmt.iUid[0]),TUid::Uid(fmt.iUid[1]),policyId));
138 Creates a new non-secure database.
140 In this "single client" mode, the database cannot be shared with the other clients.
141 The database server is not involved in the operations with the database, the client side
142 database library (edbms.dll) will be used.
143 If the database has to be shared, the following example shows how this may be accomplished:
146 TInt err = fs.Connect();
148 _LIT(KDatabaseName, _L("C:\\A.DB"));
150 err = db.Create(fs, KDatabaseName); //Step 1 - create the database using the RFs object
152 db.Close(); //Step 2 - close the database
156 err = db.Open(dbs, KDatabaseName); //Step 3 - reopen the database using the RDbs object
161 Max allowed database name length (with the extension) is KDbMaxName symbols.
163 For creating a new secure shared database, see RDbNamedDatabase::Create(), which first argument
166 @param aFs Handle to a file server session.
167 @param aSource Database file name.
168 @param aFormat Database format string. It can be omitted in which case the default parameter
169 value (TPtrC()) will be used.
170 @return KErrNone if successful otherwise one of the system-wide error codes, including:
171 KErrAlreadyExists - the database already exists;
172 KErrArgument - bad argument, including null/invaluid uids, the database name includes a null;
174 @see RDbNamedDatabase::Create(RDbs& aDbs, const TDesC& aDatabase, const TDesC& aFormat)
179 EXPORT_C TInt RDbNamedDatabase::Create(RFs& aFs, const TDesC& aSource, const TDesC& aFormat)
181 TRAPD(r,iDatabase=CreateDatabaseL(TDbFormat::ECreate,aFs,aSource,aFormat));
185 EXPORT_C TInt RDbNamedDatabase::Create(RDbs &, const TDesC& aDb, const TDesC& aFormat)
188 TInt r = theFs.Connect();
189 if(r != KErrNone)return r;
190 r = Create(theFs, aDb, aFormat);
197 Creates a new non-secure database.
198 If a database with the same file name exists, it will be replased.
200 In this "single client" mode, the database cannot be shared with the other clients.
201 The database server is not involved in the operations with the database, the client side
202 database library (edbms.dll) will be used.
203 If the database has to be shared, the following example shows how this may be accomplished:
206 TInt err = fs.Connect();
208 _LIT(KDatabaseName, _L("C:\\A.DB"));
210 err = db.Replace(fs, KDatabaseName); //Step 1 - create the database using the RFs object
212 db.Close(); //Step 2 - close the database
216 err = db.Open(dbs, KDatabaseName); //Step 3 - reopen the database using the RDbs object
221 Max allowed database name length (with the extension) is KDbMaxName symbols.
223 For creating a new secure shared database, see RDbNamedDatabase::Create(), which first argument
226 @param aFs Handle to a file server session.
227 @param aSource Database name. The name format is: <drive>:<path><name>.<ext>
228 @param aFormat Database format string. It can be omitted in which case the default parameter
229 value (TPtrC()) will be used.
230 @return KErrNone if successful otherwise one of the system-wide error codes, including:
231 KErrArgument - bad argument, including null/invaluid uids, the database name includes a null;
233 @see RDbNamedDatabase::Create(RDbs& aDbs, const TDesC& aDatabase, const TDesC& aFormat)
238 EXPORT_C TInt RDbNamedDatabase::Replace(RFs& aFs, const TDesC& aSource, const TDesC& aFormat)
240 TRAPD(r,iDatabase=CreateDatabaseL(TDbFormat::EReplace,aFs,aSource,aFormat));
245 Opens an existing non-secure database.
247 In this "single client" mode, the database cannot be shared with the other clients.
248 The database server is not involved in the operations with the database, the client side
249 database library (edbms.dll) will be used.
251 For opening a new secure shared database, see RDbNamedDatabase::Open(), which first argument
254 @param aFs Handle to a file server session.
255 @param aSource Database name. The name format is: <drive>:<path><name>.<ext>
256 @param aFormat Database format string. It can be omitted in which case the default parameter
257 value (TPtrC()) will be used.
258 @param aMode The mode in which the database is to be accessed. The mode is
259 defined by the TAccess type.
260 @return KErrNone if successful otherwise one of the system-wide error codes, including:
261 KErrNotFound - the database is not found;
262 KErrPathNotFound - the path of database is not found
263 KErrNotSupported - the format is not supported.
264 KErrArgument - bad argument,including null/invaluid uids,the database name is null;
265 KErrPermissionDenied - the caller has not enough rights to do the operation;
267 @see RDbNamedDatabase::Open(RDbs& aDbs, const TDesC& aDatabase, const TDesC& aFormat)
272 EXPORT_C TInt RDbNamedDatabase::Open(RFs& aFs, const TDesC& aSource, const TDesC& aFormat,
275 TRAPD(r,iDatabase=OpenDatabaseL(TDbFormat::TOpen(aMode),aFs,aSource,aFormat));
279 EXPORT_C TInt RDbNamedDatabase::Open(RDbs &, const TDesC& aSource, const TDesC& aFormat)
282 TInt r = theFs.Connect();
285 r = Open(theFs, aSource, aFormat );
291 CDbNotifier* CDbSource::NotifierL()
293 return AttachContext(this,OpenNotifierL());