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.

Context

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.

Prerequisites

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

Steps

  1. Make sure that you have created a session.

  2. 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.

    Example:

    ...
    
    // 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);
    ...
                 
  3. 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.

    Example:

    ...
    ptrConnPrefRecordSet->LoadL(*iDb);
    // If the flow of the code reaches here, the table has been loaded.        
    ...
  4. 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.

    Example: 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.

    Example: 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.

    Example:

    ...
    // 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); 
    ...

Related concepts