|
1 /* |
|
2 * Copyright (c) 2002-2005 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Landmarks Server's utilities |
|
15 * |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include "epos_landmarkdatabasestructure.h" |
|
21 #include "epos_cposlmlocaldbaccess.h" |
|
22 #include "epos_poslmserverutility.h" |
|
23 |
|
24 const TInt KIdIndexStartSize = 1100; |
|
25 const TInt KIdIndexGrowth = 9; |
|
26 |
|
27 // ================= MEMBER FUNCTIONS ======================= |
|
28 |
|
29 // ----------------------------------------------------------------------------- |
|
30 // ----------------------------------------------------------------------------- |
|
31 // |
|
32 TInt PosLmServerUtility::EstimatedDiskSizeOfIndex( |
|
33 TLmOperation aOperation, |
|
34 TInt aCountOfRecords ) |
|
35 { |
|
36 ASSERT( aOperation == ECreateFieldsLmIdIndex || aOperation == ECreateCategoriesLmIdIndex ); |
|
37 |
|
38 return KIdIndexStartSize + aCountOfRecords * KIdIndexGrowth; |
|
39 } |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 TBool PosLmServerUtility::IndexExistsL( |
|
45 const RDbNamedDatabase& aDatabase, |
|
46 const TDesC& aTable, |
|
47 const TDesC& aIndex ) |
|
48 { |
|
49 TBool found( EFalse ); |
|
50 CDbIndexNames* indexes = aDatabase.IndexNamesL( aTable ); |
|
51 for ( TInt i = 0; i < indexes->Count(); ++i ) |
|
52 { |
|
53 if ( (*indexes)[i].Compare( aIndex ) == 0 ) |
|
54 { |
|
55 found = ETrue; |
|
56 break; |
|
57 } |
|
58 } |
|
59 delete indexes; |
|
60 return found; |
|
61 } |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 TUint PosLmServerUtility::GetTableRowCountL( |
|
67 CPosLmLocalDbAccess& aDbAccess, |
|
68 const TDesC& aTableName ) |
|
69 { |
|
70 RDbNamedDatabase db; |
|
71 aDbAccess.GetDatabase( db ); |
|
72 |
|
73 RDbTable table; |
|
74 User::LeaveIfError( table.Open( db, aTableName, RDbRowSet::EReadOnly ) ); |
|
75 CleanupClosePushL( table ); |
|
76 TInt numRows = table.CountL(); |
|
77 CleanupStack::PopAndDestroy( &table ); |
|
78 |
|
79 if ( numRows < 0 ) |
|
80 { |
|
81 User::Leave( KErrNotFound ); |
|
82 } |
|
83 |
|
84 return numRows; |
|
85 } |
|
86 |
|
87 // ----------------------------------------------------------------------------- |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 TUint PosLmServerUtility::TotalLandmarkCountL( CPosLmLocalDbAccess& aDbAccess ) |
|
91 { |
|
92 return PosLmServerUtility::GetTableRowCountL( aDbAccess, KPosLmLandmarkTable ); |
|
93 } |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // ----------------------------------------------------------------------------- |
|
97 // |
|
98 HBufC* PosLmServerUtility::ReadFromLongTextColumnLC( |
|
99 RDbRowSet& aView, |
|
100 TDbColNo aCol ) |
|
101 { |
|
102 TInt len = aView.ColLength( aCol ); |
|
103 if ( len > 0 ) |
|
104 { |
|
105 HBufC* text = HBufC::NewLC( len ); |
|
106 TPtr ptr = text->Des(); |
|
107 |
|
108 RDbColReadStream readStream; |
|
109 readStream.OpenL( aView, aCol ); |
|
110 CleanupClosePushL( readStream ); |
|
111 readStream.ReadL( ptr, len ); |
|
112 CleanupStack::PopAndDestroy( &readStream ); |
|
113 |
|
114 return text; |
|
115 } |
|
116 else |
|
117 { |
|
118 return KNullDesC().AllocLC(); |
|
119 } |
|
120 } |
|
121 |