symhelp/helpmodel/dbwriter/DBWRITER.CPP
changeset 0 1f04cf54edd8
equal deleted inserted replaced
-1:000000000000 0:1f04cf54edd8
       
     1 // Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "DBWRITER.H"
       
    17 #include <fbs.h>
       
    18 
       
    19 // User includes
       
    20 #include "HLPMODEL.H"
       
    21 #include "hlppanic.h"
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 enum TDbWriterPanic
       
    27 	{
       
    28 	EDbWriterNoRowAtCursor,
       
    29 	EDbWriterInvalidColumnType,
       
    30 	EDbWriterStoreNotOpen
       
    31 	};
       
    32 
       
    33 
       
    34 GLDEF_C void Panic(TDbWriterPanic aReason)
       
    35 	{
       
    36 	_LIT(KHlpPanicText, "DbWriter");
       
    37 	User::Panic(KHlpPanicText, aReason);
       
    38 	}
       
    39 
       
    40 
       
    41 
       
    42 //
       
    43 // Create the database
       
    44 //
       
    45 
       
    46 CHlpRowSet::CHlpRowSet(RDbView* aView)
       
    47 		: iView(aView)
       
    48 	{
       
    49 	}
       
    50 
       
    51 EXPORT_C CHlpRowSet::~CHlpRowSet()
       
    52 	{
       
    53 	iView->Close();
       
    54 	delete iView;
       
    55 	}
       
    56 
       
    57 EXPORT_C TBool CHlpRowSet::AtRow()
       
    58 	{
       
    59 	return iView->AtRow();
       
    60 	}
       
    61 
       
    62 EXPORT_C TBool CHlpRowSet::AtBeginning()
       
    63 	{
       
    64 	return iView->AtBeginning();
       
    65 	}
       
    66 
       
    67 EXPORT_C TBool CHlpRowSet::AtEnd()
       
    68 	{
       
    69 	return iView->AtEnd();
       
    70 	}
       
    71 
       
    72 EXPORT_C TBool CHlpRowSet::FirstL()
       
    73 	{
       
    74 	return iView->FirstL();
       
    75 	}
       
    76 
       
    77 EXPORT_C TBool CHlpRowSet::LastL()
       
    78 	{
       
    79 	return iView->LastL();
       
    80 	}
       
    81 
       
    82 EXPORT_C TInt CHlpRowSet::CountL()
       
    83 	{
       
    84 	return iView->CountL();
       
    85 	}
       
    86 
       
    87 EXPORT_C void CHlpRowSet::NextL()
       
    88 	{
       
    89 	iView->NextL();
       
    90 	}
       
    91 
       
    92 EXPORT_C void CHlpRowSet::PreviousL()
       
    93 	{
       
    94 	// coverity [unchecked_value]
       
    95 	iView->PreviousL();
       
    96 	}
       
    97 
       
    98 EXPORT_C RDbView* CHlpRowSet::View()
       
    99 	{
       
   100 	return iView;
       
   101 	}
       
   102 
       
   103 
       
   104 // This method could leave while getting column set for the rowset.
       
   105 // @leave KErrNoMemory not enough memory to carry out the operation
       
   106 
       
   107 EXPORT_C TDbColNo CHlpRowSet::MapColNameToColNo(const TDesC& aName)
       
   108 	{
       
   109 	CDbColSet* columnSet = iView->ColSetL();
       
   110 	CleanupStack::PushL(columnSet);
       
   111 	TInt columnNumber = columnSet->ColNo(aName);
       
   112 	CleanupStack::PopAndDestroy(columnSet);
       
   113 	return columnNumber;
       
   114 	}
       
   115 
       
   116 
       
   117 // This method could leave while getting column set for the rowset.
       
   118 // @leave KErrNoMemory not enough memory to carry out the operation
       
   119 
       
   120 EXPORT_C TDbColNo CHlpRowSet::MapColNameToColNo(const TDbCol& aCol)
       
   121 	{
       
   122 	CDbColSet* columnSet = iView->ColSetL();
       
   123 	CleanupStack::PushL(columnSet);
       
   124 	TInt columnNumber = columnSet->ColNo(aCol.iName);
       
   125 	CleanupStack::PopAndDestroy(columnSet);
       
   126 	return columnNumber;
       
   127 	}
       
   128 
       
   129 
       
   130 
       
   131 
       
   132 
       
   133 
       
   134 
       
   135 
       
   136 
       
   137 
       
   138 
       
   139 
       
   140 
       
   141 
       
   142 //
       
   143 // CHlpView class - Read only access to database views
       
   144 //
       
   145 
       
   146 CHlpView::CHlpView(RDbView* aView)
       
   147 :	CHlpRowSet(aView)
       
   148 	{
       
   149 	}
       
   150 
       
   151 CHlpView::~CHlpView()
       
   152 	{
       
   153 	View()->Close();
       
   154 	}
       
   155 
       
   156 void CHlpView::ConstructL()
       
   157 	{
       
   158 	}
       
   159 
       
   160 EXPORT_C CHlpView* CHlpView::NewLC(RDbView* aView)
       
   161 	{
       
   162 	CHlpView* self = new(ELeave)CHlpView(aView);
       
   163 	CleanupStack::PushL(self);
       
   164 	self->ConstructL();
       
   165 	return self;
       
   166 	}
       
   167 
       
   168 EXPORT_C CHlpView* CHlpView::NewL(RDbView* aView)
       
   169 	{
       
   170 	CHlpView* self = CHlpView::NewLC(aView);
       
   171 	CleanupStack::Pop();
       
   172 	return self;
       
   173 	}
       
   174 
       
   175 EXPORT_C void CHlpView::GetL()
       
   176 	{
       
   177 	View()->GetL();
       
   178 	}
       
   179 
       
   180 EXPORT_C void CHlpView::GetTextL(TDbColNo aCol, TDes& aText)
       
   181 	{
       
   182 	__ASSERT_ALWAYS(View()->AtRow(), Panic(EDbWriterNoRowAtCursor));
       
   183 	aText = View()->ColDes(aCol);
       
   184 	}
       
   185 
       
   186 EXPORT_C void CHlpView::GetRichTextL(TDbColNo aTextCol, TDbColNo aMarkupCol, CRichText& aRichText)
       
   187 	{
       
   188 	__ASSERT_ALWAYS(View()->AtRow(), Panic(EDbWriterNoRowAtCursor));
       
   189 	TPtrC ptr=View()->ColDes(aTextCol);
       
   190 	aRichText.InsertL(0, ptr);
       
   191 	GetMarkupL(aRichText, aMarkupCol);
       
   192 	}
       
   193 
       
   194 EXPORT_C void CHlpView::GetValL(TDbColNo aCol, TUint32& aValue)
       
   195 	{
       
   196 	__ASSERT_ALWAYS(View()->AtRow(), Panic(EDbWriterNoRowAtCursor));
       
   197 	aValue=View()->ColUint16(aCol);
       
   198 	}
       
   199 
       
   200 void CHlpView::GetMarkupL(CRichText& aRichText, TDbColNo aMarkupCol)
       
   201 	{
       
   202 	__ASSERT_ALWAYS(View()->ColDef(aMarkupCol).iType == EDbColLongBinary, Panic(EDbWriterInvalidColumnType));
       
   203 
       
   204 	RDbColReadStream blob;
       
   205 	blob.OpenLC(*View(), aMarkupCol);
       
   206 
       
   207 	CEmbeddedStore* embeddedStore = CEmbeddedStore::FromLC(blob);
       
   208 	RStoreReadStream markupStream;
       
   209 	markupStream.OpenLC(*embeddedStore, embeddedStore->Root());
       
   210 	aRichText.InternalizeMarkupDataL(markupStream);
       
   211 	iStoreResolver.iStore = embeddedStore;
       
   212 
       
   213 	aRichText.SetPictureFactory(iPictureFactory, &iStoreResolver);
       
   214 	aRichText.DetachFromStoreL(CPicture::EDetachFull);
       
   215 	CleanupStack::PopAndDestroy(3);	// embeddedStore, markupStream, blob
       
   216 	}
       
   217 
       
   218 
       
   219 
       
   220 
       
   221 
       
   222 
       
   223 
       
   224 
       
   225 
       
   226 
       
   227 
       
   228 //
       
   229 // CHlpTable class - write access to database views
       
   230 //
       
   231 
       
   232 CHlpTable::CHlpTable(RDbView* aView)
       
   233 :	CHlpRowSet(aView)
       
   234 	{
       
   235 	}
       
   236 
       
   237 CHlpTable::~CHlpTable()
       
   238 	{
       
   239 //	View()->Close();
       
   240 	}
       
   241 
       
   242 void CHlpTable::ConstructL()
       
   243 	{
       
   244 	}
       
   245 
       
   246 EXPORT_C CHlpTable* CHlpTable::NewLC(RDbView* aView)
       
   247 	{
       
   248 	CHlpTable* self=new(ELeave)CHlpTable(aView);
       
   249 	CleanupStack::PushL(self);
       
   250 	self->ConstructL();
       
   251 	return self;
       
   252 	}
       
   253 
       
   254 EXPORT_C CHlpTable* CHlpTable::NewL(RDbView* aView)
       
   255 	{
       
   256 	CHlpTable* self=CHlpTable::NewLC(aView);
       
   257 	CleanupStack::Pop();
       
   258 	return self;
       
   259 	}
       
   260 
       
   261 EXPORT_C void CHlpTable::InsertL()
       
   262 	{
       
   263 	View()->InsertL();
       
   264 	}
       
   265 
       
   266 EXPORT_C void CHlpTable::PutL()
       
   267 	{
       
   268 	View()->PutL();
       
   269 	}
       
   270 
       
   271 EXPORT_C void CHlpTable::SetColL(TDbColNo aCol, const TDesC& aText)
       
   272 	{
       
   273 	__ASSERT_ALWAYS(View()->AtRow(), Panic(EDbWriterNoRowAtCursor));
       
   274 	View()->SetColL(aCol, aText);
       
   275 	}
       
   276 
       
   277 EXPORT_C void CHlpTable::SetColL(TDbColNo aCol, TUint32 aValue)
       
   278 	{
       
   279 	__ASSERT_ALWAYS(View()->AtRow(), Panic(EDbWriterNoRowAtCursor));
       
   280 	View()->SetColL(aCol, aValue);
       
   281 	}
       
   282 
       
   283 EXPORT_C void CHlpTable::SetColL(TDbColNo aCol, const CFbsBitmap& aBitmap)
       
   284 	{
       
   285 	__ASSERT_ALWAYS(View()->AtRow(), Panic(EDbWriterNoRowAtCursor));
       
   286 
       
   287 	RDbColWriteStream blob;
       
   288 	blob.OpenLC(*View(), aCol);
       
   289 	blob << aBitmap;
       
   290 	blob.CommitL();
       
   291 	CleanupStack::PopAndDestroy(); // blob
       
   292 	}
       
   293 
       
   294 EXPORT_C void CHlpTable::SetColL(TDbColNo aTextCol, TDbColNo aMarkupCol, CRichText& aRichText)
       
   295 	{
       
   296 	__ASSERT_ALWAYS(View()->AtRow(), Panic(EDbWriterNoRowAtCursor));
       
   297 	HBufC* buf = HBufC::NewLC(aRichText.DocumentLength());
       
   298 	TPtr ptr = buf->Des();
       
   299 	aRichText.Extract(ptr);
       
   300 	SetLongTextL(*buf, aTextCol);
       
   301 	CleanupStack::PopAndDestroy();	// buf
       
   302 
       
   303 	if (aRichText.HasMarkupData())
       
   304 		SetMarkupL(aRichText, aMarkupCol);
       
   305 	else
       
   306 		View()->SetColNullL(aMarkupCol);
       
   307 	}
       
   308 
       
   309 EXPORT_C void CHlpTable::SetColL(TDbColNo aTextCol, CRichText& aRichText)
       
   310 	{
       
   311 	__ASSERT_ALWAYS(View()->AtRow(), Panic(EDbWriterNoRowAtCursor));
       
   312 	HBufC* buf = HBufC::NewL(aRichText.DocumentLength());
       
   313 	CleanupStack::PushL(buf);
       
   314 	TPtr ptr = buf->Des();
       
   315 	aRichText.Extract(ptr);
       
   316 	View()->SetColL(aTextCol,ptr);
       
   317 	CleanupStack::PopAndDestroy();	// buf
       
   318 	}
       
   319 
       
   320 void CHlpTable::SetLongTextL(const TDesC& aText, TDbColNo aLongTextCol)
       
   321 	{
       
   322 	RDbColWriteStream stream;
       
   323 	stream.OpenLC(*View(), aLongTextCol);
       
   324 	stream.WriteL(aText);
       
   325 	stream.CommitL();
       
   326 	CleanupStack::PopAndDestroy();	// stream
       
   327 	}
       
   328 
       
   329 void CHlpTable::SetMarkupL(CRichText& aRichText, TDbColNo aMarkupCol)
       
   330 	{
       
   331 	aRichText.DetachFromStoreL(CPicture::EDetachFull);
       
   332 	RDbColWriteStream blob;
       
   333 	blob.OpenL(*View(), aMarkupCol);
       
   334 	CEmbeddedStore* embeddedStore=CEmbeddedStore::NewLC(blob); // takes ownership of blob
       
   335 	CStoreMap* map=CStoreMap::NewLC(*embeddedStore);
       
   336 	aRichText.StoreMarkupComponentsL(*embeddedStore, *map);
       
   337 
       
   338 	RStoreWriteStream markup(*map);
       
   339 	embeddedStore->SetRootL(markup.CreateLC(*embeddedStore));
       
   340 	aRichText.ExternalizeMarkupDataL(markup);
       
   341 	markup.CommitL();
       
   342 	map->Reset();
       
   343 	CleanupStack::PopAndDestroy(2); // map, markup
       
   344 	embeddedStore->CommitL();
       
   345 	CleanupStack::PopAndDestroy(); // embeddedStore
       
   346 	}
       
   347 
       
   348 const CStreamStore& THlpStoreResolver::StreamStoreL(TInt /*aPos*/) const
       
   349 	{
       
   350 	return *iStore;
       
   351 	}
       
   352 
       
   353 
       
   354 
       
   355 
       
   356 
       
   357 
       
   358 
       
   359 
       
   360 
       
   361 
       
   362 
       
   363 
       
   364 
       
   365 
       
   366 
       
   367 //
       
   368 // CHlpDbWriter class
       
   369 //
       
   370 
       
   371 CHlpDbWriter::CHlpDbWriter(RFs& aFs)
       
   372 :	iFs(aFs)
       
   373 	{
       
   374 	}
       
   375 
       
   376 EXPORT_C CHlpDbWriter::~CHlpDbWriter()
       
   377 	{
       
   378 	iDatabase.Close();
       
   379 	delete iTables;
       
   380 	delete iDictionary;
       
   381 	delete iStore;
       
   382 	delete iUids;
       
   383 	delete iImagesAlreadyStored;
       
   384 }
       
   385 
       
   386 void CHlpDbWriter::ConstructL()
       
   387 	{
       
   388 	iDictionary				= CStreamDictionary::NewL();
       
   389 	iTables					= new(ELeave) CArrayPtrFlat<CHlpTable>(4);
       
   390 	iUids					= new(ELeave) CArrayFixFlat<TUid>(2);
       
   391 	iImagesAlreadyStored	= new(ELeave) CArrayFixFlat<TUid>(10);
       
   392 	}
       
   393 
       
   394 EXPORT_C CHlpDbWriter* CHlpDbWriter::NewL(RFs& aFs)
       
   395 	{
       
   396 	CHlpDbWriter* self = CHlpDbWriter::NewLC(aFs);
       
   397 	CleanupStack::Pop(); //self
       
   398 	return self;
       
   399 	}
       
   400 
       
   401 EXPORT_C CHlpDbWriter* CHlpDbWriter::NewLC(RFs& aFs)
       
   402 	{
       
   403 	CHlpDbWriter* self = new(ELeave) CHlpDbWriter(aFs);
       
   404 	CleanupStack::PushL(self);
       
   405 	self->ConstructL();
       
   406 	return self;
       
   407 	}
       
   408 
       
   409 EXPORT_C void CHlpDbWriter::SetDatabaseUidL(TUid& aUid)
       
   410 	{
       
   411 	__ASSERT_DEBUG(iStore, Panic(EDbWriterStoreNotOpen));
       
   412 
       
   413 	TUidType type(KPermanentFileStoreLayoutUid, KUidHlpApp, aUid);	
       
   414 	iStore->SetTypeL(type);
       
   415 	}
       
   416 
       
   417 EXPORT_C void CHlpDbWriter::CreateFileL(const TDesC& aFileName)
       
   418 	{
       
   419 	CPermanentFileStore* store = NULL;
       
   420 	
       
   421 	if	(!BaflUtils::FileExists(iFs, aFileName))
       
   422 		store = CPermanentFileStore::CreateL(iFs, aFileName, EFileRead|EFileWrite);
       
   423 	else // Change this so that the program panics if the file exists.
       
   424 		store = CPermanentFileStore::ReplaceL(iFs, aFileName, EFileRead|EFileWrite);
       
   425 
       
   426 	delete iStore;
       
   427 	iStore = store;
       
   428 	iFileName = aFileName;
       
   429 	}
       
   430 
       
   431 EXPORT_C void CHlpDbWriter::AddBitmapL(TInt aBitmapId)
       
   432 	{
       
   433 	TKeyArrayFix key(_FOFF(TUid, iUid), ECmpTUint);
       
   434 	iImagesAlreadyStored->InsertIsqL(TUid::Uid(aBitmapId), key);
       
   435 	}
       
   436 
       
   437 EXPORT_C TBool CHlpDbWriter::IsBitmapStored(TInt aBitmapId) const
       
   438 	{
       
   439 	TInt index = KErrNotFound;
       
   440 	TKeyArrayFix key(_FOFF(TUid, iUid), ECmpTUint);
       
   441 	return (!iImagesAlreadyStored->FindIsq(TUid::Uid(aBitmapId), key, index));
       
   442 	}
       
   443 
       
   444 EXPORT_C TInt CHlpDbWriter::BitmapCount() const
       
   445 	{
       
   446 	return iImagesAlreadyStored->Count();
       
   447 	}
       
   448 
       
   449 EXPORT_C TInt CHlpDbWriter::BitmapIdForIndex(TInt aIndex) const
       
   450 	{
       
   451 	return iImagesAlreadyStored->At(aIndex).iUid;
       
   452 	}
       
   453 
       
   454 EXPORT_C void CHlpDbWriter::CreateDatabaseL()
       
   455 	{
       
   456 	TStreamId dbStream=iDatabase.CreateL(iStore);
       
   457 	iDictionary->AssignL(KUidHlpDbStream, dbStream);
       
   458 	DoCreateDatabaseL();
       
   459 	DoOpenTablesL();
       
   460 	}
       
   461 
       
   462 void CHlpDbWriter::DoCreateDatabaseL()
       
   463 	{
       
   464 	// create the table schemas
       
   465 	User::LeaveIfError(iDatabase.Execute(KHlpDMLTopicTable));
       
   466 	User::LeaveIfError(iDatabase.Execute(KHlpDMLIndexTable));
       
   467 	User::LeaveIfError(iDatabase.Execute(KHlpDMLTopicIndexTable));
       
   468 	User::LeaveIfError(iDatabase.Execute(KHlpDMLContextTable));
       
   469 	User::LeaveIfError(iDatabase.Execute(KHlpDMLImageTable));
       
   470 
       
   471 	// create the indices
       
   472 	User::LeaveIfError(iDatabase.Execute(KHlpDMLTopicTableIdx));
       
   473 	User::LeaveIfError(iDatabase.Execute(KHlpDMLIndexTableIdx));
       
   474 	User::LeaveIfError(iDatabase.Execute(KHlpDMLTopicIndexTableIdx));
       
   475 	User::LeaveIfError(iDatabase.Execute(KHlpDMLContextTableIdx));
       
   476 	User::LeaveIfError(iDatabase.Execute(KHlpDMLImageTableIdx));
       
   477 	}
       
   478 
       
   479 EXPORT_C void CHlpDbWriter::CompressDatabaseL()
       
   480 	{
       
   481 	StoreUidsL();
       
   482 	StoreStreamDictionaryL();
       
   483 
       
   484 	iStore->CommitL();
       
   485 	iDatabase.CompressL(*iStore, iDictionary->At(KUidHlpDbStream));
       
   486 	iStore->CompactL();
       
   487 	iStore->CommitL();
       
   488 	}
       
   489 
       
   490 void CHlpDbWriter::DoOpenTablesL()
       
   491 	{
       
   492 	iTables->AppendL(DoOpenTableLC(ETopicTable));
       
   493 	CleanupStack::Pop(); // ret from DoOpenTableL
       
   494 	iTables->AppendL(DoOpenTableLC(EIndexTable));
       
   495 	CleanupStack::Pop(); // ret from DoOpenTableL
       
   496 	iTables->AppendL(DoOpenTableLC(ETopicIndexTable));
       
   497 	CleanupStack::Pop(); // ret from DoOpenTableL
       
   498 	iTables->AppendL(DoOpenTableLC(EContextTable));
       
   499 	CleanupStack::Pop(); // ret from DoOpenTableL
       
   500 	iTables->AppendL(DoOpenTableLC(EImageTable));
       
   501 	CleanupStack::Pop(); // ret from DoOpenTableL
       
   502 	}
       
   503 
       
   504 CHlpTable* CHlpDbWriter::DoOpenTableLC(TInt aTable)
       
   505 	{
       
   506 	TBuf<255> sql;
       
   507 
       
   508 	switch(aTable)
       
   509 		{
       
   510 	case ETopicTable:
       
   511 		sql=KHlpSQLTopicTable;
       
   512 		break;
       
   513 	case EIndexTable:
       
   514 		sql=KHlpSQLIndexTable;
       
   515 		break;
       
   516 	case ETopicIndexTable:
       
   517 		sql=KHlpSQLTopicIndexTable;
       
   518 		break;
       
   519 	case EContextTable:
       
   520 		sql=KHlpSQLContextTable;
       
   521 		break;
       
   522 	case EImageTable:
       
   523 		sql=KHlpSQLImageTable;
       
   524 		break;
       
   525 	default:
       
   526 		User::Leave(KErrNotSupported);
       
   527 		}
       
   528 
       
   529 	RDbView* view = new(ELeave) RDbView;
       
   530 	CleanupStack::PushL(view);
       
   531 	User::LeaveIfError(view->Prepare(iDatabase, sql, RDbView::EUpdatable));
       
   532 	User::LeaveIfError(view->EvaluateAll());
       
   533 	CHlpTable* table = CHlpTable::NewL(view);
       
   534 	CleanupStack::Pop(); // view
       
   535 	CleanupStack::PushL(table);
       
   536 
       
   537 	return table;
       
   538 	}
       
   539 
       
   540 
       
   541 
       
   542 void CHlpDbWriter::StoreUidsL()
       
   543 	{
       
   544 	RStoreWriteStream out;
       
   545 	TStreamId uidStream = out.CreateLC(*iStore);
       
   546 	iDictionary->AssignL(KUidHlpUidStream, uidStream);
       
   547 	out.WriteInt32L(iUids->Count());
       
   548 	if (iUids->Count() > 0)
       
   549 		{
       
   550 		for(TInt i=0; i < iUids->Count(); i++)
       
   551 			{
       
   552 			out.WriteInt32L((*iUids)[i].iUid);
       
   553 			}
       
   554 		}
       
   555 	out.CommitL();
       
   556 	out.Close();
       
   557 	CleanupStack::PopAndDestroy(); // out
       
   558 	}
       
   559 
       
   560 void CHlpDbWriter::StoreStreamDictionaryL()
       
   561 	{
       
   562 	// Store the stream dictionary in the root
       
   563 	RStoreWriteStream out;
       
   564 	TStreamId root = out.CreateLC(*iStore);
       
   565 	iStore->SetRootL(root);
       
   566 	out << *iDictionary;
       
   567 	out.CommitL();
       
   568 	out.Close();
       
   569 	CleanupStack::PopAndDestroy(); // out
       
   570 	}
       
   571 
       
   572 EXPORT_C void CHlpDbWriter::CloseFileL() // should this be make private and put in the destructor?
       
   573 	{
       
   574 	iDatabase.Close();
       
   575 	iStore->CompactL();
       
   576 	iStore->CommitL();
       
   577 	delete iStore;
       
   578 	iStore=NULL;
       
   579 	iUids->Reset();
       
   580 	iTables->ResetAndDestroy();
       
   581 	iTables->Reset();
       
   582 	
       
   583 	// Have to do this because there is no reset procedure for a stream dictionary
       
   584 	CStreamDictionary* newDictionary = CStreamDictionary::NewL();
       
   585 	delete iDictionary;
       
   586 	iDictionary = newDictionary;
       
   587 	}
       
   588 
       
   589 EXPORT_C void CHlpDbWriter::SetUidL(TUid aUid)
       
   590 	{
       
   591 	TKeyArrayFix key(_FOFF(TUid,iUid),ECmpTUint32);
       
   592 	TInt indexNotReferenced = KErrNotFound;
       
   593 	if	(iUids->Find(aUid,key, indexNotReferenced) != KErrNone)
       
   594 		iUids->AppendL(aUid);
       
   595 	}	
       
   596 
       
   597 EXPORT_C void CHlpDbWriter::BeginTransaction()
       
   598 	{
       
   599 	iDatabase.Begin();
       
   600 	}
       
   601 
       
   602 EXPORT_C void CHlpDbWriter::CommitTransaction()
       
   603 	{
       
   604 	iDatabase.Commit();
       
   605 	}
       
   606 
       
   607 EXPORT_C CHlpTable* CHlpDbWriter::TopicTable()
       
   608 	{
       
   609 	return iTables->At(ETopicTable);
       
   610 	}
       
   611 
       
   612 EXPORT_C CHlpTable* CHlpDbWriter::IndexTable()
       
   613 	{
       
   614 	return iTables->At(EIndexTable);
       
   615 	}
       
   616 
       
   617 EXPORT_C CHlpTable* CHlpDbWriter::TopicIndexTable()
       
   618 	{
       
   619 	return iTables->At(ETopicIndexTable);
       
   620 	}
       
   621 
       
   622 EXPORT_C CHlpTable* CHlpDbWriter::ContextTable()
       
   623 	{
       
   624 	return iTables->At(EContextTable);
       
   625 	}
       
   626 
       
   627 EXPORT_C CHlpTable* CHlpDbWriter::ImageTable()
       
   628 	{
       
   629 	return iTables->At(EImageTable);
       
   630 	}