Symbian3/SDK/Source/GUID-A96ABD2C-A338-58E5-A674-E840B1F53670.dita
author Graeme Price <GRAEME.PRICE@NOKIA.COM>
Fri, 15 Oct 2010 14:32:18 +0100
changeset 15 307f4279f433
parent 7 51a74ef9ed63
permissions -rw-r--r--
Initial contribution of the Adaptation Documentation.

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
<!-- This component and the accompanying materials are made available under the terms of the License 
"Eclipse Public License v1.0" which accompanies this distribution, 
and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
<!-- Initial Contributors:
    Nokia Corporation - initial contribution.
Contributors: 
-->
<!DOCTYPE task
  PUBLIC "-//OASIS//DTD DITA Task//EN" "task.dtd">
<task id="GUID-A96ABD2C-A338-58E5-A674-E840B1F53670" xml:lang="en"><title>Creating
a User Defined Table: Tutorial</title><shortdesc>This tutorial shows you how to create a user defined table. The
tutorial, then shows you how to store a new record. </shortdesc><prolog><metadata><keywords/></metadata></prolog><taskbody>


<prereq id="GUID-AE5DC98C-AF4A-5727-8090-42FF74E80BF4"><p>Before you start,
you must understand: </p> <ul>
<li id="GUID-FA757DB7-B25F-5ECA-9030-6D7B9EC4D7E4"><p>the general concept
of the Comms Database </p> </li>
<li id="GUID-54CB318E-7A04-5D63-8AEB-C2D75F428B38"><p>the specific concepts
of fields, records, links and tables </p> </li>
<li id="GUID-C95C350C-9DC8-5445-A58B-333CEFA97AA8"><p>how to write and build
application code to run on Symbian platform </p> </li>
</ul> </prereq>
<context id="GUID-24246F22-49AD-5AC3-A0BF-7C1C625035C7"><p>This tutorial shows
you: </p> <ul>
<li id="GUID-06AFEA66-4293-5D92-AD13-11B84A4DBCBF"><p>how to create a user
defined table </p> </li>
<li id="GUID-D304F5AA-29E6-510A-9B14-E0746C71D111"><p>how to create a user
defined record and store that record in the table </p> </li>
</ul> </context>
<steps id="GUID-79745846-CD3D-5CEB-8F3C-CB090D60FF03">
<step id="GUID-10AB178C-0854-5947-ADB8-A81379C0A464"><cmd>Make sure that you
have created a session. </cmd>
</step>
<step id="GUID-D5F5C68A-9391-51AA-91F3-6F874BAEF8DF"><cmd>Define a schema
for the new table. </cmd>

<info>Create an array of <xref href="GUID-1CDD0B97-8B00-3373-9908-512C9BC1CF51.dita"><apiname>SGenericRecordTypeInfo</apiname></xref> items.
Each <codeph>SGenericRecordTypeInfo</codeph> item defines a field in the record. </info>
<stepxmp><codeblock id="GUID-59343FD3-9183-55C1-B6CC-5E9690B5A928" xml:space="preserve">const SGenericRecordTypeInfo recordInfo[] =
        {
        SGenericRecordTypeInfo(KCDTIdRecordName,EText,ENotNull,KCDTypeNameRecordName),
        SGenericRecordTypeInfo(KCDTIdRecordTag,EUint32,ENoAttrs,KCDTypeNameRecordTag),
        SGenericRecordTypeInfo(KCDTIdWLANServiceId,EUint32,ENoAttrs,KNameWLANServiceId),
        SGenericRecordTypeInfo(KCDTIdWLANType,EUint32,ENoAttrs,KNameWLANType),
        SGenericRecordTypeInfo(KCDTIdWLANEnabled,EBool,ENoAttrs,KNameWLANEnabled),
        SGenericRecordTypeInfo(KCDTIdWLANPriority,EUint32,ENoAttrs,KNameWLANPriority),
        SGenericRecordTypeInfo(0,0,ENoAttrs,KCDNull)
        };</codeblock> </stepxmp>
</step>
<step id="GUID-7C23139E-C4EC-585E-B333-862C0C9D2B5F"><cmd>Define a name for
the table. </cmd>
<stepxmp><codeblock id="GUID-948FFFF5-DE3A-5614-9F93-6C44ACBD8F76" xml:space="preserve">_LIT(KGenericTable,"MyGenericTable");</codeblock> </stepxmp>
</step>
<step id="GUID-9BCE5E36-7BF8-545F-8D9E-859A6CC2BECA"><cmd>Create a <xref href="GUID-1CDD0B97-8B00-3373-9908-512C9BC1CF51.dita"><apiname>CMDBGenericRecord</apiname></xref> object. </cmd>

<info>A <xref href="GUID-1CDD0B97-8B00-3373-9908-512C9BC1CF51.dita"><apiname>CMDBGenericRecord</apiname></xref> object represents
a record and a set of records </info>

<info>Give the object the name of the table and the name of the schema. </info>
<stepxmp><codeblock id="GUID-5F88809A-8246-5D78-AFF1-7BF2F3B1A145" xml:space="preserve">...
// Record factory creates the CMDBGenericRecord object. The KCDNewTableRequest value 
// passed to the record factory allocates a new table Id.
CMDBGenericRecord* ptrNewTable = 
      static_cast&lt;CMDBGenericRecord*&gt;(CCDRecordBase::RecordFactoryL(KCDNewTableRequest));

// Initialise with the name of the table and the name of the schema.
ptrNewTable-&gt;InitialiseL(KGenericTable(),recordInfo);
...</codeblock> </stepxmp>
</step>
<step id="GUID-DA35A3FB-E7C5-5284-A681-FD6658FB123D"><cmd>Access fields in
the record. </cmd>

<info>The code uses <codeph>GetFieldByNameL()</codeph> and <codeph>GetFieldByIdL()</codeph>. </info>
<stepxmp><codeblock id="GUID-0C746871-2A0D-55DE-8FF8-54F876635EF5" xml:space="preserve">...
TInt valueType;

CMDBElement* LanType = ptrNewTable-&gt; GetFieldByNameL(KNameWLANType, valueType);
CMDBElement* RecordName = ptrNewTable-&gt;GetFieldByIdL(KCDTIdRecordName);
...</codeblock> </stepxmp>
</step>
<step id="GUID-4C0E0735-0D3C-55B0-9415-015572D40915"><cmd>Change the valuie
of the fields and create a new record. </cmd>
<stepxmp><codeblock id="GUID-4DEC5D91-F890-5EF1-B8C5-C49DA84B4192" xml:space="preserve">...
// Cast the field objects to the appropriate type
CMDBField&lt;TUint32&gt;* LanTypefield = static_cast&lt;CMDBField&lt;TUint32&gt;*&gt;(LanType);
CMDBField&lt;TDesC&gt;* RecordNamefield = static_cast&lt;CMDBField&lt;TDesC&gt;*&gt;(RecordName);

// Change the field value
*LanTypefield = 100;

// Change the field value
_LIT(KNewName, " NewName ");
RecordNamefield-&gt;SetMaxLengthL(KNewName().Length());
*RecordNamefield = KNewName();

// Can also use this format: RecordNamefield-&gt;SetL(KNewName());


// Asks for a new record
ptrNewTable-&gt;SetRecordId(KCDNewRecordRequest);

// Stores the new record
ptrNewTable-&gt;StoreL(*iDb);
...</codeblock> </stepxmp>
</step>
</steps>
</taskbody><related-links>
<link href="GUID-1AFDDD6F-CB99-587D-A0B5-D3F5B27F7135.dita"><linktext>Comms Database
                concepts</linktext></link>
</related-links></task>