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: CASqlQueryCreator implementation
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <e32cmn.h>
|
|
19 |
#include <badesca.h>
|
|
20 |
|
|
21 |
#include "casqlquerycreator.h"
|
|
22 |
#include "casqlcommands.h"
|
|
23 |
#include "cainnerentry.h"
|
|
24 |
#include "cainnerquery.h"
|
|
25 |
#include "caarraycleanup.inl"
|
|
26 |
#include "casqlquery.h"
|
|
27 |
#include "cadebug.h"
|
|
28 |
#include "cadef.h"
|
|
29 |
#include "caoperationparams.h"
|
|
30 |
|
|
31 |
|
|
32 |
// ---------------------------------------------------------------------------
|
|
33 |
//
|
|
34 |
// ---------------------------------------------------------------------------
|
|
35 |
//
|
|
36 |
void CaSqlQueryCreator::CreateAddQueryL( CCaInnerEntry* aEntry,
|
|
37 |
RPointerArray<CCaSqlQuery>& aSqlQuery, RSqlDatabase& aSqlDb )
|
|
38 |
{
|
|
39 |
DEBUG(("_CA_:CASqlQueryCreator::CreateAddQueryL"));
|
|
40 |
CCaSqlQuery* queryIcon = CCaSqlQuery::NewLC( aSqlDb );
|
|
41 |
|
|
42 |
TIconType iconType = CaSqlQueryCreator::CheckIconType( aEntry );
|
|
43 |
|
|
44 |
if( iconType == EProperIcon )
|
|
45 |
{
|
|
46 |
CreateAddIconQueryL( aEntry, queryIcon, aSqlDb );
|
|
47 |
//add new icon to DB
|
|
48 |
aSqlQuery.AppendL( queryIcon );
|
|
49 |
CleanupStack::Pop( queryIcon );
|
|
50 |
}
|
|
51 |
else
|
|
52 |
{
|
|
53 |
// icon added to DB by another entry or not added
|
|
54 |
CleanupStack::PopAndDestroy( queryIcon );
|
|
55 |
queryIcon = NULL;
|
|
56 |
}
|
|
57 |
|
|
58 |
if( aEntry->GetId() != -1 )
|
|
59 |
{
|
|
60 |
// check if entry is new and has to be added to DB or just updated
|
|
61 |
CCaSqlQuery* query = CCaSqlQuery::NewLC( aSqlDb );
|
|
62 |
if( aEntry->GetId() > 0 )
|
|
63 |
{
|
|
64 |
//Update query is faster than replace query
|
|
65 |
CreateUpdateQueryEntryL( aEntry, query );
|
|
66 |
}
|
|
67 |
else
|
|
68 |
{
|
|
69 |
// check if entry's Uid was set
|
|
70 |
if( aEntry->GetUid() == 0 )
|
|
71 |
{
|
|
72 |
if( ( aEntry->GetIconId() == 0 ) && ( queryIcon == NULL ) )
|
|
73 |
{
|
|
74 |
query->SetQueryL(
|
|
75 |
KSQLInsertToEntryUniqueUidWithoutIcon );
|
|
76 |
}
|
|
77 |
else
|
|
78 |
{
|
|
79 |
query->SetQueryL( KSQLInsertToEntryUniqueUid );
|
|
80 |
}
|
|
81 |
}
|
|
82 |
else
|
|
83 |
{
|
|
84 |
if( ( aEntry->GetIconId() == 0 ) && ( queryIcon == NULL ) )
|
|
85 |
{
|
|
86 |
query->SetQueryL( KSQLInsertToEntryWithoutIcon );
|
|
87 |
}
|
|
88 |
else
|
|
89 |
{
|
|
90 |
query->SetQueryL( KSQLInsertToEntry );
|
|
91 |
}
|
|
92 |
}
|
|
93 |
}
|
|
94 |
query->SetTableType( CCaSqlQuery::EEntryTable );
|
|
95 |
aSqlQuery.AppendL( query );
|
|
96 |
CleanupStack::Pop( query );
|
|
97 |
}
|
|
98 |
// remove all entry's attributs from DB
|
|
99 |
CCaSqlQuery* query = CCaSqlQuery::NewLC( aSqlDb );
|
|
100 |
query->SetQueryL( KSQLDeleteAttribute );
|
|
101 |
aSqlQuery.Append( query );
|
|
102 |
query->SetTableType( CCaSqlQuery::EAttributeTable );
|
|
103 |
CleanupStack::Pop( query );
|
|
104 |
|
|
105 |
if( aEntry->GetAttributes().Count() > 0 )
|
|
106 |
{
|
|
107 |
CCaSqlQuery* query = CCaSqlQuery::NewLC( aSqlDb );
|
|
108 |
query->SetQueryL( KSQLInsertToAttribute );
|
|
109 |
aSqlQuery.AppendL( query );
|
|
110 |
query->SetTableType( CCaSqlQuery::EAttributeTable );
|
|
111 |
CleanupStack::Pop( query );
|
|
112 |
}
|
|
113 |
|
|
114 |
if( iconType == ENullIconToRemove )
|
|
115 |
{
|
|
116 |
RBuf queryRemoveIcon;
|
|
117 |
queryRemoveIcon.CleanupClosePushL();
|
|
118 |
queryRemoveIcon.CreateL( KSQLDeleteIconWhereIconId().Length() );
|
|
119 |
queryRemoveIcon.Append( KSQLDeleteIconWhereIconId );
|
|
120 |
queryRemoveIcon.ReAllocL( KSQLDeleteIconWhereIconId().Length() + KMaxIntNumLength );
|
|
121 |
queryRemoveIcon.AppendNum( aEntry->GetIconId() );
|
|
122 |
|
|
123 |
CCaSqlQuery* query = CCaSqlQuery::NewLC( aSqlDb );
|
|
124 |
query->SetQueryL( queryRemoveIcon );
|
|
125 |
aSqlQuery.AppendL( query );
|
|
126 |
query->SetTableType( CCaSqlQuery::EIconTable );
|
|
127 |
|
|
128 |
CleanupStack::Pop( query );
|
|
129 |
CleanupStack::PopAndDestroy( &queryRemoveIcon );
|
|
130 |
}
|
|
131 |
}
|
|
132 |
|
|
133 |
// ---------------------------------------------------------------------------
|
|
134 |
//
|
|
135 |
// ---------------------------------------------------------------------------
|
|
136 |
//
|
|
137 |
void CaSqlQueryCreator::CreateUpdateQueryEntryL(
|
|
138 |
const CCaInnerEntry* aEntry, CCaSqlQuery* aQuery )
|
|
139 |
{
|
|
140 |
DEBUG( ("_CA_:CASqlQueryCreator::CreateUpdateQueryEntryL") );
|
|
141 |
RBuf query;
|
|
142 |
query.CleanupClosePushL();
|
|
143 |
query.CreateL( KSQLUpdateEntry().Length() );
|
|
144 |
query.Append( KSQLUpdateEntry );
|
|
145 |
// text
|
|
146 |
if( aEntry->GetText().Length() != 0 )
|
|
147 |
{
|
|
148 |
query.ReAllocL( query.Length() + KSQLUpdateEntryText().Length()
|
|
149 |
+ KComma().Length() );
|
|
150 |
query.Append( KSQLUpdateEntryText );
|
|
151 |
query.Append( KComma );
|
|
152 |
}
|
|
153 |
// description
|
|
154 |
query.ReAllocL( query.Length() + KSQLUpdateEntryDescription().Length()
|
|
155 |
+ KComma().Length() );
|
|
156 |
query.Append( KSQLUpdateEntryDescription );
|
|
157 |
query.Append( KComma );
|
|
158 |
// role
|
|
159 |
query.ReAllocL( query.Length() + KSQLUpdateEntryRole().Length()
|
|
160 |
+ KComma().Length() );
|
|
161 |
query.Append( KSQLUpdateEntryRole );
|
|
162 |
query.Append( KComma );
|
|
163 |
// type_name
|
|
164 |
if( aEntry->GetEntryTypeName().Length() != 0 )
|
|
165 |
{
|
|
166 |
query.ReAllocL( query.Length() + KSQLUpdateEntryTypeName().Length()
|
|
167 |
+ KComma().Length() );
|
|
168 |
query.Append( KSQLUpdateEntryTypeName );
|
|
169 |
query.Append( KComma );
|
|
170 |
}
|
|
171 |
// id_icon
|
|
172 |
TIconType iconType = CaSqlQueryCreator::CheckIconType( aEntry );
|
|
173 |
if( iconType == ENullIconToRemove || iconType == ENullIcon )
|
|
174 |
{
|
|
175 |
query.ReAllocL( query.Length( ) +
|
|
176 |
KSQLUpdateEntryIdIconNull().Length() + KComma().Length() );
|
|
177 |
query.Append( KSQLUpdateEntryIdIconNull );
|
|
178 |
}
|
|
179 |
else
|
|
180 |
{
|
|
181 |
query.ReAllocL( query.Length( ) + KSQLUpdateEntryIdIcon().Length()
|
|
182 |
+ KComma().Length() );
|
|
183 |
query.Append( KSQLUpdateEntryIdIcon );
|
|
184 |
}
|
|
185 |
query.Append( KComma );
|
|
186 |
// check if entry's Uid was set
|
|
187 |
if( aEntry->GetUid() )
|
|
188 |
{
|
|
189 |
query.ReAllocL( query.Length() + KSQLUpdateEntryUid().Length()
|
|
190 |
+ KComma().Length() );
|
|
191 |
query.Append( KSQLUpdateEntryUid );
|
|
192 |
query.Append( KComma );
|
|
193 |
}
|
|
194 |
else
|
|
195 |
{
|
|
196 |
query.ReAllocL( query.Length() + KSQLUpdateEntryUidNULL().Length()
|
|
197 |
+ KComma().Length() );
|
|
198 |
query.Append( KSQLUpdateEntryUidNULL );
|
|
199 |
query.Append( KComma );
|
|
200 |
}
|
|
201 |
//flags
|
|
202 |
query.ReAllocL( query.Length() + KSQLUpdateEntryFlags().Length()
|
|
203 |
+ KComma().Length() );
|
|
204 |
query.Append( KSQLUpdateEntryFlags );
|
|
205 |
|
|
206 |
query.ReAllocL( query.Length() + KSQLUpdateWhere().Length() );
|
|
207 |
query.Append( KSQLUpdateWhere );
|
|
208 |
|
|
209 |
aQuery->SetQueryL( query );
|
|
210 |
CleanupStack::PopAndDestroy( &query );
|
|
211 |
}
|
92
|
212 |
|
|
213 |
// ---------------------------------------------------------------------------
|
|
214 |
//
|
|
215 |
// ---------------------------------------------------------------------------
|
|
216 |
//
|
|
217 |
void CaSqlQueryCreator::CreateFindIconQueryL( CCaInnerEntry* aEntry,
|
|
218 |
CCaSqlQuery* aQuery)
|
|
219 |
{
|
|
220 |
RBuf iconQuery;
|
|
221 |
iconQuery.CleanupClosePushL();
|
|
222 |
iconQuery.CreateL( KSQLGetIconIdWhere );
|
|
223 |
|
|
224 |
if( aEntry->Icon()->FileName().Compare( KNullDesC ) )
|
|
225 |
{
|
|
226 |
iconQuery.ReAllocL( iconQuery.Length() + KSQLUpdateIconFileName().Length()
|
|
227 |
+ KAnd().Length() );
|
|
228 |
iconQuery.Append( KSQLUpdateIconFileName );
|
|
229 |
iconQuery.Append( KAnd );
|
|
230 |
}
|
|
231 |
else
|
|
232 |
{
|
|
233 |
iconQuery.ReAllocL( iconQuery.Length() + KSQLEmptyIconFileName().Length()
|
|
234 |
+ KAnd().Length() );
|
|
235 |
iconQuery.Append( KSQLEmptyIconFileName );
|
|
236 |
iconQuery.Append( KAnd );
|
|
237 |
}
|
|
238 |
|
|
239 |
if( aEntry->Icon()->SkinId().Compare( KNullDesC ) )
|
|
240 |
{
|
|
241 |
iconQuery.ReAllocL( iconQuery.Length() + KSQLUpdateIconSkinId().Length()
|
|
242 |
+ KAnd().Length() );
|
|
243 |
iconQuery.Append( KSQLUpdateIconSkinId );
|
|
244 |
iconQuery.Append( KAnd );
|
|
245 |
}
|
|
246 |
else
|
|
247 |
{
|
|
248 |
iconQuery.ReAllocL( iconQuery.Length() + KSQLEmptyIconSkinId().Length()
|
|
249 |
+ KAnd().Length() );
|
|
250 |
iconQuery.Append( KSQLEmptyIconSkinId );
|
|
251 |
iconQuery.Append( KAnd );
|
|
252 |
}
|
|
253 |
|
|
254 |
if( aEntry->Icon()->ApplicationId().Compare( KNullDesC ) )
|
|
255 |
{
|
|
256 |
iconQuery.ReAllocL( iconQuery.Length() + KSQLUpdateIconAppId().Length()
|
|
257 |
+ KAnd().Length() );
|
|
258 |
iconQuery.Append( KSQLUpdateIconAppId );
|
|
259 |
iconQuery.Append( KAnd );
|
|
260 |
}
|
|
261 |
else
|
|
262 |
{
|
|
263 |
iconQuery.ReAllocL( iconQuery.Length() + KSQLEmptyIconAppId().Length()
|
|
264 |
+ KAnd().Length() );
|
|
265 |
iconQuery.Append( KSQLEmptyIconAppId );
|
|
266 |
iconQuery.Append( KAnd );
|
|
267 |
}
|
|
268 |
|
|
269 |
if (!iconQuery.Right(KAnd().Length()).Compare(KAnd))
|
|
270 |
{
|
|
271 |
iconQuery.Delete( iconQuery.Length() - KAnd().Length(), KAnd().Length() );
|
|
272 |
}
|
|
273 |
|
|
274 |
aQuery->SetQueryL( iconQuery );
|
|
275 |
CleanupStack::PopAndDestroy( &iconQuery );
|
|
276 |
}
|
|
277 |
|
85
|
278 |
// ---------------------------------------------------------------------------
|
|
279 |
//
|
|
280 |
// ---------------------------------------------------------------------------
|
|
281 |
//
|
|
282 |
void CaSqlQueryCreator::CreateAddIconQueryForNewL( CCaInnerEntry* aEntry,
|
|
283 |
CCaSqlQuery* aQuery, RSqlDatabase& aSqlDb )
|
|
284 |
{
|
|
285 |
DEBUG( ("_CA_:CASqlQueryCreator::CreateAddIconQueryForNewL") );
|
|
286 |
CCaSqlQuery* query = CCaSqlQuery::NewLC( aSqlDb );
|
92
|
287 |
|
|
288 |
CreateFindIconQueryL(aEntry, query);
|
85
|
289 |
query->SetTableType( CCaSqlQuery::EIconTable );
|
|
290 |
query->PrepareL();
|
|
291 |
query->BindValuesForGetIconL( aEntry );
|
|
292 |
TInt idIcon( 0 );
|
|
293 |
query->ExecuteL( idIcon );
|
|
294 |
CleanupStack::PopAndDestroy( query );
|
|
295 |
|
|
296 |
if( idIcon == 0 )
|
|
297 |
{
|
|
298 |
// entry's icon data is not in DB
|
92
|
299 |
if( ( aEntry->Icon()->FileName().Length() != 0 ) ||
|
|
300 |
( aEntry->Icon()->SkinId().Length() != 0 ) ||
|
|
301 |
( aEntry->Icon()->ApplicationId().Length() != 0 )
|
88
|
302 |
)
|
85
|
303 |
{
|
|
304 |
// icon is not null, so that insert it to storage
|
|
305 |
aQuery->SetQueryL( KSQLInsertToIcon );
|
|
306 |
aQuery->SetTableType( CCaSqlQuery::EIconTable );
|
|
307 |
}
|
|
308 |
else
|
|
309 |
{
|
|
310 |
// icon is null
|
|
311 |
aQuery->SetTableType( CCaSqlQuery::ENoTableType );
|
|
312 |
}
|
|
313 |
}
|
|
314 |
else if( idIcon > 0 )
|
|
315 |
{
|
|
316 |
aEntry->SetIconId( idIcon );
|
|
317 |
aQuery->SetTableType( CCaSqlQuery::ENoTableType );
|
|
318 |
}
|
|
319 |
}
|
92
|
320 |
|
85
|
321 |
// ---------------------------------------------------------------------------
|
|
322 |
//
|
|
323 |
// ---------------------------------------------------------------------------
|
|
324 |
//
|
|
325 |
void CaSqlQueryCreator::CreateAddIconQueryForUpdateL(CCaInnerEntry* aEntry,
|
|
326 |
CCaSqlQuery* aQuery, RSqlDatabase& aSqlDb )
|
|
327 |
{
|
|
328 |
DEBUG( ("_CA_:CASqlQueryCreator::CreateAddIconQueryForUpdateL") );
|
|
329 |
CCaSqlQuery* query = CCaSqlQuery::NewLC( aSqlDb );
|
|
330 |
query->SetQueryL( KSQLGetIconDataByIdIcon );
|
|
331 |
query->SetTableType( CCaSqlQuery::EIconTable );
|
|
332 |
|
|
333 |
query->PrepareL();
|
|
334 |
query->BindValuesForGetEntriesL( aEntry );
|
92
|
335 |
|
|
336 |
CCaInnerIconDescription* innerIcon = CCaInnerIconDescription::NewLC();
|
|
337 |
|
|
338 |
query->ExecuteL( innerIcon );
|
85
|
339 |
query->CloseStatement();
|
92
|
340 |
if( !( !innerIcon->FileName().Compare( aEntry->Icon()->FileName() )
|
|
341 |
&& (!innerIcon->SkinId().Compare( aEntry->Icon()->SkinId() ))
|
|
342 |
&& (!innerIcon->ApplicationId().Compare( aEntry->Icon()->ApplicationId() ))
|
88
|
343 |
) )
|
85
|
344 |
{
|
|
345 |
// entry's icon data is updated
|
|
346 |
// if icon is used by another entry(s), new icon'll added to DB and
|
|
347 |
// new Id_Icon'll set to entry, otherwise it'll just updated
|
|
348 |
query->SetQueryL( KSQLGetIconsItems );
|
|
349 |
query->SetTableType( CCaSqlQuery::EEntryTable );
|
|
350 |
|
|
351 |
query->PrepareL();
|
|
352 |
query->BindValuesForGetEntriesL( aEntry );
|
|
353 |
RPointerArray<CCaInnerEntry> innerEntries;
|
|
354 |
CleanupResetAndDestroyPushL( innerEntries );
|
|
355 |
TInt count = query->ExecuteL( innerEntries, CCaSqlQuery::EEntry );
|
|
356 |
query->CloseStatement();
|
|
357 |
if( count > 1 )
|
|
358 |
{
|
|
359 |
//icon's data is used by another entry(s)
|
|
360 |
aQuery->SetQueryL( KSQLInsertToIcon );
|
|
361 |
aQuery->SetTableType( CCaSqlQuery::EIconTable );
|
|
362 |
}
|
|
363 |
else
|
|
364 |
{
|
|
365 |
// icon's data is used just by this entry
|
|
366 |
CreateUpdateIconQueryL( aEntry, aQuery );
|
|
367 |
}
|
|
368 |
|
|
369 |
CleanupStack::PopAndDestroy( &innerEntries );
|
|
370 |
}
|
92
|
371 |
CleanupStack::PopAndDestroy( innerIcon );
|
|
372 |
|
85
|
373 |
CleanupStack::PopAndDestroy( query );
|
|
374 |
}
|
92
|
375 |
|
85
|
376 |
// ---------------------------------------------------------------------------
|
|
377 |
//
|
|
378 |
// ---------------------------------------------------------------------------
|
|
379 |
//
|
|
380 |
void CaSqlQueryCreator::CreateAddIconQueryL( CCaInnerEntry* aEntry,
|
|
381 |
CCaSqlQuery* aQuery, RSqlDatabase& aSqlDb )
|
|
382 |
{
|
|
383 |
DEBUG( ("_CA_:CASqlQueryCreator::CreateAddIconQueryL") );
|
|
384 |
// check if entry's icon id was set
|
|
385 |
if( aEntry->GetIconId() == 0 )
|
|
386 |
{
|
|
387 |
// if entry doesn't have id_icon yet
|
|
388 |
// check if entry's icon data doesn't exist in DB
|
|
389 |
CreateAddIconQueryForNewL( aEntry, aQuery, aSqlDb );
|
|
390 |
}
|
|
391 |
else if( aEntry->GetIconId() > 0 )
|
|
392 |
{
|
|
393 |
// entry has id_icon set
|
|
394 |
// check if entry's icon data are the same as in database
|
|
395 |
CreateAddIconQueryForUpdateL( aEntry, aQuery, aSqlDb );
|
|
396 |
}
|
|
397 |
}
|
92
|
398 |
|
85
|
399 |
// ---------------------------------------------------------------------------
|
|
400 |
//
|
|
401 |
// ---------------------------------------------------------------------------
|
|
402 |
//
|
|
403 |
void CaSqlQueryCreator::CreateUpdateIconQueryL(
|
|
404 |
const CCaInnerEntry* aEntry, CCaSqlQuery* aQuery )
|
|
405 |
{
|
|
406 |
DEBUG(("_CA_:CASqlQueryCreator::CreateUpdateIconQueryL"));
|
|
407 |
RBuf query;
|
|
408 |
query.CleanupClosePushL();
|
|
409 |
query.CreateL( KSQLUpdateIcon().Length() );
|
|
410 |
query.Append( KSQLUpdateIcon );
|
92
|
411 |
if( aEntry->Icon()->FileName().Compare( KNullDesC ) )
|
85
|
412 |
{
|
|
413 |
query.ReAllocL( query.Length() + KSQLUpdateIconFileName().Length()
|
|
414 |
+ KComma().Length() );
|
|
415 |
query.Append( KSQLUpdateIconFileName );
|
|
416 |
query.Append( KComma );
|
|
417 |
}
|
92
|
418 |
if( aEntry->Icon()->SkinId().Compare( KNullDesC ) )
|
85
|
419 |
{
|
88
|
420 |
query.ReAllocL( query.Length() + KSQLUpdateIconSkinId().Length()
|
85
|
421 |
+ KComma().Length() );
|
88
|
422 |
query.Append( KSQLUpdateIconSkinId );
|
85
|
423 |
query.Append( KComma );
|
|
424 |
}
|
92
|
425 |
if( aEntry->Icon()->ApplicationId().Compare(KNullDesC) )
|
85
|
426 |
{
|
88
|
427 |
query.ReAllocL( query.Length() + KSQLUpdateIconAppId().Length()
|
85
|
428 |
+ KComma().Length() );
|
88
|
429 |
query.Append( KSQLUpdateIconAppId );
|
85
|
430 |
}
|
|
431 |
if( !query.Right( KComma().Length() ).Compare( KComma ) )
|
|
432 |
{
|
92
|
433 |
query.Delete( query.Length() - KComma().Length(), KComma().Length() );
|
85
|
434 |
}
|
|
435 |
// add WHERE expr
|
|
436 |
query.ReAllocL( query.Length() + KSQLUpdateIconWhere().Length() );
|
|
437 |
query.Append( KSQLUpdateIconWhere );
|
|
438 |
|
|
439 |
aQuery->SetQueryL( query );
|
|
440 |
aQuery->SetTableType( CCaSqlQuery::EIconTable );
|
|
441 |
|
|
442 |
CleanupStack::PopAndDestroy( &query );
|
|
443 |
}
|
|
444 |
|
|
445 |
// ---------------------------------------------------------------------------
|
|
446 |
//
|
|
447 |
// ---------------------------------------------------------------------------
|
|
448 |
//
|
|
449 |
void CaSqlQueryCreator::CreateGetEntriesQueryL(
|
|
450 |
const CCaInnerQuery* aQuery, CCaSqlQuery* aSqlQuery )
|
|
451 |
{
|
|
452 |
DEBUG( ("_CA_:CASqlQueryCreator::CreateGetEntriesQueryL") );
|
|
453 |
if( aQuery->GetIds().Count() >= 1 )
|
|
454 |
{
|
|
455 |
// just one or more ids so select just those items. easy case.
|
|
456 |
CreateGetEntriesQueryByIdL( aQuery->GetIds().Count(), aSqlQuery );
|
|
457 |
}
|
|
458 |
else
|
|
459 |
{
|
|
460 |
// create a sql query for a list of items to return.
|
|
461 |
CreateGetEntriesQueryByQueryL( aQuery, aSqlQuery );
|
|
462 |
}
|
|
463 |
|
|
464 |
}
|
|
465 |
|
|
466 |
// ---------------------------------------------------------------------------
|
|
467 |
//
|
|
468 |
// ---------------------------------------------------------------------------
|
|
469 |
//
|
|
470 |
void CaSqlQueryCreator::CreateGetParentsIdsQueryL(
|
|
471 |
const RArray<TInt>& aEntryIdArray, CCaSqlQuery* aSqlQuery,
|
|
472 |
const RArray<TInt>& aParentIdArray )
|
|
473 |
{
|
|
474 |
DEBUG(("_CA_:CASqlQueryCreator::CreateGetParentsIdsQueryL"));
|
|
475 |
RBuf entryIdList;
|
|
476 |
entryIdList.CleanupClosePushL();
|
|
477 |
CreateIdListL( aEntryIdArray.Count(), entryIdList, KSQLGEEntryId );
|
|
478 |
RBuf parentIdList;
|
|
479 |
parentIdList.CleanupClosePushL();
|
|
480 |
CreateIdListL( aParentIdArray.Count(), parentIdList, KSQLGEIdGroup );
|
|
481 |
|
|
482 |
RBuf query;
|
|
483 |
query.CleanupClosePushL();
|
|
484 |
query.CreateL( KSQLGetParentIds().Length() + entryIdList.Length() );
|
|
485 |
query.AppendFormat( KSQLGetParentIds, &entryIdList );
|
|
486 |
if( aParentIdArray.Count() > 0 )
|
|
487 |
{
|
|
488 |
query.ReAllocL( query.Length() + parentIdList.Length()
|
|
489 |
+ KSQLNotINIds().Length() );
|
|
490 |
query.AppendFormat( KSQLNotINIds, &parentIdList );
|
|
491 |
}
|
|
492 |
|
|
493 |
aSqlQuery->SetQueryL( query );
|
|
494 |
|
|
495 |
CleanupStack::PopAndDestroy( &query );
|
|
496 |
CleanupStack::PopAndDestroy( &parentIdList );
|
|
497 |
CleanupStack::PopAndDestroy( &entryIdList );
|
|
498 |
}
|
|
499 |
|
|
500 |
// ---------------------------------------------------------------------------
|
|
501 |
//
|
|
502 |
// ---------------------------------------------------------------------------
|
|
503 |
//
|
|
504 |
void CaSqlQueryCreator::CreateGetAttributesQueryL(
|
|
505 |
const TInt aIdEntryCount, CCaSqlQuery* aSqlQuery )
|
|
506 |
{
|
|
507 |
DEBUG(("_CA_:CASqlQueryCreator::CreateGetAttributesQueryL"));
|
|
508 |
PopulateQueryWithIdListL( aIdEntryCount, aSqlQuery,
|
|
509 |
KSQLGetAttributesByEntryId );
|
|
510 |
}
|
|
511 |
|
|
512 |
// ---------------------------------------------------------------------------
|
|
513 |
//
|
|
514 |
// ---------------------------------------------------------------------------
|
|
515 |
//
|
|
516 |
void CaSqlQueryCreator::CreateRemoveQueryL(
|
|
517 |
RPointerArray<CCaSqlQuery>& aSqlQuery, RSqlDatabase& aSqlDb )
|
|
518 |
{
|
|
519 |
DEBUG(("_CA_:CASqlQueryCreator::CreateRemoveQueryL"));
|
|
520 |
|
|
521 |
CCaSqlQuery* query = CCaSqlQuery::NewLC( aSqlDb );
|
|
522 |
query->SetQueryL( KSQLDeleteLaunch );
|
|
523 |
aSqlQuery.Append( query );
|
|
524 |
CleanupStack::Pop( query );
|
|
525 |
|
|
526 |
query = CCaSqlQuery::NewLC( aSqlDb );
|
|
527 |
query->SetQueryL( KSQLDeleteEntryFromGroup );
|
|
528 |
aSqlQuery.Append( query );
|
|
529 |
CleanupStack::Pop( query );
|
|
530 |
|
|
531 |
query = CCaSqlQuery::NewLC( aSqlDb );
|
|
532 |
query->SetQueryL( KSQLDeleteGroupFromGroup );
|
|
533 |
aSqlQuery.Append( query );
|
|
534 |
CleanupStack::Pop( query );
|
|
535 |
|
|
536 |
query = CCaSqlQuery::NewLC( aSqlDb );
|
|
537 |
query->SetQueryL( KSQLDeleteAttribute );
|
|
538 |
aSqlQuery.Append( query );
|
|
539 |
CleanupStack::Pop( query );
|
|
540 |
|
|
541 |
query = CCaSqlQuery::NewLC( aSqlDb );
|
|
542 |
query->SetQueryL( KSQLDeleteEntry );
|
|
543 |
aSqlQuery.Append( query );
|
|
544 |
CleanupStack::Pop( query );
|
|
545 |
|
|
546 |
query = CCaSqlQuery::NewLC( aSqlDb );
|
|
547 |
query->SetQueryL( KSQLDeleteIcon );
|
|
548 |
query->SetTableType( CCaSqlQuery::EIconTable );
|
|
549 |
aSqlQuery.Append( query );
|
|
550 |
CleanupStack::Pop( query );
|
|
551 |
}
|
|
552 |
|
|
553 |
// ---------------------------------------------------------------------------
|
|
554 |
//
|
|
555 |
// ---------------------------------------------------------------------------
|
|
556 |
//
|
|
557 |
void CaSqlQueryCreator::CreateTouchQueryL(
|
|
558 |
RPointerArray<CCaSqlQuery>& aSqlQuery, RSqlDatabase& aSqlDb )
|
|
559 |
{
|
|
560 |
DEBUG(("_CA_:CASqlQueryCreator::CreateTouchQueryL"));
|
|
561 |
|
|
562 |
CCaSqlQuery* query = CCaSqlQuery::NewLC( aSqlDb );
|
|
563 |
query->SetQueryL( KSQLInsertToLaunch );
|
|
564 |
aSqlQuery.Append( query );
|
|
565 |
CleanupStack::Pop( query );
|
|
566 |
|
|
567 |
query = CCaSqlQuery::NewLC( aSqlDb );
|
|
568 |
query->SetQueryL( KSQLUpdateEntryUsedFlag );
|
|
569 |
aSqlQuery.Append( query );
|
|
570 |
CleanupStack::Pop( query );
|
|
571 |
}
|
|
572 |
|
|
573 |
// ---------------------------------------------------------------------------
|
|
574 |
//
|
|
575 |
// ---------------------------------------------------------------------------
|
|
576 |
//
|
94
|
577 |
void CaSqlQueryCreator::CreateLocalizationTableQueryL( CCaSqlQuery* aSqlQuery,
|
|
578 |
const TDesC& aStatement)
|
85
|
579 |
{
|
94
|
580 |
DEBUG(("_CA_:CASqlQueryCreator::CreateLocalizationTableQueryL"));
|
85
|
581 |
RBuf query;
|
|
582 |
query.CleanupClosePushL();
|
94
|
583 |
query.CreateL( aStatement.Length() );
|
|
584 |
query.Append( aStatement );
|
85
|
585 |
aSqlQuery->SetQueryL( query );
|
|
586 |
CleanupStack::PopAndDestroy( &query );
|
|
587 |
}
|
|
588 |
|
|
589 |
// ---------------------------------------------------------------------------
|
|
590 |
//
|
|
591 |
// ---------------------------------------------------------------------------
|
|
592 |
//
|
|
593 |
void CaSqlQueryCreator::CreateGetEntriesQueryByIdL(
|
|
594 |
const TInt aIdEntryCount, CCaSqlQuery* aSqlQuery )
|
|
595 |
{
|
|
596 |
DEBUG(("_CA_:CASqlQueryCreator::CreateGetEntriesQueryByIdL"));
|
|
597 |
PopulateQueryWithIdListL( aIdEntryCount, aSqlQuery,
|
|
598 |
KSQLGetListByEntryIds );
|
|
599 |
}
|
|
600 |
|
|
601 |
// ---------------------------------------------------------------------------
|
|
602 |
//
|
|
603 |
// ---------------------------------------------------------------------------
|
|
604 |
//
|
|
605 |
void CaSqlQueryCreator::PopulateQueryWithIdListL( const TInt aIdEntryCount,
|
|
606 |
CCaSqlQuery* aQuery, const TDesC& aSqlQueryText )
|
|
607 |
{
|
|
608 |
DEBUG(("_CA_:CASqlQueryCreator::PopulateQueryWithIdListL"));
|
|
609 |
RBuf entryIdList;
|
|
610 |
entryIdList.CleanupClosePushL();
|
|
611 |
|
|
612 |
CreateIdListL( aIdEntryCount, entryIdList, KSQLEntryId );
|
|
613 |
|
|
614 |
RBuf query;
|
|
615 |
query.CleanupClosePushL();
|
|
616 |
query.CreateL( aSqlQueryText.Length() + entryIdList.Length() );
|
|
617 |
query.AppendFormat( aSqlQueryText, &entryIdList );
|
|
618 |
|
|
619 |
aQuery->SetQueryL( query );
|
|
620 |
|
|
621 |
CleanupStack::PopAndDestroy( &query );
|
|
622 |
CleanupStack::PopAndDestroy( &entryIdList );
|
|
623 |
}
|
|
624 |
|
|
625 |
// ---------------------------------------------------------------------------
|
|
626 |
//
|
|
627 |
// ---------------------------------------------------------------------------
|
|
628 |
//
|
|
629 |
void CaSqlQueryCreator::CreateIdListL( const TInt aIdEntryCount,
|
|
630 |
RBuf& aEntryIdList, const TDesC& aColName )
|
|
631 |
{
|
|
632 |
DEBUG(("_CA_:CASqlQueryCreator::CreateIdListL"));
|
|
633 |
// Create an list of ids seperated by commas
|
|
634 |
if( aIdEntryCount > 0 )
|
|
635 |
{
|
|
636 |
aEntryIdList.CreateL( aIdEntryCount * ( aColName.Length()
|
|
637 |
+ KMaxIntNumLength ) - 1 );
|
|
638 |
for( TInt i = 0; i < aIdEntryCount; i++ )
|
|
639 |
{
|
|
640 |
aEntryIdList.Append( aColName );
|
|
641 |
aEntryIdList.AppendNum( i );
|
|
642 |
if( i != aIdEntryCount - 1 )
|
|
643 |
{
|
|
644 |
aEntryIdList.Append( KComma );
|
|
645 |
}
|
|
646 |
}
|
|
647 |
}
|
|
648 |
}
|
|
649 |
|
|
650 |
// ---------------------------------------------------------------------------
|
|
651 |
//
|
|
652 |
// ---------------------------------------------------------------------------
|
|
653 |
//
|
|
654 |
void CaSqlQueryCreator::CreateGetEntriesQueryByQueryL(
|
|
655 |
const CCaInnerQuery* aQuery, CCaSqlQuery* aSqlQuery )
|
|
656 |
{
|
|
657 |
DEBUG(("_CA_:CASqlQueryCreator::CreateGetEntriesQueryByQueryL"));
|
|
658 |
RBuf whereStatement;
|
|
659 |
whereStatement.CleanupClosePushL();
|
|
660 |
|
|
661 |
TUint flagsOn = aQuery->GetFlagsOn();
|
|
662 |
if( flagsOn != 0 )
|
|
663 |
{
|
|
664 |
whereStatement.ReAllocL( KAnd().Length() + whereStatement.Length()
|
|
665 |
+ KSQLGetEntryFlagsOn().Length() );
|
|
666 |
whereStatement.Append( KAnd );
|
|
667 |
whereStatement.Append( KSQLGetEntryFlagsOn );
|
|
668 |
}
|
|
669 |
|
|
670 |
TUint flagsOff = aQuery->GetFlagsOff();
|
|
671 |
if( flagsOff != 0 )
|
|
672 |
{
|
|
673 |
whereStatement.ReAllocL( KAnd().Length() + whereStatement.Length()
|
|
674 |
+ KSQLGetEntryFlagsOff().Length() );
|
|
675 |
whereStatement.Append( KAnd );
|
|
676 |
whereStatement.Append( KSQLGetEntryFlagsOff );
|
|
677 |
}
|
|
678 |
|
|
679 |
TInt role = aQuery->GetRole();
|
|
680 |
if( role != 0 )
|
|
681 |
{
|
|
682 |
whereStatement.ReAllocL( KAnd().Length() + whereStatement.Length()
|
|
683 |
+ KSQLGetEntryRole().Length() );
|
|
684 |
whereStatement.Append( KAnd );
|
|
685 |
whereStatement.Append( KSQLGetEntryRole );
|
|
686 |
}
|
|
687 |
|
|
688 |
TUint uid = aQuery->GetUid();
|
|
689 |
if( uid != 0 )
|
|
690 |
{
|
|
691 |
whereStatement.ReAllocL( KAnd().Length() + whereStatement.Length()
|
|
692 |
+ KSQLGetEntryUid().Length() );
|
|
693 |
whereStatement.Append( KAnd );
|
|
694 |
whereStatement.Append( KSQLGetEntryUid );
|
|
695 |
}
|
|
696 |
|
|
697 |
const CDesC16ArrayFlat* typeNames = aQuery->GetEntryTypeNames();
|
|
698 |
|
|
699 |
if( typeNames && typeNames->MdcaCount() > 0 )
|
|
700 |
{
|
|
701 |
RBuf typeNameWhereStatement;
|
|
702 |
typeNameWhereStatement.CleanupClosePushL();
|
|
703 |
for( TInt i = 0; i < typeNames->MdcaCount(); i++ )
|
|
704 |
{
|
|
705 |
typeNameWhereStatement.ReAllocL(
|
|
706 |
typeNameWhereStatement.Length()
|
|
707 |
+ typeNames->MdcaPoint( i ).Length()
|
|
708 |
+ KSingleQuotes().Length() * 2 + KComma().Length() );
|
|
709 |
typeNameWhereStatement.Append( KSingleQuotes );
|
|
710 |
typeNameWhereStatement.Append( typeNames->MdcaPoint( i ) );
|
|
711 |
typeNameWhereStatement.Append( KSingleQuotes );
|
|
712 |
if( i != typeNames->MdcaCount() - 1 )
|
|
713 |
{
|
|
714 |
typeNameWhereStatement.Append( KComma );
|
|
715 |
}
|
|
716 |
}
|
|
717 |
whereStatement.ReAllocL( KAnd().Length()
|
|
718 |
+ KSQLGetEntryTypeNames().Length()
|
|
719 |
+ typeNameWhereStatement.Length()
|
|
720 |
+ whereStatement.Length() );
|
|
721 |
whereStatement.Append( KAnd );
|
|
722 |
whereStatement.AppendFormat( KSQLGetEntryTypeNames,
|
|
723 |
&typeNameWhereStatement );
|
|
724 |
CleanupStack::PopAndDestroy( &typeNameWhereStatement );
|
|
725 |
}
|
89
|
726 |
|
|
727 |
if( aQuery->GetAttributes().Count() )
|
|
728 |
{
|
|
729 |
RBuf whereAttributes;
|
|
730 |
whereAttributes.CleanupClosePushL();
|
|
731 |
whereAttributes.CreateL( KEmpty );
|
|
732 |
|
|
733 |
for( TInt j=1; j <= aQuery->GetAttributes().Count(); j++ )
|
|
734 |
{
|
|
735 |
// at1.AT_NAME = 'Attribute_Name_1' AND at1.AT_VALUE = 'Attribute_VALUE_1'
|
|
736 |
TPtrC atrName( aQuery->GetAttributes().operator [](j-1)->Name() );
|
|
737 |
TPtrC atrValue( aQuery->GetAttributes().operator [](j-1)->Value() );
|
|
738 |
|
|
739 |
whereAttributes.ReAllocL( whereAttributes.Length() + 2 * KAnd().Length() +
|
|
740 |
4 * KSingleQuotes().Length() +
|
|
741 |
2 * KMaxIntNumLength +
|
|
742 |
2 * KAt().Length() + 2 * KDot().Length() + 2 * KEqual().Length() +
|
|
743 |
KColumnAttrName().Length() + KColumnAttrValue().Length() +
|
|
744 |
atrName.Length() + atrValue.Length() );
|
|
745 |
|
|
746 |
whereAttributes.Append( KAnd );
|
|
747 |
|
|
748 |
whereAttributes.Append( KAt );
|
|
749 |
whereAttributes.AppendNum( j );
|
|
750 |
whereAttributes.Append( KDot );
|
|
751 |
whereAttributes.Append( KColumnAttrName );
|
|
752 |
whereAttributes.Append( KEqual );
|
|
753 |
whereAttributes.Append( KSingleQuotes );
|
|
754 |
whereAttributes.Append( atrName );
|
|
755 |
whereAttributes.Append( KSingleQuotes );
|
|
756 |
|
|
757 |
whereAttributes.Append( KAnd );
|
|
758 |
|
|
759 |
whereAttributes.Append( KAt );
|
|
760 |
whereAttributes.AppendNum( j );
|
|
761 |
whereAttributes.Append( KDot );
|
|
762 |
whereAttributes.Append( KColumnAttrValue );
|
|
763 |
whereAttributes.Append( KEqual );
|
|
764 |
whereAttributes.Append( KSingleQuotes );
|
|
765 |
whereAttributes.Append( atrValue );
|
|
766 |
whereAttributes.Append( KSingleQuotes );
|
|
767 |
|
|
768 |
}
|
|
769 |
|
|
770 |
whereStatement.ReAllocL( whereStatement.Length() + whereAttributes.Length() );
|
|
771 |
whereStatement.Append( whereAttributes );
|
|
772 |
|
|
773 |
CleanupStack::PopAndDestroy( &whereAttributes );
|
|
774 |
}
|
|
775 |
|
|
776 |
RBuf leftJoins;
|
|
777 |
leftJoins.CleanupClosePushL();
|
|
778 |
leftJoins.CreateL( KEmpty );
|
|
779 |
if( aQuery->GetAttributes().Count() )
|
|
780 |
{
|
|
781 |
for( TInt j=1; j <= aQuery->GetAttributes().Count(); j++ )
|
|
782 |
{
|
|
783 |
// LEFT JOIN CA_ATTRIBUTE as at1 ON ENTRY_ID = at1.AT_ENTRY_ID
|
|
784 |
leftJoins.ReAllocL( leftJoins.Length() +
|
|
785 |
KLeftJoinCaAttrubute1().Length() + KMaxIntNumLength +
|
|
786 |
KLeftJoinCaAttrubute2().Length() + KMaxIntNumLength +
|
|
787 |
KLeftJoinCaAttrubute3().Length()
|
|
788 |
);
|
|
789 |
|
|
790 |
leftJoins.Append( KLeftJoinCaAttrubute1 );
|
|
791 |
leftJoins.AppendNum( j );
|
|
792 |
leftJoins.Append( KLeftJoinCaAttrubute2 );
|
|
793 |
leftJoins.AppendNum( j );
|
|
794 |
leftJoins.Append( KLeftJoinCaAttrubute3 );
|
|
795 |
}
|
|
796 |
}
|
|
797 |
|
|
798 |
|
|
799 |
whereStatement.ReAllocL( whereStatement.Length() +
|
|
800 |
KGroupBy().Length() + KColumnEntryId().Length() );
|
|
801 |
whereStatement.Append( KGroupBy );
|
|
802 |
whereStatement.Append( KColumnEntryId );
|
85
|
803 |
|
|
804 |
TInt groupId = aQuery->GetParentId();
|
|
805 |
RBuf query;
|
|
806 |
query.CleanupClosePushL();
|
|
807 |
if( groupId > 0 )
|
|
808 |
{
|
89
|
809 |
RBuf getListByParentId2withWhere;
|
|
810 |
getListByParentId2withWhere.CleanupClosePushL();
|
|
811 |
getListByParentId2withWhere.CreateL( KSQLGetListByParentId2().Length() + whereStatement.Length() );
|
|
812 |
getListByParentId2withWhere.AppendFormat( KSQLGetListByParentId2, &whereStatement );
|
|
813 |
|
|
814 |
query.ReAllocL( KSQLGetListByParentId1().Length() + leftJoins.Length() +
|
|
815 |
getListByParentId2withWhere.Length() );
|
|
816 |
query.Append( KSQLGetListByParentId1 );
|
|
817 |
query.Append( leftJoins );
|
|
818 |
query.Append( getListByParentId2withWhere );
|
|
819 |
CleanupStack::PopAndDestroy( &getListByParentId2withWhere );
|
85
|
820 |
}
|
99
|
821 |
else if ( aQuery->GetChildId() > 0 )
|
|
822 |
{
|
|
823 |
RBuf getListByCildIdwithWhere;
|
|
824 |
getListByCildIdwithWhere.CleanupClosePushL();
|
|
825 |
getListByCildIdwithWhere.CreateL( KSQLGetListByChildId().Length() + whereStatement.Length() );
|
|
826 |
getListByCildIdwithWhere.AppendFormat( KSQLGetListByChildId, &whereStatement );
|
|
827 |
|
|
828 |
query.ReAllocL( KSQLGetListByParentId1().Length() + leftJoins.Length() +
|
|
829 |
getListByCildIdwithWhere.Length() );
|
|
830 |
query.Append( KSQLGetListByParentId1 );
|
|
831 |
query.Append( leftJoins );
|
|
832 |
query.Append( getListByCildIdwithWhere );
|
|
833 |
CleanupStack::PopAndDestroy( &getListByCildIdwithWhere );
|
|
834 |
}
|
85
|
835 |
else
|
|
836 |
{
|
89
|
837 |
query.CreateL( KSQLGetList1().Length() );
|
|
838 |
query.Append( KSQLGetList1 );
|
|
839 |
query.ReAllocL( query.Length() + leftJoins.Length() + KSQLGetList2().Length() );
|
|
840 |
query.Append( leftJoins );
|
|
841 |
query.Append( KSQLGetList2 );
|
85
|
842 |
if( whereStatement.Length() >= KAnd().Length() )
|
|
843 |
{
|
|
844 |
TPtrC ptrWhereStatement( whereStatement.Right(
|
|
845 |
whereStatement.Length() - KAnd().Length() ) );
|
89
|
846 |
query.ReAllocL( query.Length() + KWhere().Length()
|
85
|
847 |
+ ptrWhereStatement.Length() );
|
89
|
848 |
|
85
|
849 |
query.Append( KWhere );
|
|
850 |
query.Append( ptrWhereStatement );
|
|
851 |
}
|
|
852 |
}
|
|
853 |
|
|
854 |
CCaInnerQuery::TSortAttribute sort = aQuery->GetSort();
|
|
855 |
ModifyQueryForSortOrderL( sort, query, groupId > 0 );
|
|
856 |
|
|
857 |
if( aQuery->GetCount() > 0 )
|
|
858 |
{
|
|
859 |
query.ReAllocL( query.Length() + KLimit().Length()
|
|
860 |
+ KMaxIntNumLength );
|
|
861 |
query.Append( KLimit );
|
|
862 |
TInt limitCount = aQuery->GetCount();
|
|
863 |
query.AppendNum( limitCount );
|
|
864 |
}
|
|
865 |
|
|
866 |
aSqlQuery->SetQueryL( query );
|
|
867 |
CleanupStack::PopAndDestroy( &query );
|
89
|
868 |
CleanupStack::PopAndDestroy( &leftJoins );
|
85
|
869 |
CleanupStack::PopAndDestroy( &whereStatement );
|
|
870 |
}
|
|
871 |
|
|
872 |
|
|
873 |
// ---------------------------------------------------------------------------
|
|
874 |
//
|
|
875 |
// ---------------------------------------------------------------------------
|
|
876 |
//
|
|
877 |
void CaSqlQueryCreator::CreateCustomSortQueryL(
|
|
878 |
const RArray<TInt>& aEntryIds,
|
|
879 |
RPointerArray<CCaSqlQuery>& aSqlQuery,
|
|
880 |
RSqlDatabase& aSqlDb )
|
|
881 |
{
|
|
882 |
for( TInt i = 0; i < aEntryIds.Count(); i++ )
|
|
883 |
{
|
|
884 |
CCaSqlQuery* query = CCaSqlQuery::NewLC( aSqlDb );
|
|
885 |
query->SetQueryL( KSQLUpdatePositionInGroup );
|
|
886 |
aSqlQuery.Append( query );
|
|
887 |
CleanupStack::Pop( query );
|
|
888 |
}
|
|
889 |
}
|
|
890 |
|
|
891 |
|
|
892 |
// ---------------------------------------------------------------------------
|
|
893 |
//
|
|
894 |
// ---------------------------------------------------------------------------
|
|
895 |
//
|
|
896 |
void CaSqlQueryCreator::ModifyQueryForSortOrderL(
|
|
897 |
const CCaInnerQuery::TSortAttribute aSortType, RBuf& aQuery,
|
|
898 |
TBool aSortByGroup )
|
|
899 |
{
|
|
900 |
DEBUG(("_CA_:CASqlQueryCreator::ModifyQueryForSortOrderL"));
|
|
901 |
switch ( aSortType )
|
|
902 |
{
|
|
903 |
case CCaInnerQuery::Name:
|
|
904 |
{
|
|
905 |
aQuery.ReAllocL( aQuery.Length()
|
|
906 |
+ KSQLSortOrderNameAsc().Length() );
|
|
907 |
aQuery.Append( KSQLSortOrderNameAsc );
|
|
908 |
break;
|
|
909 |
}
|
|
910 |
case CCaInnerQuery::NameDesc:
|
|
911 |
{
|
|
912 |
aQuery.ReAllocL( aQuery.Length()
|
|
913 |
+ KSQLSortOrderNameDesc().Length() );
|
|
914 |
aQuery.Append( KSQLSortOrderNameDesc );
|
|
915 |
break;
|
|
916 |
}
|
|
917 |
case CCaInnerQuery::CreatedTimestamp:
|
|
918 |
{
|
|
919 |
aQuery.ReAllocL( aQuery.Length()
|
|
920 |
+ KSQLSortOrderCreatedTimestampAsc().Length() );
|
|
921 |
aQuery.Append( KSQLSortOrderCreatedTimestampAsc );
|
|
922 |
break;
|
|
923 |
}
|
|
924 |
case CCaInnerQuery::CreatedTimestampDesc:
|
|
925 |
{
|
|
926 |
aQuery.ReAllocL( aQuery.Length()
|
|
927 |
+ KSQLSortOrderCreatedTimestampDesc().Length() );
|
|
928 |
aQuery.Append( KSQLSortOrderCreatedTimestampDesc );
|
|
929 |
break;
|
|
930 |
}
|
|
931 |
case CCaInnerQuery::MostUsed:
|
|
932 |
case CCaInnerQuery::MostUsedDesc:
|
|
933 |
case CCaInnerQuery::LastUsed:
|
|
934 |
case CCaInnerQuery::LastUsedDesc:
|
|
935 |
{
|
|
936 |
ModifyQueryForSortOrderLastMostUsedL( aSortType, aQuery );
|
|
937 |
break;
|
|
938 |
}
|
|
939 |
case CCaInnerQuery::DefaultDesc:
|
|
940 |
{
|
|
941 |
if( aSortByGroup )
|
|
942 |
{
|
|
943 |
aQuery.ReAllocL( aQuery.Length()
|
|
944 |
+ KSQLSortOrderDefaultDesc().Length() );
|
|
945 |
aQuery.Append( KSQLSortOrderDefaultDesc );
|
|
946 |
}
|
|
947 |
else
|
|
948 |
{
|
|
949 |
aQuery.ReAllocL( aQuery.Length()
|
|
950 |
+ KSQLSortOrderIdDesc().Length() );
|
|
951 |
aQuery.Append( KSQLSortOrderIdDesc );
|
|
952 |
}
|
|
953 |
break;
|
|
954 |
}
|
|
955 |
case CCaInnerQuery::Default:
|
|
956 |
default:
|
|
957 |
{
|
|
958 |
if( aSortByGroup )
|
|
959 |
{
|
|
960 |
aQuery.ReAllocL( aQuery.Length()
|
|
961 |
+ KSQLSortOrderDefault().Length() );
|
|
962 |
aQuery.Append( KSQLSortOrderDefault );
|
|
963 |
}
|
|
964 |
else
|
|
965 |
{
|
|
966 |
aQuery.ReAllocL( aQuery.Length()
|
|
967 |
+ KSQLSortOrderIdAsc().Length() );
|
|
968 |
aQuery.Append( KSQLSortOrderIdAsc );
|
|
969 |
}
|
|
970 |
break;
|
|
971 |
}
|
|
972 |
}
|
|
973 |
}
|
|
974 |
|
|
975 |
// ---------------------------------------------------------------------------
|
|
976 |
//
|
|
977 |
// ---------------------------------------------------------------------------
|
|
978 |
//
|
|
979 |
void CaSqlQueryCreator::ModifyQueryForSortOrderLastMostUsedL(
|
|
980 |
const CCaInnerQuery::TSortAttribute aSortType, RBuf& aQuery )
|
|
981 |
{
|
|
982 |
DEBUG(("_CA_:CASqlQueryCreator::ModifyQueryForSortOrderLastMostUsedL"));
|
|
983 |
|
|
984 |
RBuf descPart;
|
|
985 |
descPart.CleanupClosePushL();
|
|
986 |
if( aSortType == CCaInnerQuery::MostUsedDesc ||
|
|
987 |
aSortType == CCaInnerQuery::LastUsedDesc )
|
|
988 |
{
|
|
989 |
descPart.CreateL( KDesc );
|
|
990 |
}
|
|
991 |
else
|
|
992 |
{
|
|
993 |
descPart.CreateL( KNullDesC );
|
|
994 |
}
|
|
995 |
|
|
996 |
RBuf usageDataQuery;
|
|
997 |
usageDataQuery.CleanupClosePushL();
|
|
998 |
if( aSortType == CCaInnerQuery::MostUsed ||
|
|
999 |
aSortType == CCaInnerQuery::MostUsedDesc )
|
|
1000 |
{
|
|
1001 |
usageDataQuery.CreateL( KSQLGetMostUsed );
|
|
1002 |
}
|
|
1003 |
else
|
|
1004 |
{
|
|
1005 |
usageDataQuery.CreateL( KSQLGetLastUsed );
|
|
1006 |
}
|
|
1007 |
|
|
1008 |
RBuf newQuery;
|
|
1009 |
newQuery.CleanupClosePushL();
|
|
1010 |
newQuery.CreateL( KSQLGetListByLaunchDataPart1().Length() +
|
|
1011 |
KSQLGetListByLaunchDataPart1().Length() +
|
|
1012 |
KSQLGetListByLaunchDataPart3().Length() +
|
|
1013 |
usageDataQuery.Length() +
|
|
1014 |
descPart.Length() +
|
|
1015 |
aQuery.Length() );
|
|
1016 |
newQuery.Append( KSQLGetListByLaunchDataPart1 );
|
|
1017 |
newQuery.Append( aQuery );
|
|
1018 |
newQuery.Append( KSQLGetListByLaunchDataPart2 );
|
|
1019 |
newQuery.Append( usageDataQuery );
|
|
1020 |
newQuery.Append( KSQLGetListByLaunchDataPart3 );
|
|
1021 |
newQuery.Append( descPart );
|
|
1022 |
aQuery.Close();
|
|
1023 |
aQuery.CreateL( newQuery );
|
|
1024 |
|
|
1025 |
CleanupStack::PopAndDestroy( &newQuery );
|
|
1026 |
CleanupStack::PopAndDestroy( &usageDataQuery );
|
|
1027 |
CleanupStack::PopAndDestroy( &descPart );
|
|
1028 |
}
|
|
1029 |
|
|
1030 |
// ---------------------------------------------------------------------------
|
|
1031 |
//
|
|
1032 |
// ---------------------------------------------------------------------------
|
|
1033 |
//
|
|
1034 |
TBool CaSqlQueryCreator::CreateOrganizeQueryL(
|
|
1035 |
const RArray<TInt>& aEntryIds, TCaOperationParams aParams,
|
|
1036 |
RSqlDatabase& aSqlDb, RPointerArray<CCaSqlQuery>& aSqlQueries )
|
|
1037 |
{
|
|
1038 |
DEBUG(("_CA_:CASqlQueryCreator::CreateOrganizeQueryL"));
|
|
1039 |
TBool revereseInsertOrder = false;
|
|
1040 |
TInt idCount( aEntryIds.Count() );
|
|
1041 |
|
|
1042 |
CCaSqlQuery * query = CCaSqlQuery::NewLC( aSqlDb );
|
|
1043 |
PopulateQueryWithIdListL( idCount, query,
|
|
1044 |
KSQLOrganizeRemoveEntriesFromGroup );
|
|
1045 |
query->SetTableType( CCaSqlQuery::EGroupTableRemove );
|
|
1046 |
aSqlQueries.AppendL( query );
|
|
1047 |
CleanupStack::Pop( query );
|
|
1048 |
|
|
1049 |
switch( aParams.iOperationType )
|
|
1050 |
{
|
|
1051 |
case TCaOperationParams::EInsert:
|
|
1052 |
|
|
1053 |
{
|
|
1054 |
if( aParams.iBeforeEntryId <= 0 )
|
|
1055 |
{
|
|
1056 |
User::Leave( KErrNotSupported );
|
|
1057 |
}
|
|
1058 |
|
|
1059 |
query = CCaSqlQuery::NewLC( aSqlDb );
|
|
1060 |
query->SetQueryL( KSQLOrganizeInsertToGroupBasic );
|
|
1061 |
query->SetTableType( CCaSqlQuery::EGroupTableInsert );
|
|
1062 |
aSqlQueries.AppendL( query );
|
|
1063 |
CleanupStack::Pop( query );
|
|
1064 |
break;
|
|
1065 |
}
|
|
1066 |
case TCaOperationParams::EAppend:
|
|
1067 |
{
|
|
1068 |
CCaSqlQuery * query = CCaSqlQuery::NewLC( aSqlDb );
|
|
1069 |
query->SetQueryL( KSQLOrganizeAppendToGroup );
|
|
1070 |
query->SetTableType( CCaSqlQuery::EGroupTableInsert );
|
|
1071 |
aSqlQueries.AppendL( query );
|
|
1072 |
CleanupStack::Pop( query );
|
|
1073 |
break;
|
|
1074 |
}
|
|
1075 |
case TCaOperationParams::EPrepend:
|
|
1076 |
{
|
|
1077 |
query = CCaSqlQuery::NewLC( aSqlDb );
|
|
1078 |
query->SetQueryL( KSQLOrganizeInsertToGroupPrepend );
|
|
1079 |
query->SetTableType( CCaSqlQuery::EGroupTableInsert );
|
|
1080 |
aSqlQueries.AppendL( query );
|
|
1081 |
CleanupStack::Pop( query );
|
|
1082 |
|
|
1083 |
revereseInsertOrder = true;
|
|
1084 |
|
|
1085 |
break;
|
|
1086 |
}
|
|
1087 |
case TCaOperationParams::ERemove:
|
|
1088 |
{
|
|
1089 |
break;
|
|
1090 |
}
|
|
1091 |
default:
|
|
1092 |
{
|
|
1093 |
User::Leave( KErrNotSupported );
|
|
1094 |
}
|
|
1095 |
}
|
|
1096 |
return revereseInsertOrder;
|
|
1097 |
}
|
|
1098 |
|
|
1099 |
// ---------------------------------------------------------------------------
|
|
1100 |
//
|
|
1101 |
// ---------------------------------------------------------------------------
|
|
1102 |
//
|
|
1103 |
CaSqlQueryCreator::TIconType CaSqlQueryCreator::CheckIconType( const CCaInnerEntry* aEntry )
|
|
1104 |
{
|
|
1105 |
CaSqlQueryCreator::TIconType iconType;
|
88
|
1106 |
if(
|
92
|
1107 |
aEntry->Icon()->ApplicationId().Length() == 0 &&
|
|
1108 |
aEntry->Icon()->SkinId().Length() == 0 &&
|
|
1109 |
aEntry->Icon()->FileName().Length() == 0 )
|
85
|
1110 |
{
|
|
1111 |
if( aEntry->GetIconId() > 0 )
|
|
1112 |
{
|
|
1113 |
iconType = ENullIconToRemove;
|
|
1114 |
}
|
|
1115 |
else
|
|
1116 |
{
|
|
1117 |
iconType = ENullIcon;
|
|
1118 |
}
|
|
1119 |
}
|
|
1120 |
else
|
|
1121 |
{
|
|
1122 |
iconType = EProperIcon;
|
|
1123 |
}
|
|
1124 |
return iconType;
|
|
1125 |
}
|
|
1126 |
|
|
1127 |
|