|
1 <?xml version="1.0" encoding="utf-8"?> |
|
2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. --> |
|
3 <!-- This component and the accompanying materials are made available under the terms of the License |
|
4 "Eclipse Public License v1.0" which accompanies this distribution, |
|
5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". --> |
|
6 <!-- Initial Contributors: |
|
7 Nokia Corporation - initial contribution. |
|
8 Contributors: |
|
9 --> |
|
10 <!DOCTYPE task |
|
11 PUBLIC "-//OASIS//DTD DITA Task//EN" "task.dtd"> |
|
12 <task id="GUID-CE011029-0F2B-50D4-B793-A24C7ECFC21E" xml:lang="en"><title>Loading |
|
13 a Symbian Platform Defined Table: Tutorial</title><shortdesc>This tutorial shows you how to load a Symbian platform defined |
|
14 table from the Comms Database. The topic also gives an example that shows |
|
15 you how to process the records in a table. </shortdesc><prolog><metadata><keywords/></metadata></prolog><taskbody> |
|
16 <prereq id="GUID-68076901-260F-5588-B05A-5B51412DEE43"><p>Before you start, |
|
17 you must understand: </p> <ul> |
|
18 <li id="GUID-AA2573E6-E199-5E5B-B458-DC189FE982F0"><p>the general concept |
|
19 of the Comms Database </p> </li> |
|
20 <li id="GUID-43160B1C-200E-5326-9CE8-474A49A81C4E"><p>the specific concept |
|
21 of fields, records, links and tables </p> </li> |
|
22 <li id="GUID-2CED5E8A-83C3-5CCE-B91D-9E773AFEBB2D"><p>how to write and build |
|
23 application code to run on Symbian platform</p> </li> |
|
24 </ul> </prereq> |
|
25 <context id="GUID-770B3F59-5FA6-58C6-A484-118DB7288D3B"><p>This tutorial shows |
|
26 you how to load the <i>Connection Preferences</i> table. The principles that |
|
27 apply here also apply to the other Symbian platform defined tables. </p> <p>This |
|
28 tutorial shows you the main steps. </p> <p>This tutorial also shows how you |
|
29 can process the records in the table. The example code shows you how to sort |
|
30 the records in the table. </p> </context> |
|
31 <steps id="GUID-03C423B7-1C20-592A-9E8D-0D7D996E2A05"> |
|
32 <step id="GUID-0DE3770C-9E39-5A43-88F3-5957F5627317"><cmd>Make sure that you |
|
33 have created a session. </cmd> |
|
34 </step> |
|
35 <step id="GUID-3F0C9272-6A9E-52DF-9711-F44036BC87CE"><cmd>Create the table |
|
36 object in the tool or application process. </cmd> |
|
37 |
|
38 <info>You create a <xref href="GUID-1CDD0B97-8B00-3373-9908-512C9BC1CF51.dita"><apiname>CMDBRecordSet</apiname></xref> <codeph><T></codeph> object |
|
39 and specify <xref href="GUID-1CDD0B97-8B00-3373-9908-512C9BC1CF51.dita"><apiname>CCDConnectionPrefsRecord</apiname></xref> as |
|
40 the template parameter. </info> |
|
41 |
|
42 <info>Symbian platform defines the <codeph>CCDConnectionPrefsRecord</codeph> class |
|
43 to represent a Connection Preferences record. The class is a schema for the |
|
44 record. The class defines the fields and links that make a Connection Preferences |
|
45 record. </info> |
|
46 <info>Symbian platform defines <xref href="GUID-6DAF85AD-E412-5823-81C2-FC1755A90A84.dita#GUID-6DAF85AD-E412-5823-81C2-FC1755A90A84/GUID-32E556BC-55C3-5FBD-9A60-9708139C20D6">unique |
|
47 numeric Id</xref> s for Symbian platform defined tables. The symbol <xref href="GUID-1CDD0B97-8B00-3373-9908-512C9BC1CF51.dita"><apiname>KCDTIdConnectionPrefsRecord</apiname></xref> defines the value |
|
48 of this Id for the Connection Preferences table. The Id allows the CommsDat |
|
49 API to retrieve the table from the Comms Database efficiently. </info> |
|
50 <info>To work with other Symbian platform defined tables, use |
|
51 the correct class name and the correct unique numeric Id values. The <xref href="GUID-58089281-9DD0-502D-8DFD-831E7BAA931E.dita">Reference</xref> section |
|
52 contains a list of all Symbian defined tables. </info> |
|
53 <stepxmp><codeblock id="GUID-B141FB9E-11BA-53FB-912C-4A86294161EB" xml:space="preserve">... |
|
54 |
|
55 // This code fragment assumes that a session with the Comms Database has been created. |
|
56 // iDb is a pointer to a CMDBSession object |
|
57 ... |
|
58 |
|
59 // Use the standard "new (ELeave)" construction to create the object to |
|
60 // represent the table. |
|
61 // |
|
62 // Note: |
|
63 // 1. the template parameter CCDConnectionPrefsRecord defines |
|
64 // the "Connection Preferences" record type. |
|
65 // 2. the unique numeric Id KCDTIdConnectionPrefsRecord is passed as a parameter |
|
66 // to the constructor. |
|
67 CMDBRecordSet<CCDConnectionPrefsRecord>* ptrConnPrefRecordSet = |
|
68 new (ELeave) CMDBRecordSet(KCDTIdConnectionPrefsRecord); |
|
69 ... |
|
70 </codeblock> </stepxmp> |
|
71 </step> |
|
72 <step id="GUID-A622B842-A502-573A-BCD0-E521AA5C7011"><cmd>Load the table from |
|
73 the Comms Database. </cmd> |
|
74 |
|
75 <info>Use the <codeph>LoadL()</codeph> function to load the table from the |
|
76 Comms Database. The function is called on the class that defines the table. |
|
77 The function is implemented in the base class <xref href="GUID-1CDD0B97-8B00-3373-9908-512C9BC1CF51.dita"><apiname>MMetaDatabase</apiname></xref>. |
|
78 You pass a reference to the session object into the <codeph>LoadL()</codeph> function. </info> |
|
79 <stepxmp><codeblock id="GUID-3B4F5F6D-4ACE-560D-BBF7-1DCC037AAADE" xml:space="preserve">... |
|
80 ptrConnPrefRecordSet->LoadL(*iDb); |
|
81 // If the flow of the code reaches here, the table has been loaded. |
|
82 ...</codeblock> </stepxmp> |
|
83 </step> |
|
84 <step id="GUID-7A9CA79C-79FD-570A-9D48-82565878E422"><cmd>Process the records. </cmd> |
|
85 |
|
86 <info>This step is optional. It is an example that shows how you can process |
|
87 the records in a table. The example also shows you how to retrieve the number |
|
88 of records in the table. </info> |
|
89 <stepxmp>The following code sorts the records into record Id order. The record |
|
90 Id is the part of the <xref href="GUID-6DAF85AD-E412-5823-81C2-FC1755A90A84.dita#GUID-6DAF85AD-E412-5823-81C2-FC1755A90A84/GUID-32E556BC-55C3-5FBD-9A60-9708139C20D6">unique |
|
91 numeric Id</xref> that identifies an instance of a record. </stepxmp> |
|
92 <stepxmp>A table uses an <xref href="GUID-1CDD0B97-8B00-3373-9908-512C9BC1CF51.dita"><apiname>RPointerArray</apiname></xref> <codeph><T></codeph> to |
|
93 contain the records. <codeph>RPointerArray</codeph> allows applications to |
|
94 customise the behaviour of the sort operation. </stepxmp> |
|
95 <info>The code uses the <xref href="GUID-1CDD0B97-8B00-3373-9908-512C9BC1CF51.dita"><apiname>TLinearOrder</apiname></xref> <codeph><T></codeph> class. </info> |
|
96 <stepxmp><codeblock id="GUID-FE35BC1E-1D10-5741-9684-4C6383A226AC" xml:space="preserve">... |
|
97 // Customised sort function |
|
98 TInt SortRecordsById(const CMDBRecordBase& aLeft, const CMDBRecordBase& aRight) |
|
99 { |
|
100 return (aLeft.RecordId()) < (aRight.RecordId()) ? -1 : 1; |
|
101 } |
|
102 ... |
|
103 |
|
104 // Total number of records in the table |
|
105 TInt totalcount = ptrConnPrefRecordSet->iRecords.Count(); |
|
106 ... |
|
107 |
|
108 // Sort the records. |
|
109 // 1. Define a TLinearOrder<T> class for a Connection Preferences record and instantiate |
|
110 // the class. |
|
111 // 2. Invoke the sort operation. |
|
112 TLinearOrder<CMDBRecordBase> orderbyId(SortRecordsById); |
|
113 ptrConnPrefRecordSet->iRecords.Sort(orderbyId); |
|
114 ...</codeblock> </stepxmp> |
|
115 </step> |
|
116 </steps> |
|
117 </taskbody><related-links> |
|
118 <link href="GUID-1AFDDD6F-CB99-587D-A0B5-D3F5B27F7135.dita"><linktext>Comms Database |
|
119 concepts</linktext></link> |
|
120 </related-links></task> |