56
|
1 |
/*
|
|
2 |
* Copyright (c) 2006 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: This file implements the Location triggering container
|
|
15 |
* interface
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
|
|
20 |
#include "lbtdboperationao.h"
|
|
21 |
#include "lbtdbtriggersmanager.h"
|
|
22 |
#include "lbtlogger.h"
|
|
23 |
|
|
24 |
|
|
25 |
// ======== MEMBER FUNCTIONS ========
|
|
26 |
|
|
27 |
|
|
28 |
// ---------------------------------------------------------------------------
|
|
29 |
// The Symbian 2 phase constructor
|
|
30 |
// ---------------------------------------------------------------------------
|
|
31 |
//
|
|
32 |
CLbtDbOperationAO* CLbtDbOperationAO::NewL(
|
|
33 |
RDbDatabase& aDb,
|
|
34 |
CLbtDbTriggersManager* aObserver)
|
|
35 |
{
|
|
36 |
CLbtDbOperationAO* self = new( ELeave ) CLbtDbOperationAO(aDb, aObserver);
|
|
37 |
CleanupStack::PushL( self );
|
|
38 |
self->ConstructL();
|
|
39 |
CleanupStack::Pop( self );
|
|
40 |
return self;
|
|
41 |
}
|
|
42 |
|
|
43 |
|
|
44 |
// ---------------------------------------------------------------------------
|
|
45 |
// Execute a SQL query asynchronously
|
|
46 |
// ---------------------------------------------------------------------------
|
|
47 |
//
|
|
48 |
void CLbtDbOperationAO::ExecuteQuery(
|
|
49 |
RDbView& aView,
|
|
50 |
TDesC& aQuery)
|
|
51 |
{
|
|
52 |
FUNC_ENTER("CLbtDbOperationAO::ExecuteQuery");
|
|
53 |
if ( IsActive() )
|
|
54 |
{
|
|
55 |
// We are already executing an asynchronous operation so return error
|
|
56 |
TRAP_IGNORE( iObserver->DbSqlOperationCompletedL( KErrInUse ) );
|
|
57 |
return;
|
|
58 |
}
|
|
59 |
|
|
60 |
iView = &aView;
|
|
61 |
iView->Prepare( iDb, TDbQuery(aQuery, EDbCompareFolded) );
|
|
62 |
iView->Evaluate(iStatus);
|
|
63 |
SetActive();
|
|
64 |
iOperation = EDbSqlQuery;
|
|
65 |
}
|
|
66 |
|
|
67 |
|
|
68 |
// ---------------------------------------------------------------------------
|
|
69 |
// CLbtDbOperationAO::ExecuteSyncQuery
|
|
70 |
// ---------------------------------------------------------------------------
|
|
71 |
//
|
|
72 |
TInt CLbtDbOperationAO::ExecuteSyncQuery(
|
|
73 |
RDbView& aView,
|
|
74 |
TDesC& aQuery)
|
|
75 |
{
|
|
76 |
FUNC_ENTER("CLbtDbOperationAO::ExecuteSyncQuery");
|
|
77 |
TInt err = aView.Prepare( iDb, TDbQuery(aQuery, EDbCompareFolded),KDbUnlimitedWindow );
|
|
78 |
// This should evaluate the query fully
|
|
79 |
if ( err == KErrNone )
|
|
80 |
{
|
|
81 |
err = aView.EvaluateAll();
|
|
82 |
}
|
|
83 |
return err;
|
|
84 |
}
|
|
85 |
|
|
86 |
// ---------------------------------------------------------------------------
|
|
87 |
// Compact the database
|
|
88 |
// ---------------------------------------------------------------------------
|
|
89 |
//
|
|
90 |
void CLbtDbOperationAO::CompactDb()
|
|
91 |
{
|
|
92 |
FUNC_ENTER("CLbtDbOperationAO::CompactDb");
|
|
93 |
if ( IsActive() )
|
|
94 |
{
|
|
95 |
// We are already executing an asynchronous operation so return error
|
|
96 |
iObserver->DbIncrementalOperationCompleted( KErrInUse );
|
|
97 |
return;
|
|
98 |
}
|
|
99 |
|
|
100 |
TInt error = iDbIncrOp.Compact(iDb, iSteps);
|
|
101 |
if(error != KErrNone)
|
|
102 |
{
|
|
103 |
ERROR("iDbIncrOp.Compact returned %d", error);
|
|
104 |
iDbIncrOp.Close();
|
|
105 |
return;
|
|
106 |
}
|
|
107 |
error = iDbIncrOp.Next( iSteps );
|
|
108 |
iStatus = KRequestPending;
|
|
109 |
SetActive();
|
|
110 |
iOperation = EDbCompaction;
|
|
111 |
iStatus = KRequestPending;
|
|
112 |
TRequestStatus* status = &iStatus;
|
|
113 |
User::RequestComplete(status, error);
|
|
114 |
}
|
|
115 |
|
|
116 |
// ---------------------------------------------------------------------------
|
|
117 |
// DoCancel
|
|
118 |
// ---------------------------------------------------------------------------
|
|
119 |
//
|
|
120 |
TBool CLbtDbOperationAO::IsCompactionOngoing()
|
|
121 |
{
|
|
122 |
if( EDbCompaction == iOperation )
|
|
123 |
{
|
|
124 |
return ETrue;
|
|
125 |
}
|
|
126 |
return EFalse;
|
|
127 |
}
|
|
128 |
|
|
129 |
|
|
130 |
// ---------------------------------------------------------------------------
|
|
131 |
// DoCancel
|
|
132 |
// ---------------------------------------------------------------------------
|
|
133 |
//
|
|
134 |
void CLbtDbOperationAO::DoCancel()
|
|
135 |
{
|
|
136 |
FUNC_ENTER("CLbtDbOperationAO::DoCancel");
|
|
137 |
switch( iOperation )
|
|
138 |
{
|
|
139 |
case EDbSqlQuery:
|
|
140 |
iView->Cancel();
|
|
141 |
break;
|
|
142 |
case EDbCompaction:
|
|
143 |
// Nothing to do here since the step is already completed.
|
|
144 |
break;
|
|
145 |
default:
|
|
146 |
break;
|
|
147 |
}
|
|
148 |
iOperation = EDbOperationNone;
|
|
149 |
}
|
|
150 |
|
|
151 |
|
|
152 |
// ---------------------------------------------------------------------------
|
|
153 |
// RunL
|
|
154 |
// ---------------------------------------------------------------------------
|
|
155 |
//
|
|
156 |
void CLbtDbOperationAO::RunL()
|
|
157 |
{
|
|
158 |
FUNC_ENTER("CLbtDbOperationAO::RunL");
|
|
159 |
switch( iOperation )
|
|
160 |
{
|
|
161 |
case EDbSqlQuery:
|
|
162 |
if ( iStatus.Int() > 0 )
|
|
163 |
{
|
|
164 |
iView->Evaluate(iStatus);
|
|
165 |
SetActive();
|
|
166 |
}
|
|
167 |
else
|
|
168 |
{
|
|
169 |
iOperation = EDbOperationNone;
|
|
170 |
iObserver->DbSqlOperationCompletedL( iStatus.Int() );
|
|
171 |
}
|
|
172 |
break;
|
|
173 |
case EDbCompaction:
|
|
174 |
if ( iStatus.Int() == KErrNone && iSteps )
|
|
175 |
{
|
|
176 |
// If the steps till now have been successful and if there
|
|
177 |
// are more steps to be executed
|
|
178 |
TInt error = iDbIncrOp.Next( iSteps );
|
|
179 |
iStatus = KRequestPending;
|
|
180 |
SetActive();
|
|
181 |
TRequestStatus* status = &iStatus;
|
|
182 |
User::RequestComplete(status, error);
|
|
183 |
}
|
|
184 |
else
|
|
185 |
{
|
|
186 |
// Either the operation was fully completed or
|
|
187 |
// there was an error during database compaction.
|
|
188 |
// So just close the incremental operation and
|
|
189 |
// return the error (in case of the error).
|
|
190 |
iDbIncrOp.Close();
|
|
191 |
iOperation = EDbOperationNone;
|
|
192 |
iObserver->DbIncrementalOperationCompleted( iStatus.Int() );
|
|
193 |
}
|
|
194 |
break;
|
|
195 |
default:
|
|
196 |
// Nothing to do in this case
|
|
197 |
break;
|
|
198 |
}
|
|
199 |
}
|
|
200 |
|
|
201 |
|
|
202 |
// ---------------------------------------------------------------------------
|
|
203 |
// RunError
|
|
204 |
// ---------------------------------------------------------------------------
|
|
205 |
//
|
|
206 |
TInt CLbtDbOperationAO::RunError(TInt /*aError*/)
|
|
207 |
{
|
|
208 |
FUNC_ENTER("CLbtDbOperationAO::RunError");
|
|
209 |
// RunL doesn't have any Leaving calls. So no implementation here.
|
|
210 |
return KErrNone;
|
|
211 |
}
|
|
212 |
|
|
213 |
|
|
214 |
// ---------------------------------------------------------------------------
|
|
215 |
// Destructor
|
|
216 |
// ---------------------------------------------------------------------------
|
|
217 |
//
|
|
218 |
CLbtDbOperationAO::~CLbtDbOperationAO()
|
|
219 |
{
|
|
220 |
FUNC_ENTER("CLbtDbOperationAO::~CLbtDbOperationAO");
|
|
221 |
}
|
|
222 |
|
|
223 |
// ---------------------------------------------------------------------------
|
|
224 |
// Constructor
|
|
225 |
// ---------------------------------------------------------------------------
|
|
226 |
//
|
|
227 |
CLbtDbOperationAO::CLbtDbOperationAO(
|
|
228 |
RDbDatabase& aDb,
|
|
229 |
CLbtDbTriggersManager* aObserver)
|
|
230 |
:CActive(CActive::EPriorityStandard),
|
|
231 |
iDb(aDb),
|
|
232 |
iObserver(aObserver),
|
|
233 |
iOperation(EDbOperationNone)
|
|
234 |
{
|
|
235 |
CActiveScheduler::Add(this);
|
|
236 |
}
|
|
237 |
|
|
238 |
|
|
239 |
// ---------------------------------------------------------------------------
|
|
240 |
// The 2nd phase Symbian Constructor
|
|
241 |
// ---------------------------------------------------------------------------
|
|
242 |
//
|
|
243 |
void CLbtDbOperationAO::ConstructL()
|
|
244 |
{
|
|
245 |
}
|
|
246 |
|
|
247 |
|