|
1 /* |
|
2 * Copyright (c) 2010 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: |
|
15 * Retrieving maptile path from lookup db implementation |
|
16 * |
|
17 */ |
|
18 |
|
19 #include <bautils.h> |
|
20 #include "maptiledblookuptable.h" |
|
21 |
|
22 // select all from |
|
23 _LIT( KSelectAllFrom, "SELECT * FROM " ); |
|
24 |
|
25 // string 'where' |
|
26 _LIT( KStringWhere, " WHERE " ); |
|
27 |
|
28 // string ' = ' |
|
29 _LIT( KStringEqual, " = " ); |
|
30 |
|
31 // string 'And' |
|
32 _LIT( KStringAnd, " AND " ); |
|
33 |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // CLookupMapTileDatabase::CLookupMapTileDatabase() |
|
37 // Default constructor. |
|
38 // ----------------------------------------------------------------------------- |
|
39 // |
|
40 CLookupMapTileDatabase::CLookupMapTileDatabase() |
|
41 { |
|
42 } |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // CLookupMapTileDatabase::~CLookupMapTileDatabase() |
|
46 // Destructor. |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 CLookupMapTileDatabase::~CLookupMapTileDatabase() |
|
50 { |
|
51 |
|
52 // close the database |
|
53 iItemsDatabase.Close(); |
|
54 |
|
55 // close the file session |
|
56 iFsSession.Close(); |
|
57 } |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CLookupMapTileDatabase::~CLookupMapTileDatabase() |
|
61 // Creates an object of this class and pushes to cleanup stack. |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 CLookupMapTileDatabase* CLookupMapTileDatabase::NewLC( const TDesC& aLookupTableName ) |
|
65 { |
|
66 |
|
67 CLookupMapTileDatabase* self = new (ELeave) CLookupMapTileDatabase; |
|
68 CleanupStack::PushL(self); |
|
69 self->ConstructL( aLookupTableName ); |
|
70 return self; |
|
71 } |
|
72 |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CLookupMapTileDatabase::NewL() |
|
76 // Creates an object of this class. |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 CLookupMapTileDatabase* CLookupMapTileDatabase::NewL( const TDesC& aLookupTableName ) |
|
80 { |
|
81 CLookupMapTileDatabase* self = CLookupMapTileDatabase::NewLC( aLookupTableName ); |
|
82 CleanupStack::Pop( self ); |
|
83 return self; |
|
84 } |
|
85 |
|
86 |
|
87 // ----------------------------------------------------------------------------- |
|
88 // CLookupMapTileDatabase::ConstructL() |
|
89 // 2nd phase contructor. |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 void CLookupMapTileDatabase::ConstructL( const TDesC& aLookupTableName ) |
|
93 { |
|
94 |
|
95 User::LeaveIfError( iFsSession.Connect() ); |
|
96 |
|
97 iDbFileName.Copy( KLookupDbPath ); |
|
98 iDbFileName.Append( aLookupTableName ); |
|
99 |
|
100 iDatabaseExists = EFalse; |
|
101 |
|
102 if( BaflUtils::FileExists( iFsSession, iDbFileName ) ) |
|
103 { |
|
104 // database exists |
|
105 iDatabaseExists = ETrue; |
|
106 } |
|
107 } |
|
108 |
|
109 |
|
110 // ----------------------------------------------------------------------------- |
|
111 // CLookupMapTileDatabase::FindEntryL() |
|
112 // Finds an entry in the lookup table. |
|
113 // ----------------------------------------------------------------------------- |
|
114 // |
|
115 void CLookupMapTileDatabase::FindEntryL( TLookupItem& aLookupItem ) |
|
116 { |
|
117 |
|
118 // used to check whether entry available or not |
|
119 TBool entryAvailable = EFalse; |
|
120 |
|
121 if ( iDatabaseExists ) |
|
122 { |
|
123 |
|
124 // Create a query to find the item. |
|
125 TFileName queryBuffer; |
|
126 queryBuffer.Copy( KSelectAllFrom ); |
|
127 queryBuffer.Append( KMapTileLookupTable ); |
|
128 queryBuffer.Append( KStringWhere ); |
|
129 queryBuffer.Append( NCntColUid ); |
|
130 queryBuffer.Append( KStringEqual ); |
|
131 queryBuffer.AppendNum( aLookupItem.iUid ); |
|
132 queryBuffer.Append( KStringAnd ); |
|
133 queryBuffer.Append( NColSource ); |
|
134 queryBuffer.Append( KStringEqual ); |
|
135 queryBuffer.AppendNum( aLookupItem.iSource ); |
|
136 |
|
137 TInt ret = iItemsDatabase.Open( iFsSession, iDbFileName ); |
|
138 |
|
139 if( ret != KErrNone ) |
|
140 { |
|
141 //if already opened , close and open again |
|
142 iItemsDatabase.Close(); |
|
143 User::LeaveIfError( iItemsDatabase.Open( iFsSession, iDbFileName ) ); |
|
144 } |
|
145 User::LeaveIfError( iItemsDatabase.Begin() ); |
|
146 // Create a view of the table with the above query. |
|
147 RDbView myView; |
|
148 myView.Prepare( iItemsDatabase, TDbQuery( queryBuffer ) ); |
|
149 CleanupClosePushL( myView ); |
|
150 myView.EvaluateAll(); |
|
151 myView.FirstL(); |
|
152 |
|
153 if( myView.AtRow() ) |
|
154 { |
|
155 // Item found. get the details. |
|
156 myView.GetL(); |
|
157 if( aLookupItem.iUid == myView.ColUint( KColumnUid ) ) |
|
158 { |
|
159 aLookupItem.iFilePath.Copy( myView.ColDes16( KColumnFilePath ) ); |
|
160 entryAvailable = ETrue; |
|
161 } |
|
162 } |
|
163 |
|
164 CleanupStack::PopAndDestroy( &myView ); // myView |
|
165 |
|
166 //Close the database |
|
167 iItemsDatabase.Close(); |
|
168 } |
|
169 |
|
170 //No entry found |
|
171 if( !entryAvailable ) |
|
172 { |
|
173 User::Leave( KErrNotFound ); |
|
174 } |
|
175 } |
|
176 |
|
177 // End of file |
|
178 |