7 Nokia Corporation - initial contribution. |
7 Nokia Corporation - initial contribution. |
8 Contributors: |
8 Contributors: |
9 --> |
9 --> |
10 <!DOCTYPE task |
10 <!DOCTYPE task |
11 PUBLIC "-//OASIS//DTD DITA Task//EN" "task.dtd"> |
11 PUBLIC "-//OASIS//DTD DITA Task//EN" "task.dtd"> |
12 <task xml:lang="en" id="GUID-A96ABD2C-A338-58E5-A674-E840B1F53670"><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 OS </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[] = |
12 <task id="GUID-A96ABD2C-A338-58E5-A674-E840B1F53670" xml:lang="en"><title>Creating |
|
13 a User Defined Table: Tutorial</title><shortdesc>This tutorial shows you how to create a user defined table. The |
|
14 tutorial, then shows you how to store a new record. </shortdesc><prolog><metadata><keywords/></metadata></prolog><taskbody> |
|
15 |
|
16 |
|
17 <prereq id="GUID-AE5DC98C-AF4A-5727-8090-42FF74E80BF4"><p>Before you start, |
|
18 you must understand: </p> <ul> |
|
19 <li id="GUID-FA757DB7-B25F-5ECA-9030-6D7B9EC4D7E4"><p>the general concept |
|
20 of the Comms Database </p> </li> |
|
21 <li id="GUID-54CB318E-7A04-5D63-8AEB-C2D75F428B38"><p>the specific concepts |
|
22 of fields, records, links and tables </p> </li> |
|
23 <li id="GUID-C95C350C-9DC8-5445-A58B-333CEFA97AA8"><p>how to write and build |
|
24 application code to run on Symbian platform </p> </li> |
|
25 </ul> </prereq> |
|
26 <context id="GUID-24246F22-49AD-5AC3-A0BF-7C1C625035C7"><p>This tutorial shows |
|
27 you: </p> <ul> |
|
28 <li id="GUID-06AFEA66-4293-5D92-AD13-11B84A4DBCBF"><p>how to create a user |
|
29 defined table </p> </li> |
|
30 <li id="GUID-D304F5AA-29E6-510A-9B14-E0746C71D111"><p>how to create a user |
|
31 defined record and store that record in the table </p> </li> |
|
32 </ul> </context> |
|
33 <steps id="GUID-79745846-CD3D-5CEB-8F3C-CB090D60FF03"> |
|
34 <step id="GUID-10AB178C-0854-5947-ADB8-A81379C0A464"><cmd>Make sure that you |
|
35 have created a session. </cmd> |
|
36 </step> |
|
37 <step id="GUID-D5F5C68A-9391-51AA-91F3-6F874BAEF8DF"><cmd>Define a schema |
|
38 for the new table. </cmd> |
|
39 |
|
40 <info>Create an array of <xref href="GUID-1CDD0B97-8B00-3373-9908-512C9BC1CF51.dita"><apiname>SGenericRecordTypeInfo</apiname></xref> items. |
|
41 Each <codeph>SGenericRecordTypeInfo</codeph> item defines a field in the record. </info> |
|
42 <stepxmp><codeblock id="GUID-59343FD3-9183-55C1-B6CC-5E9690B5A928" xml:space="preserve">const SGenericRecordTypeInfo recordInfo[] = |
13 { |
43 { |
14 SGenericRecordTypeInfo(KCDTIdRecordName,EText,ENotNull,KCDTypeNameRecordName), |
44 SGenericRecordTypeInfo(KCDTIdRecordName,EText,ENotNull,KCDTypeNameRecordName), |
15 SGenericRecordTypeInfo(KCDTIdRecordTag,EUint32,ENoAttrs,KCDTypeNameRecordTag), |
45 SGenericRecordTypeInfo(KCDTIdRecordTag,EUint32,ENoAttrs,KCDTypeNameRecordTag), |
16 SGenericRecordTypeInfo(KCDTIdWLANServiceId,EUint32,ENoAttrs,KNameWLANServiceId), |
46 SGenericRecordTypeInfo(KCDTIdWLANServiceId,EUint32,ENoAttrs,KNameWLANServiceId), |
17 SGenericRecordTypeInfo(KCDTIdWLANType,EUint32,ENoAttrs,KNameWLANType), |
47 SGenericRecordTypeInfo(KCDTIdWLANType,EUint32,ENoAttrs,KNameWLANType), |
18 SGenericRecordTypeInfo(KCDTIdWLANEnabled,EBool,ENoAttrs,KNameWLANEnabled), |
48 SGenericRecordTypeInfo(KCDTIdWLANEnabled,EBool,ENoAttrs,KNameWLANEnabled), |
19 SGenericRecordTypeInfo(KCDTIdWLANPriority,EUint32,ENoAttrs,KNameWLANPriority), |
49 SGenericRecordTypeInfo(KCDTIdWLANPriority,EUint32,ENoAttrs,KNameWLANPriority), |
20 SGenericRecordTypeInfo(0,0,ENoAttrs,KCDNull) |
50 SGenericRecordTypeInfo(0,0,ENoAttrs,KCDNull) |
21 };</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">... |
51 };</codeblock> </stepxmp> |
|
52 </step> |
|
53 <step id="GUID-7C23139E-C4EC-585E-B333-862C0C9D2B5F"><cmd>Define a name for |
|
54 the table. </cmd> |
|
55 <stepxmp><codeblock id="GUID-948FFFF5-DE3A-5614-9F93-6C44ACBD8F76" xml:space="preserve">_LIT(KGenericTable,"MyGenericTable");</codeblock> </stepxmp> |
|
56 </step> |
|
57 <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> |
|
58 |
|
59 <info>A <xref href="GUID-1CDD0B97-8B00-3373-9908-512C9BC1CF51.dita"><apiname>CMDBGenericRecord</apiname></xref> object represents |
|
60 a record and a set of records </info> |
|
61 |
|
62 <info>Give the object the name of the table and the name of the schema. </info> |
|
63 <stepxmp><codeblock id="GUID-5F88809A-8246-5D78-AFF1-7BF2F3B1A145" xml:space="preserve">... |
22 // Record factory creates the CMDBGenericRecord object. The KCDNewTableRequest value |
64 // Record factory creates the CMDBGenericRecord object. The KCDNewTableRequest value |
23 // passed to the record factory allocates a new table Id. |
65 // passed to the record factory allocates a new table Id. |
24 CMDBGenericRecord* ptrNewTable = |
66 CMDBGenericRecord* ptrNewTable = |
25 static_cast<CMDBGenericRecord*>(CCDRecordBase::RecordFactoryL(KCDNewTableRequest)); |
67 static_cast<CMDBGenericRecord*>(CCDRecordBase::RecordFactoryL(KCDNewTableRequest)); |
26 |
68 |
27 // Initialise with the name of the table and the name of the schema. |
69 // Initialise with the name of the table and the name of the schema. |
28 ptrNewTable->InitialiseL(KGenericTable(),recordInfo); |
70 ptrNewTable->InitialiseL(KGenericTable(),recordInfo); |
29 ...</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">... |
71 ...</codeblock> </stepxmp> |
|
72 </step> |
|
73 <step id="GUID-DA35A3FB-E7C5-5284-A681-FD6658FB123D"><cmd>Access fields in |
|
74 the record. </cmd> |
|
75 |
|
76 <info>The code uses <codeph>GetFieldByNameL()</codeph> and <codeph>GetFieldByIdL()</codeph>. </info> |
|
77 <stepxmp><codeblock id="GUID-0C746871-2A0D-55DE-8FF8-54F876635EF5" xml:space="preserve">... |
30 TInt valueType; |
78 TInt valueType; |
31 |
79 |
32 CMDBElement* LanType = ptrNewTable-> GetFieldByNameL(KNameWLANType, valueType); |
80 CMDBElement* LanType = ptrNewTable-> GetFieldByNameL(KNameWLANType, valueType); |
33 CMDBElement* RecordName = ptrNewTable->GetFieldByIdL(KCDTIdRecordName); |
81 CMDBElement* RecordName = ptrNewTable->GetFieldByIdL(KCDTIdRecordName); |
34 ...</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">... |
82 ...</codeblock> </stepxmp> |
|
83 </step> |
|
84 <step id="GUID-4C0E0735-0D3C-55B0-9415-015572D40915"><cmd>Change the valuie |
|
85 of the fields and create a new record. </cmd> |
|
86 <stepxmp><codeblock id="GUID-4DEC5D91-F890-5EF1-B8C5-C49DA84B4192" xml:space="preserve">... |
35 // Cast the field objects to the appropriate type |
87 // Cast the field objects to the appropriate type |
36 CMDBField<TUint32>* LanTypefield = static_cast<CMDBField<TUint32>*>(LanType); |
88 CMDBField<TUint32>* LanTypefield = static_cast<CMDBField<TUint32>*>(LanType); |
37 CMDBField<TDesC>* RecordNamefield = static_cast<CMDBField<TDesC>*>(RecordName); |
89 CMDBField<TDesC>* RecordNamefield = static_cast<CMDBField<TDesC>*>(RecordName); |
38 |
90 |
39 // Change the field value |
91 // Change the field value |