Loading
a Symbian Platform Defined Table: Tutorial
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.
Before you start,
you must understand:
the general concept
of the Comms Database
the specific concept
of fields, records, links and tables
how to write and build
application code to run on Symbian platform
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.
- Make sure that you
have created a session.
- Create the table
object in the tool or application process.
You create a CMDBRecordSet <T> object
and specify 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 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 the LoadL() 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 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 RPointerArray <T> to
contain the records. RPointerArray allows applications to
customise the behaviour of the sort operation.
The code uses the 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);
...
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.