This tutorial shows you how to load a Symbian platform defined table from the Comms Database. The topic also gives an example that shows you how to process the records in a table.
This tutorial shows you how to load the Connection Preferences table. The principles that apply here also apply to the other Symbian platform defined tables.
This tutorial shows you the main steps.
This tutorial also shows how you can process the records in the table. The example code shows you how to sort the records in the table.
Before you start, you must understand:
Make sure that you have created a session.
Create the table object in the tool or application process.
You create a [[[ERROR: [NOKX000E] Unable to find definition for key reference 'CommsDat']]]CMDBRecordSet
<T>
object
and specify [[[ERROR: [NOKX000E] Unable to find definition for key reference 'CommsDat']]]CCDConnectionPrefsRecord
as
the template parameter.
Symbian platform defines the CCDConnectionPrefsRecord
class
to represent a Connection Preferences record. The class is a schema for the
record. The class defines the fields and links that make a Connection Preferences
record.
Symbian platform defines unique
numeric Id s for Symbian platform defined tables. The symbol [[[ERROR: [NOKX000E] Unable to find definition for key reference 'CommsDat']]]KCDTIdConnectionPrefsRecord
defines the value
of this Id for the Connection Preferences table. The Id allows the CommsDat
API to retrieve the table from the Comms Database efficiently.
To work with other Symbian platform defined tables, use
the correct class name and the correct unique numeric Id values. The Reference section
contains a list of all Symbian defined tables.
... // This code fragment assumes that a session with the Comms Database has been created. // iDb is a pointer to a CMDBSession object ... // Use the standard "new (ELeave)" construction to create the object to // represent the table. // // Note: // 1. the template parameter CCDConnectionPrefsRecord defines // the "Connection Preferences" record type. // 2. the unique numeric Id KCDTIdConnectionPrefsRecord is passed as a parameter // to the constructor. CMDBRecordSet<CCDConnectionPrefsRecord>* ptrConnPrefRecordSet = new (ELeave) CMDBRecordSet(KCDTIdConnectionPrefsRecord); ...
Load the table from the Comms Database.
Use theLoadL()
function to load the table from the
Comms Database. The function is called on the class that defines the table.
The function is implemented in the base class [[[ERROR: [NOKX000E] Unable to find definition for key reference 'CommsDat']]]MMetaDatabase
.
You pass a reference to the session object into the LoadL()
function.
... ptrConnPrefRecordSet->LoadL(*iDb); // If the flow of the code reaches here, the table has been loaded. ...
Process the records.
This step is optional. It is an example that shows how you can process the records in a table. The example also shows you how to retrieve the number of records in the table. The following code sorts the records into record Id order. The record Id is the part of the unique numeric Id that identifies an instance of a record. A table uses an [[[ERROR: [NOKX000E] Unable to find definition for key reference 'CommsDat']]]RPointerArray
<T>
to
contain the records. RPointerArray
allows applications to
customise the behaviour of the sort operation.
The code uses the [[[ERROR: [NOKX000E] Unable to find definition for key reference 'CommsDat']]]TLinearOrder
<T>
class.
... // Customised sort function TInt SortRecordsById(const CMDBRecordBase& aLeft, const CMDBRecordBase& aRight) { return (aLeft.RecordId()) < (aRight.RecordId()) ? -1 : 1; } ... // Total number of records in the table TInt totalcount = ptrConnPrefRecordSet->iRecords.Count(); ... // Sort the records. // 1. Define a TLinearOrder<T> class for a Connection Preferences record and instantiate // the class. // 2. Invoke the sort operation. TLinearOrder<CMDBRecordBase> orderbyId(SortRecordsById); ptrConnPrefRecordSet->iRecords.Sort(orderbyId); ...