85
|
1 |
/*
|
|
2 |
* Copyright (c) 2008 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 |
*
|
|
16 |
*/
|
86
|
17 |
#include "casqlitestorage.h"
|
85
|
18 |
#include "caconsts.h"
|
|
19 |
#include "casqlcommands.h"
|
|
20 |
#include "casqlquery.h"
|
|
21 |
#include "casqlquerycreator.h"
|
|
22 |
#include "cainnerentry.h"
|
|
23 |
#include "cainnerquery.h"
|
|
24 |
#include "caarraycleanup.inl"
|
|
25 |
#include "calocalizationentry.h"
|
88
|
26 |
#include "cainternaltypes.h"
|
89
|
27 |
#include "cadef.h"
|
85
|
28 |
|
|
29 |
// ---------------------------------------------------------------------------
|
|
30 |
// CCASqLiteStorage::CCpStorageEngine()
|
|
31 |
//
|
|
32 |
// ---------------------------------------------------------------------------
|
|
33 |
//
|
|
34 |
CCaSqLiteStorage::CCaSqLiteStorage()
|
|
35 |
{
|
|
36 |
}
|
|
37 |
|
|
38 |
// ---------------------------------------------------------------------------
|
|
39 |
// CCASqLiteStorage::ConstructL()
|
|
40 |
//
|
|
41 |
// ---------------------------------------------------------------------------
|
|
42 |
//
|
|
43 |
void CCaSqLiteStorage::ConstructL()
|
|
44 |
{
|
86
|
45 |
User::LeaveIfError( iRfs.Connect() );
|
85
|
46 |
|
127
|
47 |
User::LeaveIfError(
|
|
48 |
CreatePrivateDirPath( iPrivatePathCDriveDb, KCDrive, KDbName ) );
|
|
49 |
User::LeaveIfError(
|
|
50 |
CreatePrivateDirPath( iPrivatePathZDriveDb, KZDrive, KDbName ) );
|
|
51 |
User::LeaveIfError(
|
|
52 |
CreatePrivateDirPath( iPrivatePathCDrive, KCDrive, KNullDesC ) );
|
|
53 |
User::LeaveIfError(
|
|
54 |
CreatePrivateDirPath(
|
|
55 |
iPrivatePathCDriveDbBackup, KCDrive, KDbNameBackup ) );
|
85
|
56 |
|
86
|
57 |
if( iSqlDb.Open( iPrivatePathCDriveDb, &KSqlDbConfig ) )
|
85
|
58 |
{
|
86
|
59 |
//we could not load data base from C-drive lets try Rom
|
|
60 |
LoadDataBaseFromRomL();
|
|
61 |
}
|
89
|
62 |
else
|
|
63 |
{
|
|
64 |
TBuf<KCaMaxAttrNameLen> versionValue;
|
127
|
65 |
DbPropertyL( KCaDbPropVersion, versionValue );
|
|
66 |
ASSERT( versionValue.Length() > 0 );
|
89
|
67 |
if( versionValue.CompareC( KCaDbVersion ) )
|
|
68 |
{
|
|
69 |
// database loaded from C: is obsolete, load from Z:
|
|
70 |
iSqlDb.Close();
|
|
71 |
LoadDataBaseFromRomL();
|
|
72 |
}
|
|
73 |
}
|
127
|
74 |
TBuf<KCaMaxAttrNameLen> restoreValue;
|
|
75 |
DbPropertyL( KCaDbPropRestore, restoreValue );
|
|
76 |
if( restoreValue.CompareC( KCaDbPropRestoreVal ) == KErrNone )
|
|
77 |
{
|
|
78 |
RestoreDatabaseL();
|
|
79 |
}
|
|
80 |
}
|
|
81 |
|
|
82 |
// ---------------------------------------------------------------------------
|
|
83 |
// CCASqLiteStorage::GetDownloadedApplicationsArrayL()
|
|
84 |
//
|
|
85 |
// ---------------------------------------------------------------------------
|
|
86 |
//
|
|
87 |
void CCaSqLiteStorage::GetDownloadedApplicationsArrayL(
|
|
88 |
RPointerArray<CCaInnerEntry>& aResultArray )
|
|
89 |
{
|
|
90 |
iCollectionDownloadId = GetCollectionDownloadIdL();
|
|
91 |
CCaInnerQuery* downloadedQuery = CCaInnerQuery::NewLC();
|
|
92 |
downloadedQuery->SetParentId( iCollectionDownloadId );
|
|
93 |
GetEntriesL( downloadedQuery, aResultArray );
|
|
94 |
CleanupStack::PopAndDestroy( downloadedQuery );
|
|
95 |
}
|
|
96 |
|
|
97 |
// ---------------------------------------------------------------------------
|
|
98 |
// CCASqLiteStorage::GetDownloadedApplicationsArrayL()
|
|
99 |
//
|
|
100 |
// ---------------------------------------------------------------------------
|
|
101 |
//
|
|
102 |
void CCaSqLiteStorage::GetDownloadedApplicationsArrayL(
|
|
103 |
RArray<TInt>& aResultArray )
|
|
104 |
{
|
|
105 |
iCollectionDownloadId = GetCollectionDownloadIdL();
|
|
106 |
CCaInnerQuery* downloadedQuery = CCaInnerQuery::NewLC();
|
|
107 |
downloadedQuery->SetParentId( iCollectionDownloadId );
|
|
108 |
GetEntriesIdsL( downloadedQuery, aResultArray );
|
|
109 |
CleanupStack::PopAndDestroy( downloadedQuery );
|
|
110 |
}
|
|
111 |
|
|
112 |
// ---------------------------------------------------------------------------
|
|
113 |
// CCASqLiteStorage::RestoreDownloadedApplications()
|
|
114 |
//
|
|
115 |
// ---------------------------------------------------------------------------
|
|
116 |
//
|
|
117 |
void CCaSqLiteStorage::SetDownloadedApplicationsArrayL(
|
|
118 |
RPointerArray<CCaInnerEntry>& aResultArray )
|
|
119 |
{
|
|
120 |
//remove all entries from downloaded collection
|
|
121 |
RArray<TInt> entryIds;
|
|
122 |
CleanupClosePushL( entryIds );
|
|
123 |
GetDownloadedApplicationsArrayL( entryIds );
|
|
124 |
|
|
125 |
TCaOperationParams params;
|
|
126 |
params.iOperationType = TCaOperationParams::ERemove;
|
|
127 |
params.iGroupId = iCollectionDownloadId;
|
|
128 |
params.iBeforeEntryId = 0; // Not Used
|
|
129 |
ExecuteOrganizeL( entryIds, params );
|
|
130 |
CleanupStack::PopAndDestroy( &entryIds );
|
|
131 |
|
|
132 |
//get current downloaded applications list
|
|
133 |
for( TInt i = aResultArray.Count() - 1; i >= 0; i-- )
|
|
134 |
{
|
|
135 |
CCaInnerQuery* downloadedQuery = CCaInnerQuery::NewLC();
|
|
136 |
RArray<TInt> entryIds;
|
|
137 |
CleanupClosePushL( entryIds );
|
|
138 |
entryIds.AppendL( aResultArray[i]->GetId() );
|
|
139 |
downloadedQuery->SetIdsL( entryIds );
|
|
140 |
|
|
141 |
RArray<TInt> resultEntryIds;
|
|
142 |
CleanupClosePushL( resultEntryIds );
|
|
143 |
GetEntriesIdsL( downloadedQuery, resultEntryIds );
|
|
144 |
if( !resultEntryIds.Count() )
|
|
145 |
{
|
|
146 |
//its in case of application that was installed after backup
|
|
147 |
aResultArray[i]->SetId(0);
|
|
148 |
}
|
|
149 |
//there could be some icon added to db aster backup
|
|
150 |
//( after update or installation of applicatiotion )
|
|
151 |
aResultArray[i]->SetIconId(0);
|
|
152 |
|
|
153 |
CleanupStack::PopAndDestroy( &resultEntryIds );
|
|
154 |
CleanupStack::PopAndDestroy( &entryIds );
|
|
155 |
CleanupStack::PopAndDestroy( downloadedQuery );
|
|
156 |
}
|
|
157 |
|
|
158 |
//add applications to downloaded collection
|
|
159 |
for( TInt i = 0; i < aResultArray.Count(); i++ )
|
|
160 |
{
|
|
161 |
AddL( aResultArray[i] );
|
|
162 |
}
|
|
163 |
params.iOperationType = TCaOperationParams::EAppend;
|
|
164 |
ExecuteOrganizeL( aResultArray, params );
|
|
165 |
}
|
|
166 |
|
|
167 |
// ---------------------------------------------------------
|
|
168 |
//
|
|
169 |
// ---------------------------------------------------------
|
|
170 |
//
|
|
171 |
void CCaSqLiteStorage::ExecuteOrganizeL(
|
|
172 |
const RPointerArray<CCaInnerEntry> & aResultArray,
|
|
173 |
TCaOperationParams params)
|
|
174 |
{
|
|
175 |
RArray<TInt> restoredEntryIds;
|
|
176 |
CleanupClosePushL(restoredEntryIds);
|
|
177 |
for( TInt i = 0; i < aResultArray.Count(); i++ )
|
|
178 |
{
|
|
179 |
restoredEntryIds.AppendL( aResultArray[i]->GetId() );
|
|
180 |
}
|
|
181 |
ExecuteOrganizeL( restoredEntryIds, params );
|
|
182 |
CleanupStack::PopAndDestroy( &restoredEntryIds );
|
|
183 |
}
|
|
184 |
|
|
185 |
// ---------------------------------------------------------
|
|
186 |
//
|
|
187 |
// ---------------------------------------------------------
|
|
188 |
//
|
|
189 |
TInt CCaSqLiteStorage::GetCollectionDownloadIdL()
|
|
190 |
{
|
|
191 |
TInt downloadId( KErrNotFound );
|
|
192 |
RPointerArray<CCaInnerEntry> resultArray;
|
|
193 |
CleanupResetAndDestroyPushL( resultArray );
|
|
194 |
CCaInnerQuery* allAppQuery = CCaInnerQuery::NewLC();
|
|
195 |
CDesC16ArrayFlat* appType =
|
|
196 |
new ( ELeave ) CDesC16ArrayFlat( KGranularityOne );
|
|
197 |
CleanupStack::PushL( appType );
|
|
198 |
appType->AppendL( KCaTypeCollectionDownload );
|
|
199 |
allAppQuery->SetEntryTypeNames( appType );
|
|
200 |
CleanupStack::Pop( appType );
|
|
201 |
GetEntriesL( allAppQuery, resultArray );
|
|
202 |
CleanupStack::PopAndDestroy( allAppQuery );
|
|
203 |
if( resultArray.Count() )
|
|
204 |
{
|
|
205 |
downloadId = resultArray[0]->GetId();
|
|
206 |
}
|
|
207 |
CleanupStack::PopAndDestroy( &resultArray );
|
|
208 |
return downloadId;
|
86
|
209 |
}
|
85
|
210 |
|
86
|
211 |
// ---------------------------------------------------------------------------
|
|
212 |
// CCASqLiteStorage::NewL()
|
|
213 |
//
|
|
214 |
// ---------------------------------------------------------------------------
|
|
215 |
//
|
|
216 |
void CCaSqLiteStorage::LoadDataBaseFromRomL()
|
|
217 |
{
|
|
218 |
if( ( BaflUtils::FileExists( iRfs, iPrivatePathCDriveDb ) ) )
|
|
219 |
{
|
|
220 |
iSqlDb.Close();
|
|
221 |
User::LeaveIfError( BaflUtils::DeleteFile( iRfs,
|
|
222 |
iPrivatePathCDriveDb ) );
|
85
|
223 |
}
|
|
224 |
|
86
|
225 |
if( !( BaflUtils::FileExists( iRfs, iPrivatePathZDriveDb ) ) )
|
|
226 |
{
|
89
|
227 |
User::Panic( _L("fatal error - castorage.db not exists in ROM"),
|
86
|
228 |
KErrNotFound );
|
|
229 |
}
|
|
230 |
else
|
|
231 |
{
|
|
232 |
if( !( BaflUtils::FolderExists( iRfs, iPrivatePathCDrive ) ) )
|
|
233 |
{
|
|
234 |
User::LeaveIfError( iRfs.CreatePrivatePath( EDriveC ) );
|
|
235 |
}
|
|
236 |
User::LeaveIfError( BaflUtils::CopyFile( iRfs,
|
|
237 |
iPrivatePathZDriveDb, iPrivatePathCDrive ) );
|
|
238 |
User::LeaveIfError( iRfs.SetAtt( iPrivatePathCDriveDb,
|
|
239 |
KEntryAttNormal, KEntryAttReadOnly ) );
|
|
240 |
User::LeaveIfError( iSqlDb.Open( iPrivatePathCDriveDb,
|
|
241 |
&KSqlDbConfig ) );
|
|
242 |
}
|
85
|
243 |
}
|
|
244 |
|
|
245 |
// ---------------------------------------------------------------------------
|
127
|
246 |
//
|
107
|
247 |
//
|
|
248 |
// ---------------------------------------------------------------------------
|
|
249 |
//
|
|
250 |
void CCaSqLiteStorage::SaveDatabaseL()
|
|
251 |
{
|
|
252 |
if( ( BaflUtils::FileExists( iRfs, iPrivatePathCDriveDb ) ) )
|
|
253 |
{
|
|
254 |
iSqlDb.Close();
|
127
|
255 |
User::LeaveIfError( BaflUtils::CopyFile(
|
|
256 |
iRfs, iPrivatePathCDriveDb, iPrivatePathCDriveDbBackup ) );
|
|
257 |
User::LeaveIfError( iSqlDb.Open(
|
|
258 |
iPrivatePathCDriveDb, &KSqlDbConfig ) );
|
107
|
259 |
}
|
|
260 |
}
|
|
261 |
|
|
262 |
// ---------------------------------------------------------------------------
|
127
|
263 |
//
|
107
|
264 |
//
|
|
265 |
// ---------------------------------------------------------------------------
|
|
266 |
//
|
|
267 |
void CCaSqLiteStorage::RestoreDatabaseL()
|
|
268 |
{
|
127
|
269 |
if( BaflUtils::FileExists( iRfs, iPrivatePathCDriveDbBackup ) )
|
107
|
270 |
{
|
127
|
271 |
RPointerArray<CCaInnerEntry> resultArray;
|
|
272 |
CleanupResetAndDestroyPushL( resultArray );
|
|
273 |
//get current downloaded applications list
|
|
274 |
GetDownloadedApplicationsArrayL( resultArray );
|
|
275 |
|
107
|
276 |
iSqlDb.Close();
|
127
|
277 |
User::LeaveIfError( BaflUtils::CopyFile(
|
|
278 |
iRfs, iPrivatePathCDriveDbBackup, iPrivatePathCDriveDb ) );
|
|
279 |
User::LeaveIfError( iSqlDb.Open(
|
|
280 |
iPrivatePathCDriveDb, &KSqlDbConfig ) );
|
|
281 |
|
|
282 |
//set current downloaded applications list to backuped
|
|
283 |
//downloaded collection
|
|
284 |
SetDownloadedApplicationsArrayL( resultArray );
|
|
285 |
CleanupStack::PopAndDestroy( &resultArray );
|
107
|
286 |
}
|
127
|
287 |
SetDBPropertyL( KCaDbPropRestore, KCaDbPropNoRestoreVal );
|
107
|
288 |
}
|
|
289 |
|
|
290 |
// ---------------------------------------------------------------------------
|
85
|
291 |
// CCASqLiteStorage::NewL()
|
|
292 |
//
|
|
293 |
// ---------------------------------------------------------------------------
|
|
294 |
//
|
|
295 |
CCaSqLiteStorage* CCaSqLiteStorage::NewL()
|
|
296 |
{
|
|
297 |
CCaSqLiteStorage* self = CCaSqLiteStorage::NewLC();
|
|
298 |
CleanupStack::Pop( self );
|
|
299 |
return self;
|
|
300 |
}
|
|
301 |
|
|
302 |
// ---------------------------------------------------------------------------
|
|
303 |
// CCASqLiteStorage::NewLC()
|
|
304 |
//
|
|
305 |
// ---------------------------------------------------------------------------
|
|
306 |
//
|
|
307 |
CCaSqLiteStorage* CCaSqLiteStorage::NewLC()
|
|
308 |
{
|
|
309 |
CCaSqLiteStorage* self = new ( ELeave ) CCaSqLiteStorage();
|
|
310 |
CleanupStack::PushL( self );
|
|
311 |
self->ConstructL();
|
|
312 |
return self;
|
|
313 |
}
|
|
314 |
|
|
315 |
// ---------------------------------------------------------------------------
|
|
316 |
// CCASqLiteStorage::~CCpStorageEngine()
|
|
317 |
//
|
|
318 |
// ---------------------------------------------------------------------------
|
|
319 |
//
|
|
320 |
CCaSqLiteStorage::~CCaSqLiteStorage()
|
|
321 |
{
|
|
322 |
iSqlDb.Close();
|
86
|
323 |
iRfs.Close();
|
85
|
324 |
}
|
|
325 |
|
|
326 |
// ---------------------------------------------------------------------------
|
|
327 |
// CCaSqLiteStorage::CreatePrivateDirPath()
|
|
328 |
//
|
|
329 |
// ---------------------------------------------------------------------------
|
|
330 |
//
|
|
331 |
TInt CCaSqLiteStorage::CreatePrivateDirPath( TFileName& aPrivatePath,
|
86
|
332 |
const TDesC& aDrive, const TDesC& aDbName )
|
85
|
333 |
{
|
|
334 |
TInt error( KErrNone );
|
|
335 |
|
|
336 |
#ifdef CONTENT_ARSENAL_STORAGE_UT
|
|
337 |
TFileName KPathWithoutDrive( KDoubleSlash );
|
|
338 |
#else
|
|
339 |
TFileName KPathWithoutDrive;
|
86
|
340 |
error = iRfs.PrivatePath( KPathWithoutDrive );
|
85
|
341 |
if( error != KErrNone )
|
|
342 |
{
|
|
343 |
return error;
|
|
344 |
}
|
|
345 |
#endif
|
|
346 |
|
|
347 |
aPrivatePath.Copy( aDrive );
|
|
348 |
aPrivatePath.Append( KPathWithoutDrive );
|
|
349 |
aPrivatePath.Append( aDbName );
|
|
350 |
|
|
351 |
return error;
|
|
352 |
}
|
|
353 |
|
|
354 |
// ---------------------------------------------------------------------------
|
|
355 |
// CCASqLiteStorage::GetListL
|
|
356 |
//
|
|
357 |
// ---------------------------------------------------------------------------
|
|
358 |
//
|
|
359 |
void CCaSqLiteStorage::GetEntriesL( const CCaInnerQuery* aQuery,
|
|
360 |
RPointerArray<CCaInnerEntry>& aResultContainer )
|
|
361 |
{
|
|
362 |
// Fetch entries from
|
|
363 |
CCaSqlQuery* sqlGetEntriesQuery = CCaSqlQuery::NewLC( iSqlDb );
|
|
364 |
CaSqlQueryCreator::CreateGetEntriesQueryL( aQuery, sqlGetEntriesQuery );
|
|
365 |
sqlGetEntriesQuery->PrepareL();
|
|
366 |
sqlGetEntriesQuery->BindValuesForGetEntriesL( aQuery );
|
|
367 |
sqlGetEntriesQuery->ExecuteL( aResultContainer, CCaSqlQuery::EEntry );
|
|
368 |
CleanupStack::PopAndDestroy( sqlGetEntriesQuery );
|
|
369 |
|
|
370 |
// Populate the entries with their attributes
|
|
371 |
if( aResultContainer.Count() > 0 )
|
|
372 |
{
|
|
373 |
CCaSqlQuery* sqlGetAttributesQuery = CCaSqlQuery::NewLC( iSqlDb );
|
|
374 |
CaSqlQueryCreator::CreateGetAttributesQueryL(
|
|
375 |
aResultContainer.Count(), sqlGetAttributesQuery );
|
|
376 |
sqlGetAttributesQuery->PrepareL();
|
|
377 |
sqlGetAttributesQuery->BindEntryIdsL( aResultContainer );
|
|
378 |
sqlGetAttributesQuery->ExecuteL( aResultContainer,
|
|
379 |
CCaSqlQuery::EAttribute );
|
|
380 |
CleanupStack::PopAndDestroy( sqlGetAttributesQuery );
|
|
381 |
}
|
127
|
382 |
|
85
|
383 |
// set entries if proper order if they were fetched by ids
|
|
384 |
if( aQuery->GetIds().Count() > 0 )
|
|
385 |
{
|
|
386 |
SetEntriesInProperOrderL( aQuery->GetIds(), aResultContainer );
|
|
387 |
}
|
|
388 |
}
|
|
389 |
|
94
|
390 |
// ---------------------------------------------------------------------------
|
|
391 |
//
|
|
392 |
// ---------------------------------------------------------------------------
|
|
393 |
//
|
85
|
394 |
void CCaSqLiteStorage::LocalizeEntryL( CCaLocalizationEntry& aLocalization )
|
|
395 |
{
|
|
396 |
CCaSqlQuery* sqlLocalizeEntryQuery = CCaSqlQuery::NewLC( iSqlDb );
|
107
|
397 |
if ( aLocalization.GetAttributeName().Compare( KColumnEnText ) == 0 )
|
96
|
398 |
{
|
|
399 |
CaSqlQueryCreator::CreateLocalizationTableQueryL( sqlLocalizeEntryQuery,
|
|
400 |
KSQLLocalizeTextEntry );
|
|
401 |
}
|
|
402 |
else if ( aLocalization.GetAttributeName().Compare(
|
|
403 |
KColumnEnDescription ) == 0 )
|
|
404 |
{
|
|
405 |
CaSqlQueryCreator::CreateLocalizationTableQueryL( sqlLocalizeEntryQuery,
|
|
406 |
KSQLLocalizeDescriptionEntry );
|
|
407 |
}
|
107
|
408 |
else if ( aLocalization.GetAttributeName().Compare( KShortName ) == 0 )
|
|
409 |
{
|
|
410 |
CaSqlQueryCreator::CreateLocalizationTableQueryL( sqlLocalizeEntryQuery,
|
|
411 |
KSQLLocalizeShortNameAttribute );
|
|
412 |
}
|
|
413 |
else if ( aLocalization.GetAttributeName().Compare( KTitleName ) == 0 )
|
|
414 |
{
|
|
415 |
CaSqlQueryCreator::CreateLocalizationTableQueryL( sqlLocalizeEntryQuery,
|
|
416 |
KSQLLocalizeTitleNameAttribute );
|
|
417 |
}
|
85
|
418 |
sqlLocalizeEntryQuery->PrepareL();
|
|
419 |
sqlLocalizeEntryQuery->BindValuesForLocalizeL( aLocalization );
|
|
420 |
sqlLocalizeEntryQuery->ExecuteL( );
|
|
421 |
CleanupStack::PopAndDestroy( sqlLocalizeEntryQuery );
|
|
422 |
}
|
|
423 |
|
94
|
424 |
// ---------------------------------------------------------------------------
|
|
425 |
//
|
|
426 |
// ---------------------------------------------------------------------------
|
|
427 |
//
|
|
428 |
void CCaSqLiteStorage::AddLocalizationL(
|
|
429 |
const CCaLocalizationEntry& aLocalization)
|
|
430 |
{
|
|
431 |
if (LocalizationEntryPresentL(aLocalization))
|
|
432 |
{
|
|
433 |
ExecuteLocalizationStatementL(aLocalization, KSQLUpdateLocalization);
|
|
434 |
}
|
|
435 |
else
|
|
436 |
{
|
|
437 |
ExecuteLocalizationStatementL(aLocalization, KSQLAddLocalization);
|
|
438 |
}
|
|
439 |
}
|
|
440 |
|
|
441 |
// ---------------------------------------------------------------------------
|
|
442 |
//
|
|
443 |
// ---------------------------------------------------------------------------
|
|
444 |
//
|
|
445 |
TBool CCaSqLiteStorage::LocalizationEntryPresentL(
|
|
446 |
const CCaLocalizationEntry& aLocalization)
|
|
447 |
{
|
|
448 |
TBool result(EFalse);
|
|
449 |
CCaSqlQuery* sqlQuery = CCaSqlQuery::NewLC( iSqlDb );
|
|
450 |
CaSqlQueryCreator::CreateLocalizationTableQueryL(sqlQuery,
|
|
451 |
KSQLGetLocalization);
|
|
452 |
sqlQuery->PrepareL();
|
|
453 |
sqlQuery->BindValuesForGetLocalizationEntryL( aLocalization );
|
|
454 |
result = sqlQuery->ExecuteEntryPresentL( );
|
|
455 |
CleanupStack::PopAndDestroy( sqlQuery );
|
|
456 |
return result;
|
|
457 |
}
|
|
458 |
|
|
459 |
// ---------------------------------------------------------------------------
|
|
460 |
//
|
|
461 |
// ---------------------------------------------------------------------------
|
|
462 |
//
|
|
463 |
void CCaSqLiteStorage::ExecuteLocalizationStatementL(
|
|
464 |
const CCaLocalizationEntry& aLocalization, const TDesC& aStatement)
|
|
465 |
{
|
|
466 |
CCaSqlQuery* sqlQuery = CCaSqlQuery::NewLC( iSqlDb );
|
|
467 |
CaSqlQueryCreator::CreateLocalizationTableQueryL(sqlQuery,aStatement );
|
|
468 |
sqlQuery->PrepareL();
|
|
469 |
sqlQuery->BindValuesForLocalizationEntryL( aLocalization );
|
|
470 |
sqlQuery->ExecuteL( );
|
|
471 |
CleanupStack::PopAndDestroy( sqlQuery );
|
|
472 |
}
|
|
473 |
|
|
474 |
// ---------------------------------------------------------------------------
|
|
475 |
//
|
|
476 |
// ---------------------------------------------------------------------------
|
|
477 |
//
|
86
|
478 |
void CCaSqLiteStorage::GetLocalizationsL(
|
|
479 |
RPointerArray<CCaLocalizationEntry>& aResultContainer )
|
85
|
480 |
{
|
|
481 |
CCaSqlQuery* sqlGetLocalizationsQuery = CCaSqlQuery::NewLC( iSqlDb );
|
94
|
482 |
CaSqlQueryCreator::CreateLocalizationTableQueryL(
|
|
483 |
sqlGetLocalizationsQuery, KSQLGetLocalizations );
|
85
|
484 |
sqlGetLocalizationsQuery->PrepareL();
|
|
485 |
sqlGetLocalizationsQuery->ExecuteLocalizationsL( aResultContainer );
|
|
486 |
CleanupStack::PopAndDestroy( sqlGetLocalizationsQuery );
|
|
487 |
}
|
|
488 |
|
|
489 |
// ---------------------------------------------------------------------------
|
|
490 |
// CCASqLiteStorage::GetEntriesIdsL
|
|
491 |
//
|
|
492 |
// ---------------------------------------------------------------------------
|
|
493 |
//
|
86
|
494 |
void CCaSqLiteStorage::GetEntriesIdsL( const CCaInnerQuery* aQuery,
|
85
|
495 |
RArray<TInt>& aResultIdArray )
|
|
496 |
{
|
|
497 |
CCaSqlQuery* sqlGetEntriesIdsQuery = CCaSqlQuery::NewLC( iSqlDb );
|
|
498 |
CaSqlQueryCreator::CreateGetEntriesQueryL( aQuery,
|
|
499 |
sqlGetEntriesIdsQuery );
|
|
500 |
sqlGetEntriesIdsQuery->PrepareL();
|
|
501 |
sqlGetEntriesIdsQuery->BindValuesForGetEntriesL( aQuery );
|
|
502 |
sqlGetEntriesIdsQuery->ExecuteL( aResultIdArray,
|
|
503 |
CCaSqlQuery::EEntryTable );
|
|
504 |
CleanupStack::PopAndDestroy( sqlGetEntriesIdsQuery );
|
|
505 |
}
|
|
506 |
|
|
507 |
// ---------------------------------------------------------------------------
|
|
508 |
// CCASqLiteStorage::GetEntriesIdsL
|
|
509 |
//
|
|
510 |
// ---------------------------------------------------------------------------
|
|
511 |
//
|
|
512 |
void CCaSqLiteStorage::GetParentsIdsL( const RArray<TInt>& aEntryIdArray,
|
98
|
513 |
RArray<TInt>& aParentIdArray, TBool aCheckParentsParent )
|
85
|
514 |
{
|
|
515 |
CCaSqlQuery* sqlGetParentIdsQuery = CCaSqlQuery::NewLC( iSqlDb );
|
|
516 |
CaSqlQueryCreator::CreateGetParentsIdsQueryL( aEntryIdArray,
|
|
517 |
sqlGetParentIdsQuery, aParentIdArray );
|
|
518 |
sqlGetParentIdsQuery->PrepareL();
|
|
519 |
sqlGetParentIdsQuery->BindIdsL( aEntryIdArray, KSQLGEEntryId );
|
|
520 |
if( aParentIdArray.Count() > 0 )
|
|
521 |
{
|
|
522 |
sqlGetParentIdsQuery->BindIdsL( aParentIdArray, KSQLGEIdGroup );
|
|
523 |
}
|
|
524 |
TInt parentCount = sqlGetParentIdsQuery->ExecuteL( aParentIdArray,
|
|
525 |
CCaSqlQuery::EGroupTable );
|
|
526 |
CleanupStack::PopAndDestroy( sqlGetParentIdsQuery );
|
98
|
527 |
if( aCheckParentsParent && parentCount > 0 )
|
85
|
528 |
{
|
|
529 |
GetParentsIdsL( aParentIdArray, aParentIdArray );
|
|
530 |
}
|
|
531 |
}
|
|
532 |
|
|
533 |
// ---------------------------------------------------------------------------
|
|
534 |
// CCASqLiteStorage::AddL
|
|
535 |
//
|
|
536 |
// ---------------------------------------------------------------------------
|
|
537 |
//
|
127
|
538 |
void CCaSqLiteStorage::AddL( CCaInnerEntry* aEntry, TBool aUpdate )
|
85
|
539 |
{
|
|
540 |
RPointerArray<CCaSqlQuery> sqlQueries;
|
|
541 |
CleanupResetAndDestroyPushL( sqlQueries );
|
|
542 |
|
|
543 |
CaSqlQueryCreator::CreateAddQueryL( aEntry, sqlQueries, iSqlDb );
|
|
544 |
|
|
545 |
ExecuteStatementL( KSqlStatementBegin );
|
|
546 |
TRAPD( err, ExecuteAddL( aEntry, sqlQueries ) );
|
|
547 |
if( err )
|
|
548 |
{
|
|
549 |
ExecuteStatementL( KSqlStatementRollback );
|
|
550 |
User::Leave( err );
|
|
551 |
}
|
|
552 |
ExecuteStatementL( KSqlStatementCommit );
|
|
553 |
|
|
554 |
CleanupStack::PopAndDestroy( &sqlQueries );
|
86
|
555 |
|
85
|
556 |
if( aUpdate )
|
|
557 |
{
|
|
558 |
RemoveFromLocalizationL( aEntry->GetId() );
|
|
559 |
}
|
|
560 |
}
|
|
561 |
|
|
562 |
// ---------------------------------------------------------------------------
|
|
563 |
// CCASqLiteStorage::RemoveL
|
|
564 |
//
|
|
565 |
// ---------------------------------------------------------------------------
|
|
566 |
//
|
|
567 |
void CCaSqLiteStorage::RemoveL( const RArray<TInt>& aEntryIds )
|
|
568 |
{
|
|
569 |
ExecuteStatementL( KSqlStatementBegin );
|
|
570 |
TRAPD( err, ExecuteRemoveL( aEntryIds ) );
|
|
571 |
if( err )
|
|
572 |
{
|
|
573 |
ExecuteStatementL( KSqlStatementRollback );
|
|
574 |
User::Leave( err );
|
|
575 |
}
|
|
576 |
ExecuteStatementL( KSqlStatementCommit );
|
|
577 |
}
|
|
578 |
|
|
579 |
// ---------------------------------------------------------------------------
|
86
|
580 |
// CCASqLiteStorage::OrganizeL( const RArray<TInt>& aEntryIds,
|
85
|
581 |
// TCaOperationParams aParams )
|
|
582 |
//
|
|
583 |
// ---------------------------------------------------------------------------
|
|
584 |
//
|
|
585 |
void CCaSqLiteStorage::OrganizeL( const RArray<TInt>& aEntryIds,
|
|
586 |
TCaOperationParams aParams )
|
|
587 |
{
|
|
588 |
ExecuteStatementL( KSqlStatementBegin );
|
|
589 |
TRAPD( err, ExecuteOrganizeL( aEntryIds, aParams ) );
|
|
590 |
if( err )
|
|
591 |
{
|
|
592 |
ExecuteStatementL( KSqlStatementRollback );
|
|
593 |
User::Leave( err );
|
|
594 |
}
|
|
595 |
ExecuteStatementL( KSqlStatementCommit );
|
|
596 |
}
|
|
597 |
|
|
598 |
// ---------------------------------------------------------------------------
|
|
599 |
// CCASqLiteStorage::TouchL( const TInt aEntryId )
|
|
600 |
//
|
|
601 |
// ---------------------------------------------------------------------------
|
|
602 |
//
|
107
|
603 |
void CCaSqLiteStorage::TouchL( const TInt aEntryId, TBool aRemovable )
|
85
|
604 |
{
|
|
605 |
ExecuteStatementL( KSqlStatementBegin );
|
107
|
606 |
TRAPD( err, ExecuteTouchL( aEntryId, aRemovable ) );
|
85
|
607 |
if( err )
|
|
608 |
{
|
|
609 |
ExecuteStatementL( KSqlStatementRollback );
|
|
610 |
User::Leave( err );
|
|
611 |
}
|
|
612 |
ExecuteStatementL( KSqlStatementCommit );
|
|
613 |
}
|
|
614 |
|
|
615 |
// ---------------------------------------------------------------------------
|
86
|
616 |
// CCASqLiteStorage::DbPropertyL
|
|
617 |
// ( const TDesC& aProperty, TDes& aPropertyValue )
|
85
|
618 |
// ---------------------------------------------------------------------------
|
|
619 |
//
|
|
620 |
void CCaSqLiteStorage::DbPropertyL( const TDesC& aProperty,
|
|
621 |
TDes& aPropertyValue )
|
|
622 |
{
|
|
623 |
ExecuteStatementL( KSqlStatementBegin );
|
|
624 |
TRAPD( err, ExecuteDbPropertyL( aProperty, aPropertyValue ) );
|
|
625 |
if( err )
|
|
626 |
{
|
|
627 |
ExecuteStatementL( KSqlStatementRollback );
|
|
628 |
User::Leave( err );
|
|
629 |
}
|
|
630 |
ExecuteStatementL( KSqlStatementCommit );
|
|
631 |
}
|
|
632 |
|
|
633 |
// ---------------------------------------------------------------------------
|
86
|
634 |
// CCASqLiteStorage::SetDBPropertyL
|
|
635 |
// ( const TDesC& aProperty, const TDesC& aPropertyValue )
|
85
|
636 |
// ---------------------------------------------------------------------------
|
|
637 |
//
|
|
638 |
void CCaSqLiteStorage::SetDBPropertyL( const TDesC& aProperty,
|
|
639 |
const TDesC& aPropertyValue )
|
|
640 |
{
|
|
641 |
ExecuteStatementL( KSqlStatementBegin );
|
|
642 |
TRAPD( err, ExecuteSetDbPropertyL( aProperty, aPropertyValue ) );
|
|
643 |
if( err )
|
|
644 |
{
|
|
645 |
ExecuteStatementL( KSqlStatementRollback );
|
|
646 |
User::Leave( err );
|
|
647 |
}
|
|
648 |
ExecuteStatementL( KSqlStatementCommit );
|
|
649 |
}
|
|
650 |
|
|
651 |
// ---------------------------------------------------------------------------
|
|
652 |
// CCaSqLiteStorage::RemoveFromLocalizationL( const TInt aEntryId )
|
|
653 |
//
|
|
654 |
// ---------------------------------------------------------------------------
|
|
655 |
//
|
|
656 |
void CCaSqLiteStorage::RemoveFromLocalizationL( const TInt aEntryId )
|
|
657 |
{
|
|
658 |
ExecuteStatementL( KSqlStatementBegin );
|
|
659 |
TRAPD( err, ExecuteRemoveFromLocalizationL( aEntryId ) );
|
|
660 |
if( err )
|
|
661 |
{
|
|
662 |
ExecuteStatementL( KSqlStatementRollback );
|
|
663 |
User::Leave( err );
|
|
664 |
}
|
|
665 |
ExecuteStatementL( KSqlStatementCommit );
|
|
666 |
}
|
|
667 |
|
|
668 |
// ---------------------------------------------------------------------------
|
86
|
669 |
// CCaSqLiteStorage::CustomSortL
|
|
670 |
// ( const RArray<TInt>& aEntryIds, const TInt aGroupId )
|
85
|
671 |
// ---------------------------------------------------------------------------
|
|
672 |
//
|
|
673 |
void CCaSqLiteStorage::CustomSortL( const RArray<TInt>& aEntryIds,
|
|
674 |
const TInt aGroupId )
|
|
675 |
{
|
107
|
676 |
RArray<TInt> entryIds;
|
|
677 |
CleanupClosePushL( entryIds );
|
|
678 |
for( TInt j=0; j<aEntryIds.Count(); j++ )
|
|
679 |
{
|
|
680 |
entryIds.AppendL(aEntryIds[j]);
|
|
681 |
}
|
127
|
682 |
|
107
|
683 |
RArray<TInt> oldIds;
|
|
684 |
CleanupClosePushL( oldIds );
|
|
685 |
CCaInnerQuery* innerQuery = CCaInnerQuery::NewLC();
|
|
686 |
innerQuery->SetParentId( aGroupId );
|
127
|
687 |
|
107
|
688 |
GetEntriesIdsL( innerQuery, oldIds );
|
127
|
689 |
|
107
|
690 |
if( oldIds.Count() != entryIds.Count() )
|
|
691 |
{
|
|
692 |
for( TInt i=0; i<oldIds.Count(); i++ )
|
|
693 |
{
|
|
694 |
TInt oldId = oldIds[i];
|
|
695 |
if( entryIds.Find( oldId ) == KErrNotFound )
|
|
696 |
{
|
|
697 |
// instert apps with visible set on false on old positions
|
|
698 |
entryIds.InsertL( oldId, i );
|
|
699 |
}
|
|
700 |
}
|
|
701 |
}
|
127
|
702 |
|
107
|
703 |
const RArray<TInt> constEntryIds( entryIds );
|
127
|
704 |
|
85
|
705 |
RPointerArray<CCaSqlQuery> sqlQueries;
|
127
|
706 |
CleanupResetAndDestroyPushL( sqlQueries );
|
85
|
707 |
|
86
|
708 |
CaSqlQueryCreator::CreateCustomSortQueryL(
|
107
|
709 |
constEntryIds, sqlQueries, iSqlDb );
|
85
|
710 |
|
|
711 |
ExecuteStatementL( KSqlStatementBegin );
|
107
|
712 |
TRAPD( err, ExecuteCustomSortL( constEntryIds, aGroupId, sqlQueries ) );
|
85
|
713 |
if( err )
|
|
714 |
{
|
|
715 |
ExecuteStatementL( KSqlStatementRollback );
|
|
716 |
User::Leave( err );
|
|
717 |
}
|
|
718 |
ExecuteStatementL( KSqlStatementCommit );
|
|
719 |
|
|
720 |
CleanupStack::PopAndDestroy( &sqlQueries );
|
107
|
721 |
CleanupStack::PopAndDestroy( innerQuery );
|
|
722 |
CleanupStack::PopAndDestroy( &oldIds );
|
|
723 |
CleanupStack::PopAndDestroy( &entryIds );
|
85
|
724 |
}
|
|
725 |
|
|
726 |
// ---------------------------------------------------------------------------
|
86
|
727 |
// CCaSqLiteStorage::ExecuteCustomSortL
|
|
728 |
// ( const RArray<TInt>& aEntryIds, const TInt aGroupId )
|
85
|
729 |
// ---------------------------------------------------------------------------
|
|
730 |
//
|
|
731 |
void CCaSqLiteStorage::ExecuteCustomSortL( const RArray<TInt>& aEntryIds,
|
|
732 |
const TInt aGroupId , RPointerArray<CCaSqlQuery>& aSqlQuery )
|
|
733 |
{
|
|
734 |
for( TInt i = 0; i < aSqlQuery.Count(); i++ )
|
|
735 |
{
|
|
736 |
TInt newPosition = i + 1;
|
|
737 |
TInt entryId = aEntryIds[i];
|
86
|
738 |
|
85
|
739 |
aSqlQuery[i]->PrepareL();
|
|
740 |
aSqlQuery[i]->BindValuesForCustomSortL( aGroupId, entryId, newPosition );
|
|
741 |
aSqlQuery[i]->ExecuteL();
|
|
742 |
aSqlQuery[i]->CloseStatement();
|
|
743 |
}
|
|
744 |
}
|
|
745 |
|
|
746 |
// ---------------------------------------------------------------------------
|
|
747 |
// CCaSqLiteStorage::ExecuteRemoveFromLocalizationL( const TInt aEntryId )
|
|
748 |
//
|
|
749 |
// ---------------------------------------------------------------------------
|
|
750 |
//
|
|
751 |
void CCaSqLiteStorage::ExecuteRemoveFromLocalizationL( const TInt aEntryId )
|
|
752 |
{
|
|
753 |
CCaSqlQuery* query = CCaSqlQuery::NewLC( iSqlDb );
|
|
754 |
query->SetQueryL( KSQLDeleteLocalizationTextWhereEntryId );
|
|
755 |
query->PrepareL();
|
|
756 |
query->BindValuesForRemoveFromLocalizationL( aEntryId );
|
|
757 |
query->ExecuteL();
|
|
758 |
CleanupStack::PopAndDestroy( query );
|
|
759 |
}
|
|
760 |
|
|
761 |
// ---------------------------------------------------------------------------
|
|
762 |
// CCASqLiteStorage::ExecuteStatementL( const TDesC& aStatement )
|
|
763 |
//
|
|
764 |
// ---------------------------------------------------------------------------
|
|
765 |
//
|
|
766 |
void CCaSqLiteStorage::ExecuteStatementL( const TDesC& aStatement )
|
|
767 |
{
|
|
768 |
CCaSqlQuery* query = CCaSqlQuery::NewLC( iSqlDb );
|
|
769 |
query->SetQueryL( aStatement );
|
|
770 |
query->PrepareL();
|
|
771 |
query->ExecuteL();
|
|
772 |
CleanupStack::PopAndDestroy( query );
|
|
773 |
}
|
|
774 |
|
|
775 |
// ---------------------------------------------------------------------------
|
86
|
776 |
// CCASqLiteStorage::ExecuteAddL(CCaInnerEntry* aEntry,
|
85
|
777 |
// RPointerArray<CCASqlQuery>& sqlQuery)
|
|
778 |
//
|
|
779 |
// ---------------------------------------------------------------------------
|
|
780 |
//
|
86
|
781 |
void CCaSqLiteStorage::ExecuteAddL( CCaInnerEntry* aEntry,
|
85
|
782 |
RPointerArray<CCaSqlQuery>& aSqlQuery )
|
|
783 |
{
|
|
784 |
TBool isAttributeDeleted( EFalse );
|
|
785 |
for( TInt i = 0; i < aSqlQuery.Count(); i++ )
|
|
786 |
{
|
|
787 |
if( aSqlQuery[i]->Type() == CCaSqlQuery::EIconTable )
|
|
788 |
{
|
|
789 |
//check if icon exists - just update
|
|
790 |
CCaSqlQuery* query = CCaSqlQuery::NewLC( iSqlDb );
|
92
|
791 |
CaSqlQueryCreator::CreateFindIconQueryL(aEntry, query);
|
85
|
792 |
query->SetTableType( CCaSqlQuery::EIconTable );
|
|
793 |
query->PrepareL();
|
|
794 |
query->BindValuesForGetIconL( aEntry );
|
92
|
795 |
TInt idIcon( 0 );
|
|
796 |
query->ExecuteL( idIcon );
|
85
|
797 |
CleanupStack::PopAndDestroy( query );
|
86
|
798 |
|
85
|
799 |
aSqlQuery[i]->PrepareL();
|
|
800 |
aSqlQuery[i]->BindValuesForAddL( aEntry );
|
|
801 |
TInt tmpId( 0 );
|
|
802 |
TRAPD( err, tmpId = aSqlQuery[i]->ExecuteL() );
|
|
803 |
aSqlQuery[i]->CloseStatement();
|
92
|
804 |
if( !idIcon && !aEntry->GetIconId() )
|
85
|
805 |
{ // new icon added
|
|
806 |
aEntry->SetIconId( tmpId );
|
|
807 |
}
|
|
808 |
if( err == KSqlErrConstraint )
|
|
809 |
{
|
|
810 |
// ignore, this means that the icon cannot be removed
|
|
811 |
// because some other entry has the same icon.
|
|
812 |
}
|
|
813 |
else if( err )
|
|
814 |
{
|
|
815 |
User::Leave( err );
|
|
816 |
}
|
|
817 |
|
|
818 |
}
|
|
819 |
else if( aSqlQuery[i]->Type() == CCaSqlQuery::EEntryTable )
|
|
820 |
{
|
|
821 |
aSqlQuery[i]->PrepareL();
|
|
822 |
aSqlQuery[i]->BindValuesForAddL( aEntry );
|
|
823 |
TInt tmpId = aSqlQuery[i]->ExecuteL();
|
|
824 |
aSqlQuery[i]->CloseStatement();
|
|
825 |
if( !aEntry->GetId() )
|
|
826 |
{
|
|
827 |
// new entry added
|
|
828 |
aEntry->SetId( tmpId );
|
|
829 |
}
|
|
830 |
}
|
|
831 |
else if( !isAttributeDeleted
|
|
832 |
&& aSqlQuery[i]->Type() == CCaSqlQuery::EAttributeTable )
|
|
833 |
{
|
|
834 |
// delete all entry's attributes, just ones
|
|
835 |
aSqlQuery[i]->PrepareL();
|
|
836 |
aSqlQuery[i]->BindEntryIdL( aEntry->GetId() );
|
|
837 |
aSqlQuery[i]->ExecuteL();
|
|
838 |
aSqlQuery[i]->CloseStatement();
|
|
839 |
isAttributeDeleted = ETrue;
|
|
840 |
}
|
127
|
841 |
else if( aSqlQuery[i]->Type() == CCaSqlQuery::EAttributeTable )
|
85
|
842 |
{
|
|
843 |
// add new attribute(s) if it's neccesery
|
|
844 |
aSqlQuery[i]->PrepareL();
|
|
845 |
for( TInt k(0); k < aEntry->GetAttributes().Count(); k++ )
|
|
846 |
{
|
|
847 |
// if(id_entry, name) exist it'll replaced by new value
|
|
848 |
aSqlQuery[i]->BindValuesForAddAttributeL( aEntry,
|
|
849 |
aEntry->GetAttributes()[k] );
|
|
850 |
aSqlQuery[i]->ExecuteL();
|
|
851 |
aSqlQuery[i]->ResetStatement();
|
|
852 |
}
|
|
853 |
aSqlQuery[i]->CloseStatement();
|
|
854 |
}
|
|
855 |
}
|
|
856 |
}
|
|
857 |
// ---------------------------------------------------------------------------
|
|
858 |
// CCASqLiteStorage::ExecuteRemoveL( const RArray<TInt>& aEntryIds)
|
|
859 |
//
|
|
860 |
// ---------------------------------------------------------------------------
|
|
861 |
//
|
|
862 |
void CCaSqLiteStorage::ExecuteRemoveL( const RArray<TInt>& aEntryIds )
|
|
863 |
{
|
|
864 |
for( int i=0; i<aEntryIds.Count(); i++ )
|
|
865 |
{
|
|
866 |
// check if entry exist in database
|
|
867 |
CCaSqlQuery* queryEntry = CCaSqlQuery::NewLC( iSqlDb );
|
|
868 |
queryEntry->SetQueryL( KSQLGetEntryIdFromEntryTable );
|
|
869 |
queryEntry->PrepareL();
|
|
870 |
queryEntry->BindEntryIdL( aEntryIds[i] );
|
|
871 |
TInt entryCount( 0 );
|
|
872 |
queryEntry->ExecuteL( entryCount );
|
|
873 |
CleanupStack::PopAndDestroy( queryEntry );
|
|
874 |
if( !entryCount )
|
|
875 |
{
|
|
876 |
User::Leave( KErrNotFound );
|
|
877 |
}
|
|
878 |
|
|
879 |
// SELECT Id_Icon FROM CA_ENTRY WHERE Id = aEntryId;
|
|
880 |
CCaSqlQuery* queryIconId = CCaSqlQuery::NewLC( iSqlDb );
|
|
881 |
queryIconId->SetQueryL( KSQLGETIconIdFromEntryTable );
|
|
882 |
queryIconId->PrepareL();
|
|
883 |
queryIconId->BindEntryIdL( aEntryIds[i] );
|
|
884 |
TInt iconId( 0 );
|
|
885 |
queryIconId->ExecuteL( iconId );
|
|
886 |
CleanupStack::PopAndDestroy( queryIconId );
|
|
887 |
|
|
888 |
RPointerArray<CCaSqlQuery> sqlQuery;
|
|
889 |
CleanupResetAndDestroyPushL( sqlQuery );
|
|
890 |
CaSqlQueryCreator::CreateRemoveQueryL( sqlQuery, iSqlDb );
|
|
891 |
for( TInt j = 0; j < sqlQuery.Count(); j++ )
|
|
892 |
{
|
|
893 |
if( !( sqlQuery[j]->Type() == CCaSqlQuery::EIconTable &&
|
|
894 |
iconId == 0 ) )
|
|
895 |
{
|
|
896 |
sqlQuery[j]->PrepareL();
|
|
897 |
sqlQuery[j]->BindValuesForRemoveL( aEntryIds[i], iconId );
|
|
898 |
TRAPD( err, sqlQuery[j]->ExecuteL() );
|
|
899 |
sqlQuery[j]->CloseStatement();
|
|
900 |
|
|
901 |
if( sqlQuery[j]->Type() == CCaSqlQuery::EIconTable &&
|
|
902 |
err == KSqlErrConstraint )
|
|
903 |
{
|
|
904 |
// ignore, this means that the icon cannot be removed
|
|
905 |
// because some other entry has the same icon.
|
|
906 |
}
|
|
907 |
else if( err )
|
|
908 |
{
|
|
909 |
User::Leave( err );
|
|
910 |
}
|
|
911 |
}
|
|
912 |
}
|
|
913 |
CleanupStack::PopAndDestroy( &sqlQuery );
|
|
914 |
}
|
|
915 |
}
|
|
916 |
|
|
917 |
// ---------------------------------------------------------------------------
|
|
918 |
// CCASqLiteStorage::ExecuteOrganizeL(const RArray<TInt>& aEntryIds,
|
|
919 |
// TCaOperationParams aParams)
|
|
920 |
//
|
|
921 |
// ---------------------------------------------------------------------------
|
|
922 |
//
|
|
923 |
void CCaSqLiteStorage::ExecuteOrganizeL( const RArray<TInt>& aEntryIds,
|
|
924 |
TCaOperationParams aParams )
|
|
925 |
{
|
|
926 |
VerifyOrganizeParamsL( aEntryIds, aParams );
|
|
927 |
|
|
928 |
RPointerArray<CCaSqlQuery> sqlQueries;
|
|
929 |
CleanupResetAndDestroyPushL( sqlQueries );
|
|
930 |
|
|
931 |
TBool revereseInsertOrder = CaSqlQueryCreator::CreateOrganizeQueryL(
|
|
932 |
aEntryIds, aParams, iSqlDb, sqlQueries );
|
|
933 |
|
|
934 |
for( TInt i = 0; i < sqlQueries.Count(); i++ )
|
|
935 |
{
|
|
936 |
switch( sqlQueries[i]->Type() )
|
|
937 |
{
|
|
938 |
case CCaSqlQuery::EGroupTableRemove:
|
|
939 |
{
|
|
940 |
sqlQueries[i]->PrepareL();
|
|
941 |
sqlQueries[i]->BindValuesForOrganizeL( aEntryIds, aParams );
|
|
942 |
sqlQueries[i]->ExecuteL();
|
|
943 |
sqlQueries[i]->CloseStatement();
|
|
944 |
}
|
|
945 |
break;
|
|
946 |
|
|
947 |
case CCaSqlQuery::EGroupTableInsert:
|
|
948 |
{
|
|
949 |
sqlQueries[i]->PrepareL();
|
|
950 |
for( TInt j = 0; j < aEntryIds.Count(); j++ )
|
|
951 |
{
|
86
|
952 |
TInt k = (revereseInsertOrder) ?
|
85
|
953 |
(aEntryIds.Count() - 1) - j : j;
|
86
|
954 |
sqlQueries[i]->BindValuesForOrganizeL(
|
85
|
955 |
aEntryIds, aParams, aEntryIds[k] );
|
|
956 |
sqlQueries[i]->ExecuteL();
|
|
957 |
sqlQueries[i]->ResetStatement();
|
|
958 |
}
|
|
959 |
sqlQueries[i]->CloseStatement();
|
|
960 |
}
|
|
961 |
break;
|
|
962 |
}
|
|
963 |
}
|
|
964 |
|
|
965 |
CleanupStack::PopAndDestroy( &sqlQueries );
|
|
966 |
}
|
|
967 |
|
|
968 |
// ---------------------------------------------------------------------------
|
|
969 |
// CCASqLiteStorage::ExecuteTouchL( const TInt aEntryId )
|
|
970 |
//
|
|
971 |
// ---------------------------------------------------------------------------
|
|
972 |
//
|
107
|
973 |
void CCaSqLiteStorage::ExecuteTouchL( const TInt aEntryId, TBool aRemovable )
|
85
|
974 |
{
|
|
975 |
RPointerArray<CCaSqlQuery> sqlQuery;
|
|
976 |
CleanupResetAndDestroyPushL( sqlQuery );
|
|
977 |
|
107
|
978 |
CaSqlQueryCreator::CreateTouchQueryL( sqlQuery, iSqlDb, aRemovable );
|
85
|
979 |
|
|
980 |
for( TInt i = 0; i < sqlQuery.Count(); i++ )
|
|
981 |
{
|
|
982 |
sqlQuery[i]->PrepareL();
|
127
|
983 |
sqlQuery[i]->BindValuesForTouchL( aEntryId );
|
85
|
984 |
sqlQuery[i]->ExecuteL();
|
|
985 |
sqlQuery[i]->CloseStatement();
|
|
986 |
}
|
|
987 |
|
|
988 |
CleanupStack::PopAndDestroy( &sqlQuery );
|
|
989 |
}
|
|
990 |
|
|
991 |
// ---------------------------------------------------------------------------
|
|
992 |
// ExecuteDbPropertyL( const TDesC& aProperty, TDes& aPropertyValue )
|
|
993 |
//
|
|
994 |
// ---------------------------------------------------------------------------
|
|
995 |
//
|
|
996 |
void CCaSqLiteStorage::ExecuteDbPropertyL( const TDesC& aProperty,
|
|
997 |
TDes& aPropertyValue )
|
|
998 |
{
|
|
999 |
CCaSqlQuery* sqlQuery = CCaSqlQuery::NewLC( iSqlDb );
|
|
1000 |
sqlQuery->SetQueryL( KSQLGetProperty );
|
|
1001 |
sqlQuery->PrepareL();
|
|
1002 |
sqlQuery->BindValuesForPropertyL( aProperty );
|
|
1003 |
sqlQuery->ExecutePropertyL( aPropertyValue );
|
|
1004 |
sqlQuery->CloseStatement();
|
|
1005 |
CleanupStack::PopAndDestroy( sqlQuery );
|
|
1006 |
}
|
|
1007 |
|
|
1008 |
// ---------------------------------------------------------------------------
|
|
1009 |
// ExecuteSetDbPropertyL( const TDesC& aProperty, const TDesC& aPropertyValue )
|
|
1010 |
//
|
|
1011 |
// ---------------------------------------------------------------------------
|
|
1012 |
//
|
|
1013 |
void CCaSqLiteStorage::ExecuteSetDbPropertyL( const TDesC& aProperty,
|
|
1014 |
const TDesC& aPropertyValue )
|
|
1015 |
{
|
|
1016 |
CCaSqlQuery* sqlQuery = CCaSqlQuery::NewLC( iSqlDb );
|
|
1017 |
sqlQuery->SetQueryL( KSQLUpdateProperty );
|
|
1018 |
sqlQuery->PrepareL();
|
|
1019 |
sqlQuery->BindValuesForPropertyUpdateL( aProperty, aPropertyValue );
|
|
1020 |
sqlQuery->ExecuteL();
|
|
1021 |
sqlQuery->CloseStatement();
|
|
1022 |
CleanupStack::PopAndDestroy( sqlQuery );
|
|
1023 |
}
|
|
1024 |
|
|
1025 |
// ---------------------------------------------------------------------------
|
|
1026 |
// CCASqLiteStorage::VerifyOrganizeParamsL( const RArray<TInt>& aEntryIds,
|
|
1027 |
// TCaOperationParams aParams);
|
|
1028 |
//
|
|
1029 |
// ---------------------------------------------------------------------------
|
|
1030 |
//
|
|
1031 |
void CCaSqLiteStorage::VerifyOrganizeParamsL( const RArray<TInt>& aEntryIds,
|
|
1032 |
TCaOperationParams aParams )
|
|
1033 |
{
|
|
1034 |
switch( aParams.iOperationType )
|
|
1035 |
{
|
|
1036 |
case TCaOperationParams::ERemove:
|
|
1037 |
{
|
|
1038 |
CCaSqlQuery * query = CCaSqlQuery::NewLC( iSqlDb );
|
|
1039 |
CaSqlQueryCreator::PopulateQueryWithIdListL( aEntryIds.Count(),
|
|
1040 |
query, KSQLOrganizeGetEntryIdCountFromGroup );
|
|
1041 |
|
|
1042 |
query->PrepareL();
|
|
1043 |
query->BindValuesForOrganizeL( aEntryIds, aParams );
|
|
1044 |
TInt dbEntryCount;
|
|
1045 |
query->ExecuteL( dbEntryCount );
|
|
1046 |
query->CloseStatement();
|
127
|
1047 |
|
85
|
1048 |
if( dbEntryCount < aEntryIds.Count() )
|
|
1049 |
{
|
|
1050 |
User::Leave( KErrArgument );
|
|
1051 |
}
|
|
1052 |
|
|
1053 |
CleanupStack::PopAndDestroy( query );
|
|
1054 |
break;
|
|
1055 |
}
|
|
1056 |
case TCaOperationParams::EInsert:
|
|
1057 |
{
|
|
1058 |
CCaSqlQuery * query = CCaSqlQuery::NewLC( iSqlDb );
|
|
1059 |
CaSqlQueryCreator::PopulateQueryWithIdListL( 1, query,
|
|
1060 |
KSQLOrganizeGetEntryIdCountFromGroup );
|
|
1061 |
RArray<TInt> id;
|
|
1062 |
CleanupClosePushL( id );
|
|
1063 |
id.AppendL( aParams.iBeforeEntryId );
|
|
1064 |
|
|
1065 |
query->PrepareL();
|
|
1066 |
query->BindValuesForOrganizeL( id, aParams );
|
|
1067 |
TInt dbEntryCount;
|
|
1068 |
query->ExecuteL( dbEntryCount );
|
|
1069 |
query->CloseStatement();
|
|
1070 |
if( dbEntryCount == 0 )
|
|
1071 |
{
|
|
1072 |
User::Leave( KErrArgument );
|
|
1073 |
}
|
|
1074 |
|
|
1075 |
CleanupStack::PopAndDestroy( &id );
|
|
1076 |
CleanupStack::PopAndDestroy( query );
|
|
1077 |
break;
|
|
1078 |
}
|
|
1079 |
case TCaOperationParams::EPrepend:
|
|
1080 |
case TCaOperationParams::EAppend:
|
|
1081 |
default:
|
|
1082 |
{
|
|
1083 |
break;
|
|
1084 |
}
|
|
1085 |
}
|
|
1086 |
}
|
|
1087 |
|
|
1088 |
// ---------------------------------------------------------------------------
|
|
1089 |
// CCASqLiteStorage::SetEntriesInProperOrderL
|
|
1090 |
// ---------------------------------------------------------------------------
|
|
1091 |
//
|
|
1092 |
void CCaSqLiteStorage::SetEntriesInProperOrderL(
|
|
1093 |
const RArray<TInt>& aEntryIds,
|
|
1094 |
RPointerArray<CCaInnerEntry>& aResultContainer )
|
|
1095 |
{
|
|
1096 |
for( TInt i = 0; i < aEntryIds.Count(); i++ )
|
|
1097 |
{
|
|
1098 |
for( TInt j = i + 1; j < aResultContainer.Count(); j++ )
|
|
1099 |
{
|
|
1100 |
if( aEntryIds[i] == aResultContainer[j]->GetId() )
|
|
1101 |
{
|
|
1102 |
CCaInnerEntry* temporary( NULL );
|
|
1103 |
temporary = aResultContainer[i];
|
|
1104 |
aResultContainer[i] = aResultContainer[j];
|
|
1105 |
aResultContainer[j] = temporary;
|
|
1106 |
break;
|
|
1107 |
}
|
|
1108 |
}
|
|
1109 |
}
|
|
1110 |
}
|
|
1111 |
|
98
|
1112 |
|