111 mFileStore = CPermanentFileStore::OpenL(mFsSession, |
113 mFileStore = CPermanentFileStore::OpenL(mFsSession, |
112 databaseFile, |
114 databaseFile, |
113 EFileRead|EFileWrite); |
115 EFileRead|EFileWrite); |
114 mFileStore->SetTypeL(mFileStore->Layout()); /* Set file store type*/ |
116 mFileStore->SetTypeL(mFileStore->Layout()); /* Set file store type*/ |
115 mActDb.OpenL(mFileStore,mFileStore->Root()); |
117 mActDb.OpenL(mFileStore,mFileStore->Root()); |
116 CDbTableNames* tables = mActDb.TableNamesL(); |
|
117 CleanupStack::PushL(tables); |
|
118 if (0 == tables->Count()) { |
|
119 CreateTableL(); |
|
120 } |
|
121 CleanupStack::PopAndDestroy(tables); |
|
122 } |
118 } |
123 |
119 |
124 // ----------------------------------------------------------------------------- |
120 // ----------------------------------------------------------------------------- |
125 /** |
121 /** |
126 * Create database structure |
122 * Create database structure |
231 |
227 |
232 view.SetColL(colSet->ColNo(KFlagsColumnName), entry.Flags()); |
228 view.SetColL(colSet->ColNo(KFlagsColumnName), entry.Flags()); |
233 ExternalizeDataL(view, entry, colSet->ColNo(KDataColumnName)); |
229 ExternalizeDataL(view, entry, colSet->ColNo(KDataColumnName)); |
234 |
230 |
235 view.PutL(); |
231 view.PutL(); |
|
232 CleanupStack::PopAndDestroy(colSet);) |
|
233 |
236 if (KErrNone != errNo) { |
234 if (KErrNone != errNo) { |
237 view.Cancel(); |
235 view.Cancel(); |
238 User::Leave(errNo); |
236 User::Leave(errNo); |
239 } |
237 } |
240 CleanupStack::PopAndDestroy(colSet);) |
238 CleanupStack::PopAndDestroy(&view); |
241 |
239 } |
242 if (KErrNone != errNo) { |
240 |
243 view.Cancel(); |
241 // ----------------------------------------------------------------------------- |
244 User::Leave(errNo); |
242 /** |
245 } |
243 * Save activity |
|
244 * @param entry - activity data |
|
245 */ |
|
246 void CAfStorage::SaveActivityL(CAfEntry &entry) |
|
247 { |
|
248 // @todo check if this can be tidied up |
|
249 //verify if row already exists |
|
250 TInt errNo(KErrNone); |
|
251 RDbView view; |
|
252 CleanupClosePushL(view); |
|
253 TRAP(errNo, GetActivityForUpdateL(view, entry.ApplicationId(), entry.ActivityId())); |
|
254 if (KErrNone == errNo) { |
|
255 // update |
|
256 view.UpdateL(); |
|
257 TRAPD(errNo, |
|
258 CDbColSet* colSet = view.ColSetL(); |
|
259 CleanupStack::PushL(colSet); |
|
260 |
|
261 view.SetColL(colSet->ColNo(KFlagsColumnName), entry.Flags()); |
|
262 ExternalizeDataL(view, entry, colSet->ColNo(KDataColumnName)); |
|
263 |
|
264 view.PutL(); |
|
265 CleanupStack::PopAndDestroy(colSet);) |
|
266 |
|
267 if (KErrNone != errNo) { |
|
268 view.Cancel(); |
|
269 User::Leave(errNo); |
|
270 } |
|
271 } else { |
|
272 // insert |
|
273 |
|
274 //write table |
|
275 RDbTable table; |
|
276 CleanupClosePushL(table); |
|
277 User::LeaveIfError(table.Open(mActDb, KActivityTableName, table.EUpdatable)); |
|
278 CDbColSet *row = table.ColSetL(); |
|
279 CleanupStack::PushL(row); |
|
280 |
|
281 table.InsertL(); |
|
282 TRAP(errNo, |
|
283 table.SetColL(row->ColNo(KApplicationColumnName), TInt64(entry.ApplicationId())); |
|
284 table.SetColL(row->ColNo(KActivityColumnName), entry.ActivityId()); |
|
285 table.SetColL(row->ColNo(KFlagsColumnName), entry.Flags()); |
|
286 ExternalizeDataL(table, entry, row->ColNo(KDataColumnName)); |
|
287 table.PutL();) |
|
288 if (KErrNone != errNo) { |
|
289 table.Cancel(); |
|
290 User::Leave(errNo); |
|
291 } |
|
292 CleanupStack::PopAndDestroy(row); |
|
293 CleanupStack::PopAndDestroy(&table); |
|
294 } |
|
295 |
246 CleanupStack::PopAndDestroy(&view); |
296 CleanupStack::PopAndDestroy(&view); |
247 } |
297 } |
248 |
298 |
249 // ----------------------------------------------------------------------------- |
299 // ----------------------------------------------------------------------------- |
250 /** |
300 /** |