|
1 /* |
|
2 * Copyright (c) 2002 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: create/save/get Internet connection methods from database. |
|
15 * |
|
16 */ |
|
17 |
|
18 //Include files |
|
19 #include "CWPInternetAPDB.h" |
|
20 #include "ProvisioningDebug.h" |
|
21 #include <sysutil.h> |
|
22 |
|
23 #ifdef SYMBIAN_SECURE_DBMS |
|
24 _LIT(KInternetSecureDBMShostID, "SECURE[101F84D6]"); |
|
25 #endif |
|
26 |
|
27 const TInt KWPDBMSFileValue = 0x101F84D6; |
|
28 const TUid KWPDBMSFileUid = |
|
29 { |
|
30 KWPDBMSFileValue |
|
31 }; |
|
32 |
|
33 CWPInternetAPDB* CWPInternetAPDB::NewL() |
|
34 { |
|
35 CWPInternetAPDB* self = NewLC(); |
|
36 CleanupStack::Pop(); |
|
37 |
|
38 return self; |
|
39 } |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // CWPInternetAPDB::NewLC |
|
43 // Two-phased constructor. |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 CWPInternetAPDB* CWPInternetAPDB::NewLC() |
|
47 { |
|
48 FLOG( _L( "[Provisioning] CWPInternetAPDB::NewLC:" ) ); |
|
49 CWPInternetAPDB* self = new( ELeave ) CWPInternetAPDB; |
|
50 |
|
51 CleanupStack::PushL(self); |
|
52 self->ConstructL(); |
|
53 |
|
54 FLOG( _L( "[Provisioning] CWPInternetAPDB::NewLC:done" ) ); |
|
55 return self; |
|
56 } |
|
57 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // CWPInternetAPDB::~CWPInternetAPDB |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 CWPInternetAPDB::~CWPInternetAPDB() |
|
63 { |
|
64 FLOG( _L( "[Provisioning] CWPInternetAPDB::~CWPInternetAPDB" ) ); |
|
65 iItemsDatabase.Close(); |
|
66 iRdbSession.Close(); |
|
67 iFsSession.Close(); |
|
68 |
|
69 FLOG( _L( "[Provisioning] CWPInternetAPDB::~CWPInternetAPDB: done" ) ); |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // CWPInternetAPDB::ConstructL |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 void CWPInternetAPDB::ConstructL() |
|
77 { |
|
78 FLOG( _L( "[Provisioning] CWPInternetAPDB::ConstructL" ) ); |
|
79 TParse name; |
|
80 TInt err; |
|
81 |
|
82 User::LeaveIfError(iFsSession.Connect()); |
|
83 User::LeaveIfError(iRdbSession.Connect() ); |
|
84 |
|
85 iFsSession.SetSessionToPrivate(EDriveC); |
|
86 |
|
87 #ifdef SYMBIAN_SECURE_DBMS |
|
88 name.Set(KtxDatabaseName, NULL, NULL); |
|
89 err = iItemsDatabase.Open(iRdbSession, name.FullName(), |
|
90 KInternetSecureDBMShostID); |
|
91 #else |
|
92 name.Set( KtxDatabaseName, KNonSecureDbFullName, NULL ); |
|
93 err = iItemsDatabase.Open(iRdbSession, DBFileName); |
|
94 #endif |
|
95 |
|
96 if (err == KErrNotFound) |
|
97 { |
|
98 CreateandOpenL(name); |
|
99 } |
|
100 else |
|
101 { |
|
102 |
|
103 if ( (err == KErrEof ) || (err == KErrCorrupt ) || (err |
|
104 == KErrArgument )) |
|
105 { |
|
106 // something seriously wrong with the db, delete it and try |
|
107 // to create new |
|
108 iRdbSession.DeleteDatabase(name.FullName(), KWPDBMSFileUid); |
|
109 CreateandOpenL(name); |
|
110 } |
|
111 |
|
112 } |
|
113 |
|
114 FLOG( _L( "[Provisioning] CWPInternetAPDB::ConstructL: done" ) ); |
|
115 } |
|
116 |
|
117 // ----------------------------------------------------------------------------- |
|
118 // CWPInternetAPDB::CreateandOpenL |
|
119 // ----------------------------------------------------------------------------- |
|
120 // |
|
121 inline void CWPInternetAPDB::CreateandOpenL(TParse& name) |
|
122 { |
|
123 FLOG( _L( "[Provisioning] CWPInternetAPDB::CreateandOpenL" ) ); |
|
124 TInt err; |
|
125 |
|
126 #ifdef SYMBIAN_SECURE_DBMS |
|
127 iItemsDatabase.Create(iRdbSession, name.FullName(), |
|
128 KInternetSecureDBMShostID); |
|
129 #else |
|
130 if( SysUtil::FFSSpaceBelowCriticalLevelL( &iFsSession, KEmptyDbSizeEstimate ) ) |
|
131 { |
|
132 User::Leave( KErrDiskFull ); |
|
133 } |
|
134 iItemsDatabase.Create(iFsSession, name.FullName()); |
|
135 #endif |
|
136 |
|
137 CreateTableL(iItemsDatabase); |
|
138 iItemsDatabase.Close(); |
|
139 #ifdef SYMBIAN_SECURE_DBMS |
|
140 |
|
141 err = iItemsDatabase.Open(iRdbSession, name.FullName(), |
|
142 KInternetSecureDBMShostID); |
|
143 |
|
144 #else |
|
145 err = iItemsDatabase.Open(iFsSession, DBFileName); |
|
146 #endif |
|
147 |
|
148 //Debug |
|
149 if (err != KErrNone) |
|
150 { |
|
151 FLOG(_L("Error man?" )); |
|
152 User::LeaveIfError(err); |
|
153 } |
|
154 |
|
155 FLOG( _L( "[Provisioning] CWPInternetAPDB::CreateandOpenL:done" ) ); |
|
156 } |
|
157 |
|
158 // ----------------------------------------------------------------------------- |
|
159 // CWPInternetAPDB::CreateTableL |
|
160 // ----------------------------------------------------------------------------- |
|
161 // |
|
162 void CWPInternetAPDB::CreateTableL(RDbDatabase& aDatabase) |
|
163 { |
|
164 FLOG( _L( "[Provisioning] CWPInternetAPDB::CreateTableL" ) ); |
|
165 |
|
166 // Create a table definition |
|
167 CDbColSet* columns=CDbColSet::NewLC(); |
|
168 |
|
169 // Add Columns |
|
170 TDbCol id(NCol1, EDbColInt32); |
|
171 |
|
172 // automatic indexing for items,it is our key field. |
|
173 id.iAttributes=id.EAutoIncrement; |
|
174 columns->AddL(id); |
|
175 |
|
176 columns->AddL(TDbCol(NCol2, EDbColInt32)); |
|
177 columns->AddL(TDbCol(NCol3, EDbColInt32)); |
|
178 columns->AddL(TDbCol(NCol4, EDbColText, KOriginatorMaxLength)); |
|
179 |
|
180 // Create a table |
|
181 User::LeaveIfError(aDatabase.CreateTable(KtxtItemlist, *columns) ); |
|
182 |
|
183 // cleanup the column set |
|
184 CleanupStack::PopAndDestroy(columns); |
|
185 FLOG( _L( "[Provisioning] CWPInternetAPDB::CreateTableL: done" ) ); |
|
186 } |
|
187 |
|
188 // ----------------------------------------------------------------------------- |
|
189 // CWPInternetAPDB::ReadDbItemsForOrigL |
|
190 // ----------------------------------------------------------------------------- |
|
191 // |
|
192 void CWPInternetAPDB::ReadDbItemsForOrigL( |
|
193 RArray<TAccessPointItem>& aItemArray, TDesC& aValue) |
|
194 { |
|
195 FLOG( _L( "[Provisioning] CWPInternetAPDB::ReadDbItemsForOrigL" ) ); |
|
196 aItemArray.Reset();// first reset the array |
|
197 |
|
198 _LIT(KEqualToString,"='%S'"); |
|
199 _LIT(KQuery, "SELECT * FROM %S WHERE %S"); |
|
200 |
|
201 TBuf<100> bufsql; |
|
202 bufsql.Append(KQuery); |
|
203 bufsql.Append(KEqualToString); |
|
204 TBuf<100> bufsql1; |
|
205 bufsql1.Format(bufsql, &KtxtItemlist, &NCol4, &aValue); |
|
206 |
|
207 ReadItemsL(aItemArray, bufsql1); |
|
208 |
|
209 FLOG( _L( "[Provisioning] CWPInternetAPDB::ReadDbItemsForOrigL:done" ) ); |
|
210 } |
|
211 |
|
212 // ----------------------------------------------------------------------------- |
|
213 // CWPInternetAPDB::ReadDbItemsL |
|
214 // ----------------------------------------------------------------------------- |
|
215 // |
|
216 void CWPInternetAPDB::ReadDbItemsL(RArray<TAccessPointItem>& aItemArray) |
|
217 { |
|
218 FLOG( _L( "[Provisioning] CWPInternetAPDB::ReadDbItemsL" ) ); |
|
219 aItemArray.Reset();// first reset the array |
|
220 |
|
221 TFileName QueryBuffer; |
|
222 |
|
223 // just get all columns & rows of same originator |
|
224 QueryBuffer.Copy(_L("SELECT * FROM ")); |
|
225 QueryBuffer.Append(KtxtItemlist); |
|
226 |
|
227 ReadItemsL(aItemArray, QueryBuffer); |
|
228 |
|
229 FLOG( _L( "[Provisioning] CWPInternetAPDB::ReadDbItemsL:done" ) ); |
|
230 } |
|
231 |
|
232 // ----------------------------------------------------------------------------- |
|
233 // CWPInternetAPDB::ReadItemsL |
|
234 // ----------------------------------------------------------------------------- |
|
235 // |
|
236 void CWPInternetAPDB::ReadItemsL(RArray<TAccessPointItem>& aItemArray, |
|
237 TFileName QueryBuffer) |
|
238 { |
|
239 FLOG( _L( "[Provisioning] CWPInternetAPDB::ReadItemsL" ) ); |
|
240 RDbView Myview; |
|
241 Myview.Prepare(iItemsDatabase, TDbQuery(QueryBuffer)); |
|
242 CleanupClosePushL(Myview); |
|
243 Myview.EvaluateAll(); |
|
244 Myview.FirstL(); |
|
245 |
|
246 while (Myview.AtRow()) |
|
247 { |
|
248 Myview.GetL(); |
|
249 |
|
250 TAccessPointItem AccessPointItem; |
|
251 AccessPointItem.iIndex = Myview.ColInt(1); |
|
252 AccessPointItem.iAPID = Myview.ColInt(2); |
|
253 AccessPointItem.iBearerType = Myview.ColInt(3); |
|
254 AccessPointItem.iOriginator.Copy(Myview.ColDes(4)); |
|
255 |
|
256 aItemArray.Append(AccessPointItem); |
|
257 Myview.NextL(); |
|
258 } |
|
259 |
|
260 CleanupStack::PopAndDestroy(); // Myview |
|
261 FLOG( _L( "[Provisioning] CWPInternetAPDB::ReadItemsL: done" ) ); |
|
262 } |
|
263 |
|
264 // ----------------------------------------------------------------------------- |
|
265 // CWPInternetAPDB::SaveToDatabaseL |
|
266 // ----------------------------------------------------------------------------- |
|
267 // |
|
268 void CWPInternetAPDB::SaveToDatabaseL(TInt& aIndex, TUint aAPId, |
|
269 TUint32 aBearerType, const TDesC& aOriginator) |
|
270 { |
|
271 FLOG( _L( "[Provisioning] CWPInternetAPDB::SaveToDatabaseL" ) ); |
|
272 |
|
273 //If there is any existing rows for the same APID, delete those |
|
274 if (DeleteFromDatabaseL(aAPId)) |
|
275 { |
|
276 iItemsDatabase.Begin(); |
|
277 } |
|
278 |
|
279 TFileName QueryBuffer; |
|
280 QueryBuffer.Copy(_L("SELECT * FROM ")); |
|
281 QueryBuffer.Append(KtxtItemlist); |
|
282 |
|
283 RDbView Myview; |
|
284 Myview.Prepare(iItemsDatabase, TDbQuery(QueryBuffer)); |
|
285 CleanupClosePushL(Myview); |
|
286 |
|
287 Myview.InsertL(); |
|
288 |
|
289 Myview.SetColL(2, aAPId); |
|
290 Myview.SetColL(3, aBearerType); |
|
291 Myview.SetColL(4, aOriginator); |
|
292 |
|
293 Myview.PutL(); |
|
294 |
|
295 aIndex = Myview.ColInt(1);// autoincrement gives us unique index. |
|
296 |
|
297 CleanupStack::PopAndDestroy(1); // Myview |
|
298 iItemsDatabase.Commit(); |
|
299 FLOG( _L( "[Provisioning] CWPInternetAPDB::SaveToDatabaseL:done" ) ); |
|
300 } |
|
301 |
|
302 // ----------------------------------------------------------------------------- |
|
303 // CWPInternetAPDB::DeleteFromDatabaseL |
|
304 // ----------------------------------------------------------------------------- |
|
305 // |
|
306 TBool CWPInternetAPDB::DeleteFromDatabaseL(TUint aAPId) |
|
307 { |
|
308 FLOG( _L( "[Provisioning] CWPInternetAPDB::DeleteFromDatabaseL" ) ); |
|
309 TBool rowsdeleted = EFalse; |
|
310 TFileName QueryBuffer; |
|
311 QueryBuffer.Copy(_L("SELECT * FROM ")); |
|
312 QueryBuffer.Append(KtxtItemlist); |
|
313 QueryBuffer.Append(_L(" WHERE ")); |
|
314 QueryBuffer.Append(NCol2); |
|
315 QueryBuffer.Append(_L(" = ")); |
|
316 QueryBuffer.AppendNum(aAPId); |
|
317 |
|
318 iItemsDatabase.Begin(); |
|
319 |
|
320 RDbView Myview; |
|
321 // query buffer with index finds only the selected item row. |
|
322 Myview.Prepare(iItemsDatabase, TDbQuery(QueryBuffer)); |
|
323 CleanupClosePushL(Myview); |
|
324 |
|
325 Myview.EvaluateAll(); |
|
326 Myview.FirstL(); |
|
327 |
|
328 if (!Myview.IsEmptyL()) |
|
329 { |
|
330 // we have autoincrement in index so it should be unique |
|
331 // but just to make sure, we use 'while', instead of 'if' |
|
332 while (Myview.AtRow()) |
|
333 { |
|
334 Myview.GetL(); |
|
335 Myview.DeleteL(); |
|
336 Myview.NextL(); |
|
337 } |
|
338 |
|
339 iItemsDatabase.Commit(); |
|
340 // compacts the databse, by physically removig deleted data. |
|
341 iItemsDatabase.Compact(); |
|
342 rowsdeleted = ETrue; |
|
343 } |
|
344 CleanupStack::PopAndDestroy(1); // Myview |
|
345 |
|
346 FLOG( _L( "[Provisioning] CWPInternetAPDB::DeleteFromDatabaseL: done" ) ); |
|
347 return rowsdeleted; |
|
348 } |
|
349 |
|
350 //End of the file |