williamr@4: // Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies). williamr@4: // All rights reserved. williamr@4: // This component and the accompanying materials are made available williamr@4: // under the terms of "Eclipse Public License v1.0" williamr@4: // which accompanies this distribution, and is available williamr@4: // at the URL "http://www.eclipse.org/legal/epl-v10.html". williamr@4: // williamr@4: // Initial Contributors: williamr@4: // Nokia Corporation - initial contribution. williamr@4: // williamr@4: // Contributors: williamr@4: // williamr@4: // Description: williamr@4: // williamr@4: williamr@4: #ifndef __DBWRITER_H__ williamr@4: #define __DBWRITER_H__ williamr@4: williamr@4: #include williamr@4: #include williamr@4: #include williamr@4: #include williamr@4: #include williamr@4: #include williamr@4: #include williamr@4: #include williamr@4: williamr@4: // User includes williamr@4: #include "hlpconstants.h" williamr@4: williamr@4: // Db writer constants williamr@4: const TInt KTopicTblTopicTitle = 1; williamr@4: const TInt KTopicTblCategoryTitle = 2; williamr@4: const TInt KTopicTblTopicText = 3; williamr@4: const TInt KTopicTblTopicMarkup = 4; williamr@4: const TInt KTopicTblSynonym = 5; williamr@4: const TInt KTopicTblTopicId = 6; williamr@4: const TInt KTopicTblCategoryUID = 7; williamr@4: williamr@4: const TInt KIndexTblIndex = 1; williamr@4: const TInt KIndexTblIndexId = 2; williamr@4: williamr@4: const TInt KTopicIndexTblTopicId = 1; williamr@4: const TInt KTopicIndexTblIndexId = 2; williamr@4: const TInt KTopicIndexTblCategoryUID = 3; williamr@4: const TInt KTopicIndexTblTopicTitle = 4; williamr@4: williamr@4: const TInt KContextTblContext = 1; williamr@4: const TInt KContextTblTopicId = 2; williamr@4: williamr@4: const TInt KImageTblImageId = 1; williamr@4: const TInt KImageTblImageCount = 2; williamr@4: const TInt KImageTblImage0 = 3; williamr@4: const TInt KImageTblImage1 = 4; williamr@4: const TInt KImageTblImage2 = 5; williamr@4: williamr@4: williamr@4: williamr@4: // DML statements used in creating the database tables and indices williamr@4: _LIT(KHlpDMLTopicTable, "CREATE TABLE Topic (TopicTitle CHAR(120), Category CHAR(120), TopicText LONG VARCHAR, TopicMarkup LONG VARBINARY, Synonym CHAR(200), TopicId UNSIGNED INTEGER, CategoryUID UNSIGNED INTEGER)"); williamr@4: williamr@4: // IndexeId's are unique on a per-helpfile basis, ie. all indexId's in one help file are unique. williamr@4: _LIT(KHlpDMLIndexTable, "CREATE TABLE Index (Index CHAR(120), IndexId UNSIGNED INTEGER)"); williamr@4: williamr@4: // TopicId's are unique within a helpfile but not across a help file williamr@4: _LIT(KHlpDMLTopicIndexTable, "CREATE TABLE TopicIndex (TopicId UNSIGNED INTEGER, IndexId UNSIGNED INTEGER, CategoryUID UNSIGNED INTEGER, TopicTitle CHAR(120))"); williamr@4: williamr@4: _LIT(KHlpDMLContextTable, "CREATE TABLE Context (Context CHAR(30), TopicId UNSIGNED INTEGER)"); williamr@4: williamr@4: _LIT(KHlpDMLImageTable, "CREATE TABLE Image (ImageId UNSIGNED INTEGER, ImageCount UNSIGNED INTEGER, Image0 LONG VARBINARY, Image1 LONG VARBINARY, Image2 LONG VARBINARY)"); williamr@4: williamr@4: williamr@4: _LIT(KHlpDMLTopicTableIdx, "CREATE UNIQUE INDEX TopicIdx ON Topic (TopicId)"); williamr@4: _LIT(KHlpDMLIndexTableIdx, "CREATE UNIQUE INDEX IndexIdx ON Index (IndexId)"); williamr@4: _LIT(KHlpDMLTopicIndexTableIdx, "CREATE UNIQUE INDEX TopicIndexIdx ON TopicIndex (IndexId, TopicId)"); williamr@4: _LIT(KHlpDMLContextTableIdx, "CREATE UNIQUE INDEX ContextIdx ON Context (Context)"); williamr@4: _LIT(KHlpDMLImageTableIdx, "CREATE UNIQUE INDEX ImageIdx ON Image (ImageId)"); williamr@4: williamr@4: // DDL statements used in opening tables for writing williamr@4: _LIT(KHlpSQLTopicTable, "SELECT * FROM Topic"); williamr@4: _LIT(KHlpSQLIndexTable, "SELECT * FROM Index"); williamr@4: _LIT(KHlpSQLTopicIndexTable, "SELECT * FROM TopicIndex"); williamr@4: _LIT(KHlpSQLContextTable, "SELECT * FROM Context"); williamr@4: _LIT(KHlpSQLImageTable, "SELECT * FROM Image"); williamr@4: williamr@4: // enum for selecting a table for writing to williamr@4: enum williamr@4: { williamr@4: ETopicTable, williamr@4: EIndexTable, williamr@4: ETopicIndexTable, williamr@4: EContextTable, williamr@4: EImageTable williamr@4: }; williamr@4: williamr@4: williamr@4: class CHlpTable; williamr@4: williamr@4: // CHlpDbWriter class: creates the store and the database, and provides the interface to write to the file williamr@4: class CHlpDbWriter : public CBase williamr@4: /** williamr@4: @internalComponent williamr@4: @released williamr@4: */ williamr@4: { williamr@4: public: williamr@4: IMPORT_C ~CHlpDbWriter(); williamr@4: IMPORT_C static CHlpDbWriter* NewL(RFs& aFs); williamr@4: IMPORT_C static CHlpDbWriter* NewLC(RFs& aFs); williamr@4: public: williamr@4: IMPORT_C void CreateFileL(const TDesC& aFileName); williamr@4: IMPORT_C void CreateDatabaseL(); williamr@4: IMPORT_C void CompressDatabaseL(); williamr@4: IMPORT_C void SetDatabaseUidL(TUid& aUid); williamr@4: IMPORT_C void CloseFileL(); williamr@4: public: williamr@4: IMPORT_C void AddBitmapL(TInt aBitmapId); williamr@4: IMPORT_C TBool IsBitmapStored(TInt aBitmapId) const; williamr@4: IMPORT_C TInt BitmapCount() const; williamr@4: IMPORT_C TInt BitmapIdForIndex(TInt aIndex) const; williamr@4: public: williamr@4: IMPORT_C void BeginTransaction(); williamr@4: IMPORT_C void CommitTransaction(); williamr@4: public: williamr@4: IMPORT_C CHlpTable* TopicTable(); williamr@4: IMPORT_C CHlpTable* IndexTable(); williamr@4: IMPORT_C CHlpTable* TopicIndexTable(); williamr@4: IMPORT_C CHlpTable* ContextTable(); williamr@4: IMPORT_C CHlpTable* ImageTable(); williamr@4: IMPORT_C void SetUidL(TUid aUid); williamr@4: private: williamr@4: void DoCreateDatabaseL(); williamr@4: CHlpTable* DoOpenTableLC(TInt aTable); williamr@4: void DoOpenTablesL(); williamr@4: void StoreUidsL(); williamr@4: void StoreStreamDictionaryL(); williamr@4: private: williamr@4: CHlpDbWriter(RFs& aFs); williamr@4: void ConstructL(); williamr@4: private: williamr@4: RFs& iFs; williamr@4: TFileName iFileName; williamr@4: williamr@4: RDbStoreDatabase iDatabase; williamr@4: CArrayFixFlat* iUids; williamr@4: CArrayPtrFlat* iTables; williamr@4: CArrayFixFlat* iImagesAlreadyStored; williamr@4: williamr@4: CPermanentFileStore* iStore; williamr@4: CStreamDictionary* iDictionary; williamr@4: }; williamr@4: williamr@4: class THlpStoreResolver : public MRichTextStoreResolver williamr@4: /** williamr@4: @internalComponent williamr@4: @released williamr@4: */ williamr@4: { williamr@4: public: williamr@4: virtual const CStreamStore& StreamStoreL(TInt aPos) const; williamr@4: CStreamStore* iStore; williamr@4: }; williamr@4: williamr@4: // CHlpRowSet class: abstract class for accessing database tables williamr@4: class CHlpRowSet : public CBase williamr@4: /** williamr@4: @internalComponent williamr@4: @released williamr@4: */ williamr@4: { williamr@4: public: williamr@4: CHlpRowSet(RDbView* aView); williamr@4: IMPORT_C virtual ~CHlpRowSet(); williamr@4: IMPORT_C TBool AtRow(); williamr@4: IMPORT_C TBool AtBeginning(); williamr@4: IMPORT_C TBool AtEnd(); williamr@4: IMPORT_C TBool FirstL(); williamr@4: IMPORT_C TBool LastL(); williamr@4: IMPORT_C TInt CountL(); williamr@4: public: williamr@4: IMPORT_C void NextL(); williamr@4: IMPORT_C void PreviousL(); williamr@4: public: williamr@4: IMPORT_C TDbColNo MapColNameToColNo(const TDbCol& aCol); williamr@4: IMPORT_C TDbColNo MapColNameToColNo(const TDesC& aName); williamr@4: IMPORT_C CDbColSet* ColSet(); williamr@4: williamr@4: IMPORT_C RDbView* View(); williamr@4: private: williamr@4: RDbView* iView; williamr@4: }; williamr@4: williamr@4: // CHlpView class: concrete class used for accessing database tables (for test code) williamr@4: class CHlpView : public CHlpRowSet williamr@4: /** williamr@4: @internalComponent williamr@4: @released williamr@4: */ williamr@4: { williamr@4: public: williamr@4: IMPORT_C static CHlpView* NewL(RDbView* aView); williamr@4: IMPORT_C static CHlpView* NewLC(RDbView* aView); williamr@4: ~CHlpView(); williamr@4: public: williamr@4: inline void SetPictureFactory(MPictureFactory* aPictureFactory) {iPictureFactory=aPictureFactory;}; williamr@4: public: williamr@4: IMPORT_C void GetTextL(TDbColNo aCol, TDes& aText); williamr@4: IMPORT_C void GetRichTextL(TDbColNo aTextCol, TDbColNo aMarkupCol, CRichText& aRichText); williamr@4: IMPORT_C void GetValL(TDbColNo aCol, TUint32& aValue); williamr@4: IMPORT_C void GetL(); williamr@4: private: williamr@4: void GetMarkupL(CRichText& aRichText, TDbColNo aMarkupCol); williamr@4: private: williamr@4: CHlpView(RDbView* aView); williamr@4: void ConstructL(); williamr@4: private: williamr@4: THlpStoreResolver iStoreResolver; williamr@4: MPictureFactory *iPictureFactory; williamr@4: TBool iHasRows; williamr@4: }; williamr@4: williamr@4: // CHlpTable class: concrete class used for writing to database tables williamr@4: class CHlpTable : public CHlpRowSet williamr@4: /** williamr@4: @internalComponent williamr@4: @released williamr@4: */ williamr@4: { williamr@4: public: williamr@4: IMPORT_C static CHlpTable* NewL(RDbView* aView); williamr@4: IMPORT_C static CHlpTable* NewLC(RDbView* aView); williamr@4: ~CHlpTable(); williamr@4: public: williamr@4: IMPORT_C void InsertL(); williamr@4: IMPORT_C void PutL(); williamr@4: public: williamr@4: IMPORT_C void SetColL(TDbColNo aCol, const TDesC& aText); williamr@4: IMPORT_C void SetColL(TDbColNo aTextCol, TDbColNo aMarkupCol, CRichText& aRichText); williamr@4: IMPORT_C void SetColL(TDbColNo aTextCol, CRichText& aRichText); williamr@4: IMPORT_C void SetColL(TDbColNo aCol, TUint32 aValue); williamr@4: IMPORT_C void SetColL(TDbColNo aCol, const CFbsBitmap& aBitmap); williamr@4: private: williamr@4: void SetMarkupL(CRichText& aRichText, TDbColNo aMarkupCol); williamr@4: void SetLongTextL(const TDesC& aText, TDbColNo aLongTextCol); williamr@4: private: williamr@4: CHlpTable(RDbView* aView); williamr@4: void ConstructL(); williamr@4: }; williamr@4: williamr@4: #endif