1 // Copyright (c) 2006-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 // Comms Database public interface
20 @deprecated since v9.1. Functionality is replaced with commsdat.
27 #include <metadatabase.h>
29 using namespace CommsDat;
36 Protection of settings: when the entire table is protected, write operations
37 fail with KErrWrite. However KErrAccessDenied should be returned to client
40 #define TRAPD_CONVERT(_r,_s) TRAPD(_r,_s); if(ret == KErrWrite) ret = KErrAccessDenied;
44 #define TRAP_CONVERT(_r,_s) TRAP(_r,_s); if(ret == KErrWrite) ret = KErrAccessDenied;
46 class CCommsDbTableView;
47 class CCommsDbConnectionPrefTableView;
48 class CCommDbTableExtension;
49 class CCommsDatabaseImpl;
51 class CCommsDatabaseBase : public CBase
52 /** Base class for CCommsDatabase.
54 This class is never instantiated, but its member functions are used through
57 Responsible for Transactions, Notifications, Write protection, Hidden
58 records, Phone number resolution and Creating views. Stores the database, the
59 session, transaction and notifier information.
61 CCommsDatabaseBase is an abstract base class as the CreateDatabaseL() and
62 Open() methods are pure virtual.
67 // These classes added as friends for commdb shim
68 friend class CCommsDbTableView;
69 friend class CCommsDbConnectionPrefTableView;
70 friend class CCommsDbProtectTableView;
71 friend class CCommsDbProtectConnectPrefTableView;
72 friend class CCommsDbTemplateRecord;
74 IMPORT_C virtual ~CCommsDatabaseBase();
76 // Returns the version of the database server.
77 IMPORT_C TVersion Version() const;
78 // Begin a transaction. Call before `InsertRecord()` or `UpdateRecord()`.
79 IMPORT_C TInt BeginTransaction();
80 // End a transaction. Call after `InsertRecord()` or `UpdateRecord()`.
81 IMPORT_C TInt CommitTransaction();
82 // Cancel a transaction.
83 IMPORT_C void RollbackTransaction();
84 // True if BeginTransaction() has been called but not
85 // `CommitTransaction()` or `RollbackTransaction()`.
86 IMPORT_C TBool InTransaction();
87 // True if the database has been locked.
88 IMPORT_C TBool IsDatabaseWriteLockedL();
90 // Enable a notification event on any change to the database.
91 IMPORT_C TInt RequestNotification(TRequestStatus& aStatus);
92 // Cancels notifications.
93 IMPORT_C void CancelRequestNotification();
95 // Obtain a view of all records in a table.
96 IMPORT_C CCommsDbTableView* OpenTableLC(const TDesC& aTableName);
97 // Obtain a view of the records in a table that match the query.
98 IMPORT_C CCommsDbTableView* OpenViewLC(const TDesC& aTableName, const TDesC& aSqlQuery);
99 // Obtain a view of all the records in a table for which the field
100 // `aColumnToMatch` matches `aValueToMatch`.
101 IMPORT_C CCommsDbTableView* OpenViewMatchingUintLC(const TDesC& aTableName, const TDesC& aColumnToMatch, TUint32 aValueToMatch);
102 IMPORT_C CCommsDbTableView* OpenViewMatchingBoolLC(const TDesC& aTableName, const TDesC& aColumnToMatch, TBool aValueToMatch);
103 IMPORT_C CCommsDbTableView* OpenViewMatchingTextLC(const TDesC& aTableName, const TDesC& aColumnToMatch, const TDesC8& aValueToMatch);
104 IMPORT_C CCommsDbTableView* OpenViewMatchingTextLC(const TDesC& aTableName, const TDesC& aColumnToMatch, const TDesC16& aValueToMatch);
106 // Make hidden records visible
107 IMPORT_C void ShowHiddenRecords();
109 // Set `aDialString` to be the appropriate string based on the directory
110 // number, where the dial is being performed and the chargecard to use.
111 // `ResolvePhoneNumberL()` opens a comms database to perform the
113 IMPORT_C static void ResolvePhoneNumberL(TDesC& aNumber, TDes& aDialString, TParseMode aDialParseMode, TUint32 aLocationId, TUint32 aChargecardId);
114 // Set `aDialString` to be the appropriate string based on the directory
115 // number, where the dial is being performed and the chargecard to use.
116 IMPORT_C void ResolvePhoneNumberFromDatabaseL(TDesC& aNumber, TDes& aDialString, TParseMode aDialParseMode, TUint32 aLocationId, TUint32 aChargecardId);
117 IMPORT_C static TInt InitializeFilestore();
119 // Check access to database fields
120 IMPORT_C TInt CheckReadCapability( const TDesC& aField, const RMessagePtr2* aMessage );
121 IMPORT_C TInt CheckWriteCapability( const TDesC& aField, const RMessagePtr2* aMessage );
125 // Please note that as of v9.0 TCommDbSystemAgentNotification now actually contains
126 // the notification information for the Publish and Subscribe notifications, not
127 // for System Agent notifications.
128 class TCommDbSystemAgentNotification
135 TCommDbSystemAgentNotification();
136 void Set(TUid aUid, TInt aVal);
142 class TCommDbPublishSubscribeNotification
149 TCommDbPublishSubscribeNotification();
150 void Set(TUid aUid, TInt aVal);
158 IMPORT_C CCommsDatabaseBase();
160 virtual void CreateDatabaseL() =0;
163 CCommsDbTableView* DoOpenViewMatchingUintL(const TDesC& aTableName, const TDesC& aColumnToMatch, TUint32 aValueToMatch, TBool aIncludeHiddenRecords);
164 CCommsDbTableView* DoOpenViewMatchingTextL(const TDesC& aTableName, const TDesC& aColumnToMatch, const TDesC8& aValueToMatch, TBool aIncludeHiddenRecords);
165 CCommsDbTableView* DoOpenViewMatchingTextL(const TDesC& aTableName, const TDesC& aColumnToMatch, const TDesC16& aValueToMatch, TBool aIncludeHiddenRecords);
166 CCommsDbTableView* DoOpenTableViewL(const TDesC& aTableName, const TDesC& aSqlQuery);
167 CCommsDbTableView* DoOpenIAPTableViewL(const TDesC& aTableName,const TDesC& aSqlQuery);
169 void PopulateDialLocationL(TUint32 aId, TDialLocation& aLocation);
170 void PopulateChargeCardL(TUint32 aId, TChargeCard& aChargeCard);
171 void BeginInternalTransactionL();
172 TInt CommitInternalTransaction();
173 void RollbackInternalTransaction();
174 void DatabaseUpdateHasOccurred();
175 void NotifyChangeL(const TDesC& aSetting, TUint32 aVal);
176 TInt NotifyAllChanges();
178 TUint32 GetNewNumber(TUid aUid);
179 TInt CheckDBCapability( RDbs::TPolicyType aType, const TDesC& aField, const RMessagePtr2* aMessage );
180 void ConvertToUid(const TDesC& aSetting, TUint32 aVal, TCommDbPublishSubscribeNotification& aNotification);
182 inline RDbNamedDatabase* Database();
185 CCommsDatabaseImpl* iImpl;
186 RDbNamedDatabase iDatabase;
187 RDbNotifier iNotifier;
188 // store container data for deletion after session is finished
189 //RPointerArray<CMDBElement> iTransactionCache;
191 TInt iNotifierOpenError;
192 TBool iShowHiddenRecords;
193 TBool iImplNotCreated;
194 TBool iInInternalTransaction;
196 RArray<TCommDbPublishSubscribeNotification> iNotifications;
198 // Check access to database fields
199 TInt DoCheckReadCapabilityL( const TDesC& aField, const RMessagePtr2* aMessage );
200 TInt DoCheckWriteCapabilityL( const TDesC& aField, const RMessagePtr2* aMessage );
202 TBool ConvertTableName(const TDesC& aTableName, TDes& aResult);
205 class CCommsDatabase : public CCommsDatabaseBase
207 Accesses the communications database through the DBMS.
209 An object of this type must be constructed and opened by a client before any
210 of the tables in the database can be accessed, e.g. to create views and access
213 Implements the pure virtual functions CreateDatabaseL() and DoOpen().
214 Responsible for Global settings and Connection Preferences. Has utility
215 functions for accessing Global and Agent tables. No additional state (to
216 CCommsDatabaseBase) is stored.
221 IMPORT_C static CCommsDatabase* NewL();
222 IMPORT_C static CCommsDatabase* NewL(TBool aUseDefaultDb);
223 IMPORT_C static CCommsDatabase* NewL(TCommDbOpeningMethod &aOpeningMethod);
224 IMPORT_C virtual ~CCommsDatabase();
225 IMPORT_C void GetGlobalSettingL(const TDesC& aSetting, TUint32& aValue);
226 IMPORT_C void GetGlobalSettingL(const TDesC& aSetting, TDes& aValue);
227 IMPORT_C void SetGlobalSettingL(const TDesC& aSetting, TUint32 aValue);
228 IMPORT_C void SetGlobalSettingL(const TDesC& aSetting, const TDesC& aValue);
229 IMPORT_C void ClearGlobalSettingL(const TDesC& aSetting);
230 IMPORT_C void GetDefaultTsyL(TDes& aValue);
232 // Deprecated. Past use: Gets settings (Modem, Chargecard, and Service) for the dial out IAP.
233 IMPORT_C void GetCurrentDialOutSettingL(const TDesC& aSetting, TUint32& aValue);
234 // Deprecated. Past use: Retrieve settings for the dial in IAP.
235 IMPORT_C void GetCurrentDialInSettingL(const TDesC& aSetting, TUint32& aValue);
236 // Open a connection preference view.
237 IMPORT_C CCommsDbConnectionPrefTableView* OpenConnectionPrefTableLC();
238 // Open a connection preference view containing connections of the
239 // specified direction.
240 IMPORT_C CCommsDbConnectionPrefTableView* OpenConnectionPrefTableLC(TCommDbConnectionDirection aDirection);
241 // Open a connection preference view containing connections of the
242 // specified direction excluding connections of rank zero.
243 IMPORT_C CCommsDbConnectionPrefTableView* OpenConnectionPrefTableInRankOrderLC(TCommDbConnectionDirection aDirection);
244 // Open a connection preference view containing connections of the
245 // specified direction and rank.
246 IMPORT_C CCommsDbConnectionPrefTableView* OpenConnectionPrefTableViewOnRankLC(TCommDbConnectionDirection aDirection, TUint32 aRank);
248 //DEPRECATED : Agent table has been removed. These functions have been
249 // stubbed to return KErrNotSupported or leave with the same error.
250 // Access agent settings. `aService` is one of: (`DIAL_OUT_ISP`,
251 // `DIAL_IN_ISP`, `OUTGOING_WCDMA'). */
252 IMPORT_C void SetAgentL(const TDesC& aService, const TDesC& aAgent);
254 IMPORT_C void SetAgentExtL(const TDesC& aService, const TDesC& aAgentExt);
255 IMPORT_C void GetAgentL(const TDesC& aService, TDes& aAgent);
256 IMPORT_C void GetAgentExtL(const TDesC& aService, TDes& aAgentExt);
257 IMPORT_C void ClearAgentAndExtL(const TDesC& aService);
258 IMPORT_C void SetAgentClientTimeoutL(const TDesC& aService, TInt aClientTimeout);
259 IMPORT_C void SetAgentRouteTimeoutL(const TDesC& aService, TInt aRouteTimeout);
260 IMPORT_C TInt GetAgentClientTimeoutL(const TDesC& aService);
261 IMPORT_C TInt GetAgentRouteTimeoutL(const TDesC& aService);
263 /** Open a view on the IAP table containing records that match the
264 bearers and direction specified. `aBearerSet` is a bit mask of type
266 IMPORT_C CCommsDbTableView* OpenIAPTableViewMatchingBearerSetLC(TUint32 aBearerSet, TCommDbConnectionDirection aDirection);
268 /** Open a viewon the IAP table containing records which match the specified network */
269 IMPORT_C CCommsDbTableView* OpenIAPTableViewMatchingNetworkLC(TUint32 aNetwork);
271 // Open a view on the proxy table containing records that match the
272 // service id and type specified.
273 IMPORT_C CCommsDbTableView* OpenViewOnProxyRecordLC(TUint32 aServiceId, const TDesC& aServiceType);
275 // Functionality re-implemented to facilitate BC with 6.1
276 IMPORT_C static CCommsDatabase* NewL(TCommDbDatabaseType aDbType);
277 // Creates a `CCommsDatabase` as with `NewL()`. The method of opening:
278 // (Created, CopiedDefault or Opened) is returned in `aOpeningMethod`.
279 IMPORT_C static CCommsDatabase* NewL(TCommDbDatabaseType aDbType, TCommDbOpeningMethod &aOpeningMethod);
282 enum TGlobalSettingType
286 ECompatibilitySetting
290 void DoOpenL(TCommDbOpeningMethod& aOpeningMethod,TBool aUseDefaultDb);
292 /** CCommsDatabaseBase pure virtuals */
294 virtual void CreateDatabaseL();
295 CCommsDbTableView* OpenGlobalSettingsTableLC(const TDesC& aSetting, TBool& aExists);
296 TGlobalSettingType GlobalSettingTypeL(const TDesC& aSetting) const;
300 class CCommsDbTemplateRecord;
302 class CCommsDbTableView : public CBase
305 The view on a specific table in the database.
307 Includes the necessary behaviour for navigating through the records in
308 the view and reading and writing to columns within a record.
310 Uses a CCommsDatabase and has an RDbView to read from and write to database. Created via
311 CCommsDatabase::OpenTableLC() (which opens a view of all the records in the table) or one
312 of the OpenViewLC...() functions (which open a specific view of the table):
314 CCommsDatabase::OpenTableLC()
316 CCommsDatabase::OpenViewMatchingUintLC()
318 CCommsDatabase::OpenViewMatchingBoolLC()
320 CCommsDatabase::OpenViewMatchingTextLC()
322 CCommsDatabase::OpenViewLC()
324 Note that the above five functions have been withdrawn in CCommsDatabase and
325 are now implemented in CCommsDatabaseBase.
330 friend class CCommsDatabaseBase;
331 friend class CCommsDbTemplateRecord;
333 // Low level view creation. Use if `CCommsDatabase::OpenTableLC()` or
334 //`CCommsDatabase::OpenViewLC...()` are not sufficient.
335 static CCommsDbTableView* NewL(CCommsDatabaseBase& aDb, const TDesC& aTableName, const TDbQuery& aQuery, TBool aUseTemplate = ETrue);
336 static CCommsDbTableView* NewLC(const TDesC& aTableName, CCommsDatabaseBase& aDb);
337 // additional constructors, commdb shim specific
338 static CCommsDbTableView* NewLC(CCommsDatabaseBase& aDb, const TDesC& aTableName, TBool aUseTamplate = ETrue); // ETrue if template is instantiating
339 static CCommsDbTableView* NewL(CCommsDatabaseBase& aDb, const TDesC& aTableName, const TDesC& aColumnToMatch, const TDesC8& aValueToMatch);
340 static CCommsDbTableView* NewL(CCommsDatabaseBase& aDb, const TDesC& aTableName, const TDesC& aColumnToMatch, const TDesC16& aValueToMatch);
341 static CCommsDbTableView* NewL(CCommsDatabaseBase& aDb, const TDesC& aTableName, const TDesC& aColumnToMatch, TUint32 aValueToMatch);
342 static CCommsDbTableView* NewLC(CCommsDatabaseBase& aDb, const TDesC& aTableName, const TDesC& aColumnToMatch, TBool aValueToMatch);
343 // this two are for IAP table only so table name is not needed
344 static CCommsDbTableView* NewLC(CCommsDatabaseBase& aDb, TUint32 aBearerSet, TCommDbConnectionDirection aDirection);
345 static CCommsDbTableView* NewLC(CCommsDatabaseBase& aDb, TUint32 aNetworkId);
346 // this one is for Proxie table only
347 static CCommsDbTableView* NewLC(CCommsDatabaseBase& aDb, TUint32 aServiceId, const TDesC& aServiceType);
349 CCommsDbTableView(CCommsDatabaseBase& aDb, const TDesC& aTableName);
351 IMPORT_C virtual ~CCommsDbTableView();
353 // Add a new record to this table. The record number is returned.
354 // `PutRecordChanges()` is called to complete the transaction
355 IMPORT_C TInt InsertRecord(TUint32& aId);
356 /** Add a new record to this table. Filling all empty fields with values copied
357 from record currently pointed at. The record number is returned.
358 `PutRecordChanges()` is called to complete the transaction */
359 IMPORT_C TInt InsertCopyRecord(TUint32& aId);
360 /** Modify the current record of this view. `PutRecordChanges()` is called
361 to complete the transaction */
362 IMPORT_C TInt UpdateRecord();
363 // Remove the current record from the table.
364 IMPORT_C TInt DeleteRecord();
365 // Store an inserted or updated record back to the database.
366 IMPORT_C TInt PutRecordChanges(TBool aHidden = EFalse, TBool aReadOnly = EFalse);
367 // Cancel pending changes since an insert or update.
368 IMPORT_C void CancelRecordChanges();
370 // Navigate throught the records in the view
372 IMPORT_C TInt GotoFirstRecord();
373 IMPORT_C TInt GotoNextRecord();
374 IMPORT_C TInt GotoPreviousRecord();
376 // Access data from the current record
378 IMPORT_C void ReadTextL(const TDesC& aColumn, TDes8& aValue);
379 IMPORT_C void ReadTextL(const TDesC& aColumn, TDes16& aValue);
380 IMPORT_C HBufC* ReadLongTextLC(const TDesC& aColumn);
381 IMPORT_C void ReadUintL(const TDesC& aColumn, TUint32& aValue);
382 IMPORT_C void ReadBoolL(const TDesC& aColumn, TBool& aValue);
383 // Determine the type and attributes of a column. The type is one of:
384 // (EDbColBit, EDbColUint32, EDbColText8, EDbColText16, EDbColLongText16).
385 // The attribute is a bit mask of: (ENotNull and EAutoIncrement).
386 IMPORT_C void ReadTypeAttribL(const TDesC& aColumn, TDbColType& aColType, TUint32& aAttrib);
387 // Null columns return 0, integers and bools 1, strings return their length in characters.
388 IMPORT_C void ReadColumnLengthL(const TDesC& aColumn, TInt& aLength);
391 // Modify an inserted or modified record. Must call `PutRecordChanges()`
392 // to store the changes.
394 IMPORT_C void WriteTextL(const TDesC& aColumn, const TDesC8& aValue);
395 IMPORT_C void WriteTextL(const TDesC& aColumn, const TDesC16& aValue);
396 IMPORT_C void WriteLongTextL(const TDesC& aColumn, const TDesC& aValue);
397 IMPORT_C void WriteUintL(const TDesC& aColumn, const TUint32& aValue);
398 IMPORT_C void WriteBoolL(const TDesC& aColumn, const TBool& aValue);
399 IMPORT_C void SetNullL(const TDesC& aColumn);
401 IMPORT_C void ReadColumnMaxLengthL(const TDesC& aColumn, TInt& aLength);
402 inline CCommsDatabaseBase* Database() const { return &iDb; }
404 void OpenL(const TDbQuery& aQuery);
406 inline void GetTableName(TDes& aTableName) const;
408 TDbColNo ColNumL(const TDesC& aColumn) const;
410 void ConstructL(const TDesC& aTableName, TBool aShowHidden, TBool aUseTemplate);
411 void ConstructL(const TDbQuery& aQuery, TBool aUseTemplate);
412 RDbRowSet::TAccess GetL();
414 // All other ConstructructL methods are added for commdb shimm
415 void ConstructL(const TDesC& aTableName, const TDesC& aColumnToMatch, const TDesC8& aValueToMatch);
416 void ConstructL(const TDesC& aTableName, const TDesC& aColumnToMatch, const TDesC16& aValueToMatch);
417 void ConstructL(const TDesC& aTableName, const TDesC& aColumnToMatch, TUint32 aValueToMatch);
418 void ConstructL(const TDesC& aTableName, const TDesC& aColumnToMatch, TBool aValueToMatch);
419 void ConstructL(TUint32 aBearerSet, TCommDbConnectionDirection aDirection);
420 void ConstructL(TUint32 aNetworkId);
421 void ConstructL(TUint32 aServiceId, const TDesC& aServiceType);
422 // used for template creation only
423 void ConstructL(const TDesC& aTableName);
433 TBool TableWithTemplateRecord() const;
434 TInt InsertTemplateRecord();
435 TInt DoInsertRecord(TBool aType, TUint32& aId, TBool aIsTemplate);
436 TInt DoPutRecordChanges(TBool aHidden = EFalse, TBool aReadOnly = EFalse, TBool aIsTemplateCall = EFalse);
440 CCommsDbTemplateRecord* iTemplate;
441 TBool iTsyNameChanged;
442 TUint32 iInsertedRecordIndex;
446 CCommsDatabaseBase& iDb;
447 TBuf<KCommsDbSvrMaxColumnNameLength> iTableName;
449 CCommDbTableExtension* iTableExt;
457 Convert a legacy field name to a CommsDat element Id
460 @param aFieldName A legacy commdb field name in the format "tableName\fieldName"
461 @return A Commsdat element Id
466 IMPORT_C static TMDBElementId GetElementIdFromFieldNameL(const TDesC& aFieldName);
469 // SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY
472 #include <commdb.inl>