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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #ifndef __DBWRITER_H__
17 #define __DBWRITER_H__
29 #include "hlpconstants.h"
31 // Db writer constants
32 const TInt KTopicTblTopicTitle = 1;
33 const TInt KTopicTblCategoryTitle = 2;
34 const TInt KTopicTblTopicText = 3;
35 const TInt KTopicTblTopicMarkup = 4;
36 const TInt KTopicTblSynonym = 5;
37 const TInt KTopicTblTopicId = 6;
38 const TInt KTopicTblCategoryUID = 7;
40 const TInt KIndexTblIndex = 1;
41 const TInt KIndexTblIndexId = 2;
43 const TInt KTopicIndexTblTopicId = 1;
44 const TInt KTopicIndexTblIndexId = 2;
45 const TInt KTopicIndexTblCategoryUID = 3;
46 const TInt KTopicIndexTblTopicTitle = 4;
48 const TInt KContextTblContext = 1;
49 const TInt KContextTblTopicId = 2;
51 const TInt KImageTblImageId = 1;
52 const TInt KImageTblImageCount = 2;
53 const TInt KImageTblImage0 = 3;
54 const TInt KImageTblImage1 = 4;
55 const TInt KImageTblImage2 = 5;
59 // DML statements used in creating the database tables and indices
60 _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)");
62 // IndexeId's are unique on a per-helpfile basis, ie. all indexId's in one help file are unique.
63 _LIT(KHlpDMLIndexTable, "CREATE TABLE Index (Index CHAR(120), IndexId UNSIGNED INTEGER)");
65 // TopicId's are unique within a helpfile but not across a help file
66 _LIT(KHlpDMLTopicIndexTable, "CREATE TABLE TopicIndex (TopicId UNSIGNED INTEGER, IndexId UNSIGNED INTEGER, CategoryUID UNSIGNED INTEGER, TopicTitle CHAR(120))");
68 _LIT(KHlpDMLContextTable, "CREATE TABLE Context (Context CHAR(30), TopicId UNSIGNED INTEGER)");
70 _LIT(KHlpDMLImageTable, "CREATE TABLE Image (ImageId UNSIGNED INTEGER, ImageCount UNSIGNED INTEGER, Image0 LONG VARBINARY, Image1 LONG VARBINARY, Image2 LONG VARBINARY)");
73 _LIT(KHlpDMLTopicTableIdx, "CREATE UNIQUE INDEX TopicIdx ON Topic (TopicId)");
74 _LIT(KHlpDMLIndexTableIdx, "CREATE UNIQUE INDEX IndexIdx ON Index (IndexId)");
75 _LIT(KHlpDMLTopicIndexTableIdx, "CREATE UNIQUE INDEX TopicIndexIdx ON TopicIndex (IndexId, TopicId)");
76 _LIT(KHlpDMLContextTableIdx, "CREATE UNIQUE INDEX ContextIdx ON Context (Context)");
77 _LIT(KHlpDMLImageTableIdx, "CREATE UNIQUE INDEX ImageIdx ON Image (ImageId)");
79 // DDL statements used in opening tables for writing
80 _LIT(KHlpSQLTopicTable, "SELECT * FROM Topic");
81 _LIT(KHlpSQLIndexTable, "SELECT * FROM Index");
82 _LIT(KHlpSQLTopicIndexTable, "SELECT * FROM TopicIndex");
83 _LIT(KHlpSQLContextTable, "SELECT * FROM Context");
84 _LIT(KHlpSQLImageTable, "SELECT * FROM Image");
86 // enum for selecting a table for writing to
99 // CHlpDbWriter class: creates the store and the database, and provides the interface to write to the file
100 class CHlpDbWriter : public CBase
107 IMPORT_C ~CHlpDbWriter();
108 IMPORT_C static CHlpDbWriter* NewL(RFs& aFs);
109 IMPORT_C static CHlpDbWriter* NewLC(RFs& aFs);
111 IMPORT_C void CreateFileL(const TDesC& aFileName);
112 IMPORT_C void CreateDatabaseL();
113 IMPORT_C void CompressDatabaseL();
114 IMPORT_C void SetDatabaseUidL(TUid& aUid);
115 IMPORT_C void CloseFileL();
117 IMPORT_C void AddBitmapL(TInt aBitmapId);
118 IMPORT_C TBool IsBitmapStored(TInt aBitmapId) const;
119 IMPORT_C TInt BitmapCount() const;
120 IMPORT_C TInt BitmapIdForIndex(TInt aIndex) const;
122 IMPORT_C void BeginTransaction();
123 IMPORT_C void CommitTransaction();
125 IMPORT_C CHlpTable* TopicTable();
126 IMPORT_C CHlpTable* IndexTable();
127 IMPORT_C CHlpTable* TopicIndexTable();
128 IMPORT_C CHlpTable* ContextTable();
129 IMPORT_C CHlpTable* ImageTable();
130 IMPORT_C void SetUidL(TUid aUid);
132 void DoCreateDatabaseL();
133 CHlpTable* DoOpenTableLC(TInt aTable);
134 void DoOpenTablesL();
136 void StoreStreamDictionaryL();
138 CHlpDbWriter(RFs& aFs);
144 RDbStoreDatabase iDatabase;
145 CArrayFixFlat<TUid>* iUids;
146 CArrayPtrFlat<CHlpTable>* iTables;
147 CArrayFixFlat<TUid>* iImagesAlreadyStored;
149 CPermanentFileStore* iStore;
150 CStreamDictionary* iDictionary;
153 class THlpStoreResolver : public MRichTextStoreResolver
160 virtual const CStreamStore& StreamStoreL(TInt aPos) const;
161 CStreamStore* iStore;
164 // CHlpRowSet class: abstract class for accessing database tables
165 class CHlpRowSet : public CBase
172 CHlpRowSet(RDbView* aView);
173 IMPORT_C virtual ~CHlpRowSet();
174 IMPORT_C TBool AtRow();
175 IMPORT_C TBool AtBeginning();
176 IMPORT_C TBool AtEnd();
177 IMPORT_C TBool FirstL();
178 IMPORT_C TBool LastL();
179 IMPORT_C TInt CountL();
181 IMPORT_C void NextL();
182 IMPORT_C void PreviousL();
184 IMPORT_C TDbColNo MapColNameToColNo(const TDbCol& aCol);
185 IMPORT_C TDbColNo MapColNameToColNo(const TDesC& aName);
186 IMPORT_C CDbColSet* ColSet();
188 IMPORT_C RDbView* View();
193 // CHlpView class: concrete class used for accessing database tables (for test code)
194 class CHlpView : public CHlpRowSet
201 IMPORT_C static CHlpView* NewL(RDbView* aView);
202 IMPORT_C static CHlpView* NewLC(RDbView* aView);
205 inline void SetPictureFactory(MPictureFactory* aPictureFactory) {iPictureFactory=aPictureFactory;};
207 IMPORT_C void GetTextL(TDbColNo aCol, TDes& aText);
208 IMPORT_C void GetRichTextL(TDbColNo aTextCol, TDbColNo aMarkupCol, CRichText& aRichText);
209 IMPORT_C void GetValL(TDbColNo aCol, TUint32& aValue);
210 IMPORT_C void GetL();
212 void GetMarkupL(CRichText& aRichText, TDbColNo aMarkupCol);
214 CHlpView(RDbView* aView);
217 THlpStoreResolver iStoreResolver;
218 MPictureFactory *iPictureFactory;
222 // CHlpTable class: concrete class used for writing to database tables
223 class CHlpTable : public CHlpRowSet
230 IMPORT_C static CHlpTable* NewL(RDbView* aView);
231 IMPORT_C static CHlpTable* NewLC(RDbView* aView);
234 IMPORT_C void InsertL();
235 IMPORT_C void PutL();
237 IMPORT_C void SetColL(TDbColNo aCol, const TDesC& aText);
238 IMPORT_C void SetColL(TDbColNo aTextCol, TDbColNo aMarkupCol, CRichText& aRichText);
239 IMPORT_C void SetColL(TDbColNo aTextCol, CRichText& aRichText);
240 IMPORT_C void SetColL(TDbColNo aCol, TUint32 aValue);
241 IMPORT_C void SetColL(TDbColNo aCol, const CFbsBitmap& aBitmap);
243 void SetMarkupL(CRichText& aRichText, TDbColNo aMarkupCol);
244 void SetLongTextL(const TDesC& aText, TDbColNo aLongTextCol);
246 CHlpTable(RDbView* aView);