|
1 /* |
|
2 * Copyright (c) 2004 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 the License "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 * Implementation of class RFavouritesSrvTable |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 |
|
23 #include <s32strm.h> |
|
24 #include "FavouritesSrvTable.h" |
|
25 #include "FavouritesPanic.h" |
|
26 #include "FavouritesItemData.h" |
|
27 #include "FavouritesFilter.h" |
|
28 |
|
29 // CONSTANTS |
|
30 |
|
31 /// Buffer size for formatting SQL query in SetFiltersL(). |
|
32 const TInt KFavouritesMaxSql = 255; |
|
33 |
|
34 // Database table names. |
|
35 |
|
36 /// Favourites table name. |
|
37 _LIT( KFavouritesTableName, "Favourites" ); |
|
38 |
|
39 // Database column names. // First in: |
|
40 |
|
41 /// "Uid" column name. |
|
42 _LIT( KFavouritesDbUidColName, "Uid" ); // 6.6 |
|
43 /// "Parent folder" column name. |
|
44 _LIT( KFavouritesDbParentColName, "Parent" ); // 6.6 |
|
45 /// "Type" column name. |
|
46 _LIT( KFavouritesDbTypeColName, "Type" ); // 6.6 |
|
47 /// "Name" column name. |
|
48 _LIT( KFavouritesDbNameColName, "Name" ); // 6.6 |
|
49 /// "URL" column name. |
|
50 _LIT( KFavouritesDbUrlColName, "Url" ); // 6.6 |
|
51 /// "WAP AP ApId" column name. |
|
52 _LIT( KFavouritesDbApIdColName, "WapApId" ); // 6.6 |
|
53 /// "WAP AP Value Kind" column name. |
|
54 _LIT( KFavouritesDbApValueKindColName, "WapApValueKind" ); // 6.6 |
|
55 /// "Username" column name. |
|
56 _LIT( KFavouritesDbUserNameColName, "Username" ); // 6.6 |
|
57 /// "Password" column name. |
|
58 _LIT( KFavouritesDbPasswordColName, "Password" ); // 6.6 |
|
59 /// "Derived classes' extra data" column name. |
|
60 _LIT( KFavouritesDbExtraDataColName, "ExtraData" ); // 6.6 |
|
61 /// "Factory item" column name. |
|
62 _LIT( KFavouritesDbFactoryItemColName, "FactoryItem" ); // 6.6 |
|
63 /// "Read-only" column name. |
|
64 _LIT( KFavouritesDbReadOnlyColName, "ReadOnly" ); // 7.0 |
|
65 /// "ContextId" column name. |
|
66 _LIT( KFavouritesDbContextIdColName, "ContextId" ); // 7.0 |
|
67 /// "Modified" column name. |
|
68 _LIT( KFavouritesDbModifiedColName, "Modified" ); // 8.0 |
|
69 /// "Preferred Uid" column name. |
|
70 _LIT( KFavouritesDbPrefUidColName, "PrefUid" ); // 9.0 |
|
71 /// "Derived classes' extra data" column name. |
|
72 _LIT( KFavouritesDbBrowserDataColName, "BrowserData" ); // 10.0 |
|
73 |
|
74 _LIT( KFavouritesDbHiddenColName, "Hidden" ); // 11.0 |
|
75 // Index column names. |
|
76 |
|
77 /// "Index by Uid" column name. |
|
78 _LIT( KFavouritesDbUidIdxName, "UidIdx" ); |
|
79 |
|
80 // ================= LOCAL FUNCTIONS ======================= |
|
81 |
|
82 /** |
|
83 * Append escaped aLiteral to the end of aBuffer. This means appenging aLiteral, |
|
84 * with all '-s changed to ''-s. |
|
85 * @param aBuffer Buffer to append to. |
|
86 * @param aLiteral Literal to append escaped. |
|
87 */ |
|
88 LOCAL_C void AppendEscaped( TDes& aBuffer, const TDesC& aLiteral ) |
|
89 { |
|
90 TInt i; |
|
91 TUint quote('\''); // TChar gives warnings in THUMB & ARMI |
|
92 for ( i = 0; i < aLiteral.Length(); i++ ) |
|
93 { |
|
94 aBuffer.Append( aLiteral[i] ); |
|
95 if ( aLiteral[i] == quote ) |
|
96 { |
|
97 // Duplicate quote. |
|
98 aBuffer.Append( quote ); |
|
99 } |
|
100 } |
|
101 } |
|
102 |
|
103 // ================= MEMBER FUNCTIONS ======================= |
|
104 |
|
105 // --------------------------------------------------------- |
|
106 // RFavouritesSrvTable::OpenL |
|
107 // --------------------------------------------------------- |
|
108 // |
|
109 void RFavouritesSrvTable::OpenL |
|
110 ( |
|
111 RDbNamedDatabase& aDb, |
|
112 RDbRowSet::TAccess aAccess /*=RDbRowSet::EUpdatable*/ |
|
113 ) |
|
114 { |
|
115 iFiltering = EFalse; |
|
116 User::LeaveIfError( RDbTable::Open( aDb, KFavouritesTableName, aAccess ) ); |
|
117 CleanupClosePushL<RDbTable>( *this ); |
|
118 GetColumnNumbersL(); |
|
119 CleanupStack::Pop(); // closing this |
|
120 SetIndex( KFavouritesDbUidIdxName ); |
|
121 } |
|
122 |
|
123 // --------------------------------------------------------- |
|
124 // RFavouritesSrvTable::Close |
|
125 // --------------------------------------------------------- |
|
126 // |
|
127 void RFavouritesSrvTable::Close() |
|
128 { |
|
129 ClearFilters(); |
|
130 RDbTable::Close(); |
|
131 } |
|
132 |
|
133 // --------------------------------------------------------- |
|
134 // RFavouritesSrvTable::InsertLC |
|
135 // --------------------------------------------------------- |
|
136 // |
|
137 void RFavouritesSrvTable::InsertLC() |
|
138 { |
|
139 RDbTable::InsertL(); |
|
140 CleanupStack::PushL( TCleanupItem( StaticCancel, this ) ); |
|
141 } |
|
142 |
|
143 // --------------------------------------------------------- |
|
144 // RFavouritesSrvTable::UpdateLC |
|
145 // --------------------------------------------------------- |
|
146 // |
|
147 void RFavouritesSrvTable::UpdateLC() |
|
148 { |
|
149 RDbTable::UpdateL(); |
|
150 CleanupStack::PushL( TCleanupItem( StaticCancel, this ) ); |
|
151 } |
|
152 |
|
153 // --------------------------------------------------------- |
|
154 // RFavouritesSrvTable::PutL |
|
155 // --------------------------------------------------------- |
|
156 // |
|
157 void RFavouritesSrvTable::PutL( TBool aTouch /*=ETrue*/ ) |
|
158 { |
|
159 if ( aTouch ) |
|
160 { |
|
161 TTime now; |
|
162 now.UniversalTime(); |
|
163 SetModifiedL( now ); |
|
164 } |
|
165 RDbTable::PutL(); |
|
166 CleanupStack::Pop(); // StaticCancel, pushed by InsertLC or UpdateLC. |
|
167 } |
|
168 |
|
169 // --------------------------------------------------------- |
|
170 // RFavouritesSrvTable::Cancel |
|
171 // --------------------------------------------------------- |
|
172 // |
|
173 void RFavouritesSrvTable::Cancel() |
|
174 { |
|
175 // Any updates in this method must also be applied StaticCancel! |
|
176 RDbTable::Cancel(); |
|
177 CleanupStack::Pop(); // StaticCancel, pushed by InsertLC or UpdateLC. |
|
178 } |
|
179 |
|
180 // --------------------------------------------------------- |
|
181 // RFavouritesSrvTable::SetFiltersL |
|
182 // --------------------------------------------------------- |
|
183 // |
|
184 void RFavouritesSrvTable::SetFiltersL( const TFavouritesFilter& aFilter ) |
|
185 { |
|
186 HBufC* buf = HBufC::NewLC( KFavouritesMaxSql ); |
|
187 TPtr sql = buf->Des(); |
|
188 HBufC* tmpBuf = HBufC::NewLC( KFavouritesMaxSql ); |
|
189 TPtr tmpPtr = tmpBuf->Des(); |
|
190 _LIT( KNone, "" ); |
|
191 _LIT( KAnd, "and" ); |
|
192 TPtrC sConn; |
|
193 |
|
194 sConn.Set( KNone ); |
|
195 |
|
196 if ( aFilter.iName ) |
|
197 { |
|
198 // "name like 'foo*'" |
|
199 _LIT( KFormat1, "%S like '" ); |
|
200 sql.Format( KFormat1, &KFavouritesDbNameColName ); |
|
201 AppendEscaped( sql, *aFilter.iName ); |
|
202 sql.Append( TChar('\'') ); |
|
203 sConn.Set( KAnd ); |
|
204 } |
|
205 |
|
206 if ( aFilter.iType != CFavouritesItem::ENone ) |
|
207 { |
|
208 // "and type = 0" |
|
209 _LIT( KFormat2, " %S %S = %d" ); |
|
210 tmpPtr.Format |
|
211 ( KFormat2, &sConn, &KFavouritesDbTypeColName, aFilter.iType ); |
|
212 sConn.Set( KAnd ); |
|
213 sql.Append( tmpPtr ); |
|
214 } |
|
215 |
|
216 if ( aFilter.iParentFolder != KFavouritesNullUid ) |
|
217 { |
|
218 // "and parent = 7" |
|
219 _LIT( KFormat3, " %S %S = %d" ); |
|
220 tmpPtr.Format( KFormat3, |
|
221 &sConn, &KFavouritesDbParentColName, aFilter.iParentFolder ); |
|
222 sConn.Set( KAnd ); |
|
223 sql.Append( tmpPtr ); |
|
224 } |
|
225 |
|
226 if ( aFilter.iContextId != KFavouritesNullContextId ) |
|
227 { |
|
228 // "and contextid = 7" |
|
229 _LIT( KFormat3, " %S %S = %d" ); |
|
230 tmpPtr.Format( KFormat3, |
|
231 &sConn, &KFavouritesDbContextIdColName, aFilter.iContextId ); |
|
232 sConn.Set( KAnd ); |
|
233 sql.Append( tmpPtr ); |
|
234 } |
|
235 |
|
236 // Clear old one, if any. |
|
237 ClearFilters(); |
|
238 |
|
239 if ( sql.Length() > 0 ) |
|
240 { |
|
241 // Make new constraint, if there is any filter set. |
|
242 // Otherwise there will be no constraint. |
|
243 User::LeaveIfError |
|
244 ( iFilter.Open( *this, TDbQuery( sql, EDbCompareFolded ) ) ); |
|
245 iFiltering = ETrue; |
|
246 } |
|
247 |
|
248 CleanupStack::PopAndDestroy( 2 ); // tmpBuf, buf |
|
249 } |
|
250 |
|
251 // --------------------------------------------------------- |
|
252 // RFavouritesSrvTable::ClearFilters |
|
253 // --------------------------------------------------------- |
|
254 // |
|
255 void RFavouritesSrvTable::ClearFilters() |
|
256 { |
|
257 if ( iFiltering ) |
|
258 { |
|
259 iFilter.Close(); |
|
260 iFiltering = EFalse; |
|
261 } |
|
262 } |
|
263 |
|
264 // --------------------------------------------------------- |
|
265 // RFavouritesSrvTable::NextL |
|
266 // --------------------------------------------------------- |
|
267 // |
|
268 TBool RFavouritesSrvTable::NextL() |
|
269 { |
|
270 while ( RDbTable::NextL() ) |
|
271 { |
|
272 // Use the filters, if any. |
|
273 if ( !iFiltering || MatchL( iFilter ) ) |
|
274 { |
|
275 // We have a matching row. |
|
276 return ETrue; |
|
277 } |
|
278 } |
|
279 // No matching rows were found. |
|
280 return EFalse; |
|
281 } |
|
282 |
|
283 // --------------------------------------------------------- |
|
284 // RFavouritesSrvTable::SeekToUidL |
|
285 // --------------------------------------------------------- |
|
286 // |
|
287 TBool RFavouritesSrvTable::SeekToUidL( TInt aUid ) |
|
288 { |
|
289 return SeekL( TDbSeekKey( aUid ) ); |
|
290 } |
|
291 |
|
292 // --------------------------------------------------------- |
|
293 // RFavouritesSrvTable::GotoToUidL |
|
294 // --------------------------------------------------------- |
|
295 // |
|
296 void RFavouritesSrvTable::GotoToUidL( TInt aUid ) |
|
297 { |
|
298 if ( !SeekToUidL( aUid ) ) |
|
299 { |
|
300 User::Leave( KErrNotFound ); |
|
301 } |
|
302 } |
|
303 |
|
304 // --------------------------------------------------------- |
|
305 // RFavouritesSrvTable::ReadItemDataL |
|
306 // --------------------------------------------------------- |
|
307 // |
|
308 void RFavouritesSrvTable::ReadItemDataL( CFavouritesItemImpl& aItem ) const |
|
309 { |
|
310 // Fill standard attributes. |
|
311 aItem.SetUid( Uid() ); |
|
312 // No bookmark can exist with the Null Uid. |
|
313 __ASSERT_DEBUG( aItem.Uid() != KFavouritesNullUid, |
|
314 FavouritesPanic( EFavouritesNullUidInDatabase ) ); |
|
315 aItem.SetParentFolder( ParentFolder() ); |
|
316 aItem.SetType( Type() ); |
|
317 aItem.SetNameL( Name() ); |
|
318 HBufC* url = UrlLC(); |
|
319 aItem.SetUrlL( *url ); |
|
320 CleanupStack::PopAndDestroy(); // url |
|
321 aItem.SetUserNameL( Username() ); |
|
322 aItem.SetPasswordL( Password() ); |
|
323 aItem.SetWapAp( WapAp() ); |
|
324 aItem.SetFactoryItem( FactoryItem() ); |
|
325 aItem.SetReadOnly( ReadOnly() ); |
|
326 aItem.SetContextId( ContextId() ); |
|
327 aItem.SetModified( Modified() ); |
|
328 aItem.SetHidden( Hidden() ); |
|
329 } |
|
330 |
|
331 // --------------------------------------------------------- |
|
332 // RFavouritesSrvTable::Uid |
|
333 // --------------------------------------------------------- |
|
334 // |
|
335 TInt RFavouritesSrvTable::Uid() const |
|
336 { |
|
337 return ColInt( iColNoUid ); |
|
338 } |
|
339 |
|
340 // --------------------------------------------------------- |
|
341 // RFavouritesSrvTable::ParentFolder |
|
342 // --------------------------------------------------------- |
|
343 // |
|
344 TInt RFavouritesSrvTable::ParentFolder() const |
|
345 { |
|
346 return ColInt( iColNoParentFolder ); |
|
347 } |
|
348 |
|
349 // --------------------------------------------------------- |
|
350 // RFavouritesSrvTable::Type |
|
351 // --------------------------------------------------------- |
|
352 // |
|
353 CFavouritesItem::TType RFavouritesSrvTable::Type() const |
|
354 { |
|
355 return STATIC_CAST( CFavouritesItem::TType, ColInt32( iColNoType ) ); |
|
356 } |
|
357 |
|
358 // --------------------------------------------------------- |
|
359 // RFavouritesSrvTable::Name |
|
360 // --------------------------------------------------------- |
|
361 // |
|
362 TPtrC RFavouritesSrvTable::Name() const |
|
363 { |
|
364 return ColDes( iColNoName ); |
|
365 } |
|
366 |
|
367 // --------------------------------------------------------- |
|
368 // RFavouritesSrvTable::UrlLC |
|
369 // --------------------------------------------------------- |
|
370 // |
|
371 HBufC* RFavouritesSrvTable::UrlLC() const |
|
372 { |
|
373 // URL is long column. |
|
374 RDbColReadStream stream; |
|
375 TInt len = ColLength( iColNoUrl ); |
|
376 HBufC* buf = HBufC::NewLC( len ); |
|
377 if ( len ) |
|
378 { |
|
379 stream.OpenLC( *this, iColNoUrl ); |
|
380 TPtr ptr = buf->Des(); |
|
381 stream.ReadL( ptr, len ); |
|
382 CleanupStack::PopAndDestroy(); // Close stream |
|
383 } |
|
384 return buf; |
|
385 } |
|
386 |
|
387 // --------------------------------------------------------- |
|
388 // RFavouritesSrvTable::WapAp |
|
389 // --------------------------------------------------------- |
|
390 // |
|
391 TFavouritesWapAp RFavouritesSrvTable::WapAp() const |
|
392 { |
|
393 TFavouritesWapAp wapAp; |
|
394 wapAp.iApId = ColUint32 ( iColNoWapApId ); |
|
395 wapAp.iValueKind = STATIC_CAST |
|
396 ( TFavouritesWapAp::TValueKind, ColInt ( iColNoWapApValueKind ) ); |
|
397 return wapAp; |
|
398 } |
|
399 |
|
400 // --------------------------------------------------------- |
|
401 // RFavouritesSrvTable::Username |
|
402 // --------------------------------------------------------- |
|
403 // |
|
404 TPtrC RFavouritesSrvTable::Username() const |
|
405 { |
|
406 return ColDes( iColNoUserName ); |
|
407 } |
|
408 |
|
409 // --------------------------------------------------------- |
|
410 // RFavouritesSrvTable::Password |
|
411 // --------------------------------------------------------- |
|
412 // |
|
413 TPtrC RFavouritesSrvTable::Password() const |
|
414 { |
|
415 return ColDes( iColNoPassword ); |
|
416 } |
|
417 |
|
418 // --------------------------------------------------------- |
|
419 // RFavouritesSrvTable::GetExtraDataL |
|
420 // --------------------------------------------------------- |
|
421 // |
|
422 void RFavouritesSrvTable::GetExtraDataL( MStreamBuf& aSink ) |
|
423 { |
|
424 RDbColReadStream rs; |
|
425 rs.OpenLC( *this, iColNoExtraData ); |
|
426 RWriteStream ws( &aSink ); |
|
427 rs.ReadL( ws ); |
|
428 CleanupStack::PopAndDestroy(); // Close rs |
|
429 } |
|
430 |
|
431 // --------------------------------------------------------- |
|
432 // RFavouritesSrvTable::GetBrowserDataL |
|
433 // --------------------------------------------------------- |
|
434 // |
|
435 void RFavouritesSrvTable::GetBrowserDataL( MStreamBuf& aSink ) |
|
436 { |
|
437 if ( iColNoBrowserData != KDbNullColNo ) |
|
438 { |
|
439 RDbColReadStream rs; |
|
440 rs.OpenLC( *this, iColNoBrowserData ); |
|
441 RWriteStream ws( &aSink ); |
|
442 rs.ReadL( ws ); |
|
443 CleanupStack::PopAndDestroy(); // Close rs |
|
444 } |
|
445 } |
|
446 |
|
447 // --------------------------------------------------------- |
|
448 // RFavouritesSrvTable::FactoryItem |
|
449 // --------------------------------------------------------- |
|
450 // |
|
451 TBool RFavouritesSrvTable::FactoryItem() const |
|
452 { |
|
453 return ColInt( iColNoFactoryItem ); |
|
454 } |
|
455 |
|
456 // --------------------------------------------------------- |
|
457 // RFavouritesSrvTable::ReadOnly |
|
458 // --------------------------------------------------------- |
|
459 // |
|
460 TBool RFavouritesSrvTable::ReadOnly() const |
|
461 { |
|
462 return ColInt( iColNoReadOnly ); |
|
463 } |
|
464 |
|
465 // --------------------------------------------------------- |
|
466 // RFavouritesSrvTable::ContextId |
|
467 // --------------------------------------------------------- |
|
468 // |
|
469 TInt32 RFavouritesSrvTable::ContextId() const |
|
470 { |
|
471 return ColInt32( iColNoContextId ); |
|
472 } |
|
473 |
|
474 // --------------------------------------------------------- |
|
475 // RFavouritesSrvTable::Modified |
|
476 // --------------------------------------------------------- |
|
477 // |
|
478 TTime RFavouritesSrvTable::Modified() const |
|
479 { |
|
480 TTime modified( 0 ); |
|
481 if ( iColNoModified != KDbNullColNo ) |
|
482 { |
|
483 modified = ColTime( iColNoModified ); |
|
484 } |
|
485 return modified; |
|
486 } |
|
487 |
|
488 // --------------------------------------------------------- |
|
489 // RFavouritesSrvTable::PreferredUid |
|
490 // --------------------------------------------------------- |
|
491 // |
|
492 TInt RFavouritesSrvTable::PreferredUid() const |
|
493 { |
|
494 TInt preferredUid( KFavouritesNullUid ); |
|
495 if ( iColNoPreferredUid != KDbNullColNo ) |
|
496 { |
|
497 preferredUid = ColInt( iColNoPreferredUid ); |
|
498 } |
|
499 return preferredUid; |
|
500 } |
|
501 |
|
502 |
|
503 // --------------------------------------------------------- |
|
504 // RFavouritesSrvTable::Hidden |
|
505 // --------------------------------------------------------- |
|
506 // |
|
507 TBool RFavouritesSrvTable::Hidden() const |
|
508 { |
|
509 return ColInt( iColNoHidden ); |
|
510 } |
|
511 |
|
512 // --------------------------------------------------------- |
|
513 // RFavouritesSrvTable::WriteItemDataL |
|
514 // --------------------------------------------------------- |
|
515 // |
|
516 void RFavouritesSrvTable::WriteItemDataL( const CFavouritesItemImpl& aItem ) |
|
517 { |
|
518 // Fill standard attributes. |
|
519 __ASSERT_DEBUG( !ReadOnly(), FavouritesPanic( EFavouritesInternal ) ); |
|
520 // Uid is *NOT* set. We update the current row. |
|
521 SetParentFolderL( aItem.ParentFolder() ); |
|
522 SetTypeL( aItem.Type() ); |
|
523 SetNameL( aItem.Name() ); |
|
524 SetUrlL( aItem.Url() ); |
|
525 SetUsernameL( aItem.UserName() ); |
|
526 SetPasswordL( aItem.Password() ); |
|
527 SetWapApL( aItem.WapAp() ); |
|
528 // Note: read-only flag is *NOT* set. Setting that is accessible via |
|
529 // SetReadOnlyL. |
|
530 // Note: factory item flag is *NOT* set. Setting that is accessible via |
|
531 // SetFactoryItemL. |
|
532 SetContextIdL( aItem.ContextId() ); |
|
533 // Note: last modification time is *NOT* set; PutL will do it. |
|
534 // Manual setting (override) is accessible via SetModifiedL. |
|
535 SetHiddenL( aItem.IsHidden() ); |
|
536 } |
|
537 |
|
538 // --------------------------------------------------------- |
|
539 // RFavouritesSrvTable::SetUidL |
|
540 // --------------------------------------------------------- |
|
541 // |
|
542 void RFavouritesSrvTable::SetUidL( TInt aUid ) |
|
543 { |
|
544 SetColL( iColNoUid, aUid ); |
|
545 } |
|
546 |
|
547 // --------------------------------------------------------- |
|
548 // RFavouritesSrvTable::SetParentFolderL |
|
549 // --------------------------------------------------------- |
|
550 // |
|
551 void RFavouritesSrvTable::SetParentFolderL( TInt aUid ) |
|
552 { |
|
553 SetColL( iColNoParentFolder, aUid ); |
|
554 } |
|
555 |
|
556 // --------------------------------------------------------- |
|
557 // RFavouritesSrvTable::SetTypeL |
|
558 // --------------------------------------------------------- |
|
559 // |
|
560 void RFavouritesSrvTable::SetTypeL( CFavouritesItem::TType aType ) |
|
561 { |
|
562 SetColL( iColNoType, STATIC_CAST( TInt, aType ) ); |
|
563 } |
|
564 |
|
565 // --------------------------------------------------------- |
|
566 // RFavouritesSrvTable::SetNameL |
|
567 // --------------------------------------------------------- |
|
568 // |
|
569 void RFavouritesSrvTable::SetNameL( const TDesC& aName ) |
|
570 { |
|
571 SetColL( iColNoName, aName ); |
|
572 } |
|
573 |
|
574 // --------------------------------------------------------- |
|
575 // RFavouritesSrvTable::SetUrlL |
|
576 // --------------------------------------------------------- |
|
577 // |
|
578 void RFavouritesSrvTable::SetUrlL( const TDesC& aUrl ) |
|
579 { |
|
580 RDbColWriteStream stream; |
|
581 stream.OpenLC( *this, iColNoUrl ); |
|
582 stream.WriteL( aUrl, aUrl.Length() ); |
|
583 stream.CommitL(); |
|
584 CleanupStack::PopAndDestroy(); // stream; |
|
585 } |
|
586 |
|
587 // --------------------------------------------------------- |
|
588 // RFavouritesSrvTable::SetWapApL |
|
589 // --------------------------------------------------------- |
|
590 // |
|
591 void RFavouritesSrvTable::SetWapApL( const TFavouritesWapAp& aWapAp ) |
|
592 { |
|
593 SetColL( iColNoWapApId, aWapAp.iApId ); |
|
594 SetColL( iColNoWapApValueKind, |
|
595 STATIC_CAST( TInt, aWapAp.iValueKind ) ); |
|
596 } |
|
597 |
|
598 // --------------------------------------------------------- |
|
599 // RFavouritesSrvTable::SetUsernameL |
|
600 // --------------------------------------------------------- |
|
601 // |
|
602 void RFavouritesSrvTable::SetUsernameL( const TDesC& aUsername ) |
|
603 { |
|
604 SetColL( iColNoUserName, aUsername ); |
|
605 } |
|
606 |
|
607 // --------------------------------------------------------- |
|
608 // RFavouritesSrvTable::SetPasswordL |
|
609 // --------------------------------------------------------- |
|
610 // |
|
611 void RFavouritesSrvTable::SetPasswordL( const TDesC& aPassword ) |
|
612 { |
|
613 SetColL( iColNoPassword, aPassword ); |
|
614 } |
|
615 |
|
616 // --------------------------------------------------------- |
|
617 // RFavouritesSrvTable::SetExtraDataL |
|
618 // --------------------------------------------------------- |
|
619 // |
|
620 void RFavouritesSrvTable::SetExtraDataL( MStreamBuf& aSource ) |
|
621 { |
|
622 RDbColWriteStream ws; |
|
623 ws.OpenLC( *this, iColNoExtraData ); |
|
624 RReadStream rs( &aSource ); |
|
625 ws.WriteL( rs ); |
|
626 ws.CommitL(); |
|
627 CleanupStack::PopAndDestroy(); // Close ws |
|
628 } |
|
629 |
|
630 // --------------------------------------------------------- |
|
631 // RFavouritesSrvTable::SetBrowserDataL |
|
632 // --------------------------------------------------------- |
|
633 // |
|
634 void RFavouritesSrvTable::SetBrowserDataL( MStreamBuf& aSource ) |
|
635 { |
|
636 if ( iColNoBrowserData != KDbNullColNo ) |
|
637 { |
|
638 RDbColWriteStream ws; |
|
639 ws.OpenLC( *this, iColNoBrowserData ); |
|
640 RReadStream rs( &aSource ); |
|
641 ws.WriteL( rs ); |
|
642 ws.CommitL(); |
|
643 CleanupStack::PopAndDestroy(); // Close ws |
|
644 } |
|
645 } |
|
646 |
|
647 // --------------------------------------------------------- |
|
648 // RFavouritesSrvTable::SetFactoryItemL |
|
649 // --------------------------------------------------------- |
|
650 // |
|
651 void RFavouritesSrvTable::SetFactoryItemL( TBool aFactoryItem ) |
|
652 { |
|
653 SetColL( iColNoFactoryItem, aFactoryItem ); |
|
654 } |
|
655 |
|
656 // --------------------------------------------------------- |
|
657 // RFavouritesSrvTable::SetReadOnlyL |
|
658 // --------------------------------------------------------- |
|
659 // |
|
660 void RFavouritesSrvTable::SetReadOnlyL( TBool aReadOnly ) |
|
661 { |
|
662 SetColL( iColNoReadOnly, aReadOnly ); |
|
663 } |
|
664 |
|
665 // --------------------------------------------------------- |
|
666 // RFavouritesSrvTable::SetContextIdL |
|
667 // --------------------------------------------------------- |
|
668 // |
|
669 void RFavouritesSrvTable::SetContextIdL( TInt32 aContextId ) |
|
670 { |
|
671 SetColL( iColNoContextId, aContextId ); |
|
672 } |
|
673 |
|
674 // --------------------------------------------------------- |
|
675 // RFavouritesSrvTable::SetModifiedL |
|
676 // --------------------------------------------------------- |
|
677 // |
|
678 void RFavouritesSrvTable::SetModifiedL( TTime aModified ) |
|
679 { |
|
680 if ( iColNoModified != KDbNullColNo ) |
|
681 { |
|
682 SetColL( iColNoModified, aModified ); |
|
683 } |
|
684 } |
|
685 |
|
686 // --------------------------------------------------------- |
|
687 // RFavouritesSrvTable::SetPreferredUidL |
|
688 // --------------------------------------------------------- |
|
689 // |
|
690 void RFavouritesSrvTable::SetPreferredUidL( TInt aUid ) |
|
691 { |
|
692 if ( iColNoPreferredUid != KDbNullColNo ) |
|
693 { |
|
694 SetColL( iColNoPreferredUid, aUid ); |
|
695 } |
|
696 } |
|
697 |
|
698 // --------------------------------------------------------- |
|
699 // RFavouritesSrvTable::SetHiddenL |
|
700 // --------------------------------------------------------- |
|
701 // |
|
702 void RFavouritesSrvTable::SetHiddenL( TBool aHidden ) |
|
703 { |
|
704 SetColL( iColNoHidden, aHidden ); |
|
705 } |
|
706 |
|
707 // --------------------------------------------------------- |
|
708 // RFavouritesSrvTable::PutWriteLockL |
|
709 // --------------------------------------------------------- |
|
710 // |
|
711 void RFavouritesSrvTable::PutWriteLockL() |
|
712 { |
|
713 // Insert will get write-lock if possible, or leave if not. |
|
714 InsertLC(); |
|
715 Cancel(); |
|
716 } |
|
717 |
|
718 // --------------------------------------------------------- |
|
719 // RFavouritesSrvTable::CreateStructureL |
|
720 // --------------------------------------------------------- |
|
721 // |
|
722 void RFavouritesSrvTable::CreateStructureL( RDbNamedDatabase& aDb ) |
|
723 { |
|
724 // Create columns. |
|
725 CDbColSet* colset = CDbColSet::NewLC(); |
|
726 |
|
727 TDbCol col( KFavouritesDbUidColName, EDbColInt32 ); |
|
728 col.iAttributes = TDbCol::EAutoIncrement; |
|
729 colset->AddL( col ); |
|
730 colset->AddL( TDbCol( KFavouritesDbParentColName, EDbColInt32 ) ); |
|
731 colset->AddL( TDbCol( KFavouritesDbTypeColName, EDbColInt32 ) ); |
|
732 colset->AddL( TDbCol |
|
733 ( KFavouritesDbNameColName, EDbColText, KFavouritesMaxName ) ); |
|
734 colset->AddL( TDbCol |
|
735 ( KFavouritesDbUrlColName, EDbColLongText, KFavouritesMaxUrl ) ); |
|
736 colset->AddL( TDbCol( KFavouritesDbApIdColName, EDbColUint32 ) ); |
|
737 colset->AddL( TDbCol( KFavouritesDbApValueKindColName, EDbColInt32 ) ); |
|
738 colset->AddL( TDbCol |
|
739 ( KFavouritesDbUserNameColName, EDbColText, KFavouritesMaxUserName ) ); |
|
740 colset->AddL( TDbCol |
|
741 ( KFavouritesDbPasswordColName, EDbColText, KFavouritesMaxPassword ) ); |
|
742 colset->AddL( TDbCol( KFavouritesDbExtraDataColName, EDbColLongBinary ) ); |
|
743 colset->AddL( TDbCol( KFavouritesDbFactoryItemColName, EDbColBit ) ); |
|
744 colset->AddL( TDbCol( KFavouritesDbReadOnlyColName, EDbColBit ) ); |
|
745 colset->AddL( TDbCol( KFavouritesDbContextIdColName, EDbColInt32 ) ); |
|
746 colset->AddL( TDbCol( KFavouritesDbModifiedColName, EDbColDateTime ) ); |
|
747 colset->AddL( TDbCol( KFavouritesDbPrefUidColName, EDbColInt32 ) ); |
|
748 colset->AddL |
|
749 ( TDbCol( KFavouritesDbBrowserDataColName, EDbColLongBinary ) ); |
|
750 colset->AddL( TDbCol( KFavouritesDbHiddenColName, EDbColBit ) ); |
|
751 User::LeaveIfError |
|
752 ( aDb.CreateTable( KFavouritesTableName, *colset ) ); |
|
753 CleanupStack::PopAndDestroy(); // colset |
|
754 |
|
755 // Create index by uid. |
|
756 CDbKey* key = CDbKey::NewLC(); |
|
757 // Create key on Uid column, ascending order. |
|
758 key->AddL( TDbKeyCol ( KFavouritesDbUidColName ) ); |
|
759 User::LeaveIfError( aDb.CreateIndex |
|
760 ( KFavouritesDbUidIdxName, KFavouritesTableName, *key ) ); |
|
761 CleanupStack::PopAndDestroy(); // key |
|
762 } |
|
763 |
|
764 // --------------------------------------------------------- |
|
765 // RFavouritesSrvTable::VerifyStructureL |
|
766 // --------------------------------------------------------- |
|
767 // |
|
768 void RFavouritesSrvTable::VerifyStructureL |
|
769 ( RDbNamedDatabase& aDb, TBool aUpgrade ) |
|
770 { |
|
771 CDbColSet* colset = aDb.ColSetL( KFavouritesTableName ); |
|
772 CleanupStack::PushL( colset ); |
|
773 |
|
774 if ( |
|
775 colset->ColNo( KFavouritesDbUidColName ) == KDbNullColNo || |
|
776 colset->ColNo( KFavouritesDbParentColName ) == KDbNullColNo || |
|
777 colset->ColNo( KFavouritesDbTypeColName ) == KDbNullColNo || |
|
778 colset->ColNo( KFavouritesDbNameColName ) == KDbNullColNo || |
|
779 colset->ColNo( KFavouritesDbUrlColName ) == KDbNullColNo || |
|
780 colset->ColNo( KFavouritesDbUserNameColName ) == KDbNullColNo || |
|
781 colset->ColNo( KFavouritesDbPasswordColName ) == KDbNullColNo || |
|
782 colset->ColNo( KFavouritesDbApIdColName ) == KDbNullColNo || |
|
783 colset->ColNo( KFavouritesDbApValueKindColName ) == KDbNullColNo || |
|
784 colset->ColNo( KFavouritesDbExtraDataColName ) == KDbNullColNo || |
|
785 colset->ColNo( KFavouritesDbFactoryItemColName ) == KDbNullColNo || |
|
786 colset->ColNo( KFavouritesDbReadOnlyColName ) == KDbNullColNo || |
|
787 colset->ColNo( KFavouritesDbContextIdColName ) == KDbNullColNo |
|
788 ) |
|
789 { |
|
790 // Mandatory column is missing, this database is corrupt. |
|
791 User::Leave( KErrCorrupt ); |
|
792 } |
|
793 |
|
794 if ( aUpgrade ) |
|
795 { |
|
796 // Check optional columns, upgrade if necessary. |
|
797 // If upgrade is not possible, we don't even check those; as the |
|
798 // database is still functional without them. |
|
799 |
|
800 TInt missingCols( EFalse ); |
|
801 |
|
802 if ( colset->ColNo( KFavouritesDbModifiedColName ) == KDbNullColNo ) |
|
803 { |
|
804 // Last modification column is missing. |
|
805 colset->AddL( TDbCol |
|
806 ( KFavouritesDbModifiedColName, EDbColDateTime ) ); |
|
807 missingCols = ETrue; |
|
808 } |
|
809 |
|
810 if ( colset->ColNo( KFavouritesDbPrefUidColName ) == KDbNullColNo ) |
|
811 { |
|
812 // Preferred uid column is missing. |
|
813 colset->AddL( TDbCol( KFavouritesDbPrefUidColName, EDbColInt32 ) ); |
|
814 missingCols = ETrue; |
|
815 } |
|
816 |
|
817 if ( colset->ColNo( KFavouritesDbBrowserDataColName ) == KDbNullColNo ) |
|
818 { |
|
819 // Preferred uid column is missing. |
|
820 colset->AddL |
|
821 ( TDbCol( KFavouritesDbBrowserDataColName, EDbColLongBinary ) ); |
|
822 missingCols = ETrue; |
|
823 } |
|
824 if( colset->ColNo( KFavouritesDbHiddenColName) == KDbNullColNo ) |
|
825 { |
|
826 // Preferred uid column is missing. |
|
827 colset->AddL |
|
828 ( TDbCol( KFavouritesDbHiddenColName, EDbColBit ) ); |
|
829 missingCols = ETrue; |
|
830 } |
|
831 |
|
832 if ( missingCols ) |
|
833 { |
|
834 // Some columns are missing, try to add them now. |
|
835 // Upgrade error is ignored, database is still functional (except |
|
836 // of course the missing columns). |
|
837 (void)aDb.AlterTable( KFavouritesTableName, *colset ); |
|
838 } |
|
839 } |
|
840 |
|
841 CleanupStack::PopAndDestroy(); // colset |
|
842 } |
|
843 |
|
844 // --------------------------------------------------------- |
|
845 // RFavouritesSrvTable::GetColumnNumbersL |
|
846 // --------------------------------------------------------- |
|
847 // |
|
848 void RFavouritesSrvTable::GetColumnNumbersL() |
|
849 { |
|
850 CDbColSet* colset = ColSetL(); |
|
851 CleanupStack::PushL( colset ); |
|
852 |
|
853 iColNoUid = colset->ColNo( KFavouritesDbUidColName ); |
|
854 iColNoParentFolder = colset->ColNo( KFavouritesDbParentColName ); |
|
855 iColNoType = colset->ColNo( KFavouritesDbTypeColName ); |
|
856 iColNoName = colset->ColNo( KFavouritesDbNameColName ); |
|
857 iColNoUrl = colset->ColNo( KFavouritesDbUrlColName ); |
|
858 iColNoUserName = colset->ColNo( KFavouritesDbUserNameColName ); |
|
859 iColNoPassword = colset->ColNo( KFavouritesDbPasswordColName ); |
|
860 iColNoWapApId = colset->ColNo( KFavouritesDbApIdColName ); |
|
861 iColNoWapApValueKind = colset->ColNo( KFavouritesDbApValueKindColName ); |
|
862 iColNoExtraData = colset->ColNo( KFavouritesDbExtraDataColName ); |
|
863 iColNoFactoryItem = colset->ColNo( KFavouritesDbFactoryItemColName ); |
|
864 iColNoReadOnly = colset->ColNo( KFavouritesDbReadOnlyColName ); |
|
865 iColNoContextId = colset->ColNo( KFavouritesDbContextIdColName ); |
|
866 iColNoModified = colset->ColNo( KFavouritesDbModifiedColName ); |
|
867 iColNoPreferredUid = colset->ColNo( KFavouritesDbPrefUidColName ); |
|
868 iColNoBrowserData = colset->ColNo( KFavouritesDbBrowserDataColName ); |
|
869 iColNoHidden = colset->ColNo( KFavouritesDbHiddenColName ); |
|
870 |
|
871 CleanupStack::PopAndDestroy(); // colset |
|
872 } |
|
873 |
|
874 // --------------------------------------------------------- |
|
875 // RFavouritesSrvTable::StaticCancel |
|
876 // --------------------------------------------------------- |
|
877 // |
|
878 void RFavouritesSrvTable::StaticCancel( TAny* aTable ) |
|
879 { |
|
880 // Same as Cancel; except it does not pop the cleanup item; because |
|
881 // it is called as part of leave processing. |
|
882 // Any updates in this method must also be applied Cancel! |
|
883 RFavouritesSrvTable* table = STATIC_CAST( RFavouritesSrvTable*, aTable ); |
|
884 table->RDbTable::Cancel(); |
|
885 } |
|
886 |
|
887 // End of File |