Using Template Records: Tutorial

This tutorial shows you how to create a template record and how to load a template record.

Before you start, you must understand:

  • the general concept of the Comms Database

  • the specific concepts of fields, records, links and tables

  • how to write and build application code to run on Symbian platform

A template record contains default data values. You can use a template record when you create a record to add to the Comms Database.

For example, the records in the DialOutISP table are large. Many of the fields in a DialOutISP record have values that are the same in all DialOutISP records. A template record can contain these common values. When you create a DialOutISP record, set the value of those fields to be copied from the template record to NULL. Set the other fields in your DialOutISP record to values that are specific to that record.

These principles apply to all record types.

The following steps create and load a template record for the Network table.

  1. Make sure that you have created a session.
  2. Set the attribute mask for this session to hidden. Template records are marked as hidden. Set the session mask to hidden to allow you to view the template records.
    cmdbSession->SetAttributeMask(ECDHidden); 
    
  3. Create a template record and store it in the database.
    ...
    // Create a "Network" record, but give it the unique numeric Id KCDDefaultRecord.
    // The CommsDat API interprets the record Id KCDDefaultRecord to mean the 
    // template record.
    CCDNetworkRecord* ptrNetworkRecord = (CCDNetworkRecord*)CCDRecordBase::RecordFactoryL(KCDTIdNetworkRecord);
    ptrNetworkRecord->SetRecordId(KCDDefaultRecord);
    
    // Template records must be hidden.
    ptrNetworkRecord->SetAttributes(ECDHidden);
    
    // Store the template record in the database
    ptrNetworkRecord->StoreL(*cmdbSession);
    ...
  4. Load the template record from the Comms Database
    ...
    // Create an empty "Network" record, and set the record Id to KCDDefaultRecord
    // The CommsDat API interprets the record Id KCDDefaultRecord to mean the 
    // template record.
    CCDNetworkRecord* ptrNetworkRecord = (CCDNetworkRecord*)CCDRecordBase::RecordFactoryL(KCDTIdNetworkRecord);
    ptrNetworkRecord->SetRecordId(KCDDefaultRecord);
    ptrNetworkRecord->LoadL(*cmdbSession);
    ...
Related concepts
Comms Database concepts