Following a link to another table and finding a field by Id and by name: Tutorial

This tutorial shows you how to follow a link to a Symbian platform defined table. The tutorial also shows two methods to get the value of a field.


The tutorial shows you how to follow a link from a record in the IAP table to a record in the service table. The tutorial then shows you how to find the "Bearer Speed" field by its Id and by its name in the linked record.

The principles that apply here also apply to the other Symbian platform defined tables


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


  1. Make sure that you have created a session.

  2. Create the IAP record object in the tool or application process and prime it for the search for the service type "DialOutISP".

    Symbian platform defines the CCDIAPRecord class to represent a IAP record. The class is a schema for the record. The class defines the fields and links that make a IAP 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']]]KCDTIdIAPRecord defines the value of this Id for the IAP table. The Id allows the CommsDat API to retrieve the table from the Comms Database efficiently.
    // Create a single IAP record in memory and prime it with the type of service
    // that you want to find. In this case, the type of service is "DialOutISP".
    // This code fragment assumes that a session with the Comms Database has been created.
    // "iDb" is a pointer to a CMDBSession object
    _LIT(KISPType, "DialOutISP");
    TUint32 bearerSpeed;
    // Use the factory function CCDRecordBase::RecordFactoryL() to create the IAP record obejct. 
    // Note:
    // 1. the template parameter CCDIAPRecord defines 
    //    the "IAP" record type.
    // 2. the unique numeric Id KCDTIdIAPRecord is passed as a parameter
    //    to the constructor.
    CCDIAPRecord* ptrSingleIAPRecord = static_cast<CCDIAPRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdIAPRecord)); 
    // The storage for string or binary fields must be allocated
    // explicitly if set or reset by the application. Storage required for
    // storing data  retrieved from the database is handled by the implementation of the CommsDat API.
    // Set the service type.
    ptrSingleIAPRecord->iServiceType = KISPType; 
    // Note that you can replace the above two function calls with the 
    // single function call:
    // ptrSingleIAPRecord->iServiceType.SetL(KISPType); 
  3. Search for the first IAP record that has "DialOutISP" as the service type. If the record is found, load the associated service table record.

        // An IAP record with "DialOutISP" as the service type has
        // been found and loaded into memory. 
        // Load the service table record associated with this IAP.
    1. CASE 1 : Access the service record when you know the service type. This is the most effiecient method.

          CCDDialOutISPRecord* ptrIspRecord = static_cast<CCDDialOutISPRecord*>(ptrSingleIAPRecord->iService.iLinkedRecord);
          bearerSpeed = ptrIspRecord->iBearerSpeed;
    2. CASE 2: Access the service record when you do not know the service type. This is also the more general case and is slower than case 1.

      You can find a field by its Id, or you can find a field by its name. To find a field by its name is not recommended, because this operation is slow.
          // Use the base class "CCDServiceRecordBase" instead of the more specific
          // class "CCDDialOutISPRecord" [or any other specific class derived from "CCDServiceRecordBase"].
          CCDServiceRecordBase* ptrServiceRecord = static_cast<CCDServiceRecordBase*>(ptrSingleIAPRecord->iService.iLinkedRecord);
          CMDBField<TUint32>* field; 
          // Find a field by its Id
          field = (CMDBField<TUint32>*)ptrServiceRecord->GetFieldByIdL(KCDTIdBearerSpeed);
          bearerSpeed = *field;
         // Find a field by its name. Symbian platform defines KCDTypeNameBearerSpeed to represent 
         // the name of the field.
          TPtrC16 BearerName(KCDTypeNameBearerSpeed);
          TInt valueType; 
          field = (CMDBField<TUint32>*)ptrServiceRecord->GetFieldByNameL(BearerName,valueType);
          bearerSpeed = *field;
  4. Clean up.

        // This also deletes "ptrSingleIAPRecord->iService.iLinkedRecord"     
        delete ptrSingleIAPRecord;

Related concepts