epoc32/include/app/dbwriter.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
     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 #ifndef __DBWRITER_H__
    17 #define __DBWRITER_H__
    18 
    19 #include <d32dbms.h>
    20 #include <e32std.h>
    21 #include <s32file.h>
    22 #include <bautils.h>
    23 #include <txtrich.h>
    24 #include <txtfmlyr.h>
    25 #include <txtmrtsr.h>
    26 #include <gdi.h>
    27 
    28 // User includes
    29 #include "hlpconstants.h"
    30 
    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;
    39 
    40 const TInt KIndexTblIndex = 1;
    41 const TInt KIndexTblIndexId = 2;
    42 
    43 const TInt KTopicIndexTblTopicId = 1;
    44 const TInt KTopicIndexTblIndexId = 2;
    45 const TInt KTopicIndexTblCategoryUID = 3;
    46 const TInt KTopicIndexTblTopicTitle = 4;
    47 
    48 const TInt KContextTblContext = 1;
    49 const TInt KContextTblTopicId = 2;
    50 
    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;
    56 
    57 
    58 
    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)");
    61 
    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)");
    64 
    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))");
    67 
    68 _LIT(KHlpDMLContextTable,		"CREATE TABLE Context (Context CHAR(30), TopicId UNSIGNED INTEGER)");
    69 
    70 _LIT(KHlpDMLImageTable,			"CREATE TABLE Image (ImageId UNSIGNED INTEGER, ImageCount UNSIGNED INTEGER, Image0 LONG VARBINARY, Image1 LONG VARBINARY, Image2 LONG VARBINARY)");
    71 
    72 
    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)");
    78 
    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");
    85 
    86 // enum for selecting a table for writing to
    87 enum
    88 	{
    89 	ETopicTable,
    90 	EIndexTable,
    91 	ETopicIndexTable,
    92 	EContextTable,
    93 	EImageTable
    94 	};
    95 
    96 
    97 class CHlpTable;
    98 
    99 // CHlpDbWriter class: creates the store and the database, and provides the interface to write to the file
   100 class CHlpDbWriter : public CBase
   101 /**
   102 @internalComponent
   103 @released
   104 */
   105 	{
   106 public:
   107 	IMPORT_C	~CHlpDbWriter();
   108 	IMPORT_C	static CHlpDbWriter* NewL(RFs& aFs);
   109 	IMPORT_C	static CHlpDbWriter* NewLC(RFs& aFs);
   110 public:
   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();
   116 public:
   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;
   121 public:
   122 	IMPORT_C	void BeginTransaction();
   123 	IMPORT_C	void CommitTransaction();
   124 public:
   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);
   131 private:
   132 	void DoCreateDatabaseL();
   133 	CHlpTable* DoOpenTableLC(TInt aTable);
   134 	void DoOpenTablesL();
   135 	void StoreUidsL();
   136 	void StoreStreamDictionaryL();
   137 private:
   138 	CHlpDbWriter(RFs& aFs);
   139 	void ConstructL();
   140 private:
   141 	RFs& iFs;
   142 	TFileName iFileName;
   143 
   144 	RDbStoreDatabase iDatabase;
   145 	CArrayFixFlat<TUid>* iUids;
   146 	CArrayPtrFlat<CHlpTable>* iTables;
   147 	CArrayFixFlat<TUid>* iImagesAlreadyStored;
   148 
   149 	CPermanentFileStore* iStore;
   150 	CStreamDictionary* iDictionary;
   151 	};
   152 
   153 class THlpStoreResolver : public MRichTextStoreResolver
   154 /**
   155 @internalComponent
   156 @released
   157 */
   158 	{
   159 public:
   160 	virtual const CStreamStore& StreamStoreL(TInt aPos) const;
   161 	CStreamStore* iStore;
   162 	};
   163 
   164 // CHlpRowSet class: abstract class for accessing database tables
   165 class CHlpRowSet : public CBase
   166 /**
   167 @internalComponent
   168 @released
   169 */
   170 	{
   171 public:
   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();
   180 public:
   181 	IMPORT_C	void NextL();
   182 	IMPORT_C	void PreviousL();
   183 public:
   184 	IMPORT_C	TDbColNo MapColNameToColNo(const TDbCol& aCol);
   185 	IMPORT_C	TDbColNo MapColNameToColNo(const TDesC& aName);
   186 	IMPORT_C	CDbColSet* ColSet();
   187 
   188 	IMPORT_C	RDbView* View();
   189 private:
   190 	RDbView* iView;
   191 	};
   192 
   193 // CHlpView class: concrete class used for accessing database tables (for test code)
   194 class CHlpView : public CHlpRowSet
   195 /**
   196 @internalComponent
   197 @released
   198 */
   199 	{
   200 public:
   201 	IMPORT_C	static CHlpView* NewL(RDbView* aView);
   202 	IMPORT_C	static CHlpView* NewLC(RDbView* aView);
   203 	~CHlpView();
   204 public:
   205 	inline void SetPictureFactory(MPictureFactory* aPictureFactory) {iPictureFactory=aPictureFactory;};
   206 public:
   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();
   211 private:
   212 	void GetMarkupL(CRichText& aRichText, TDbColNo aMarkupCol);
   213 private:
   214 	CHlpView(RDbView* aView);
   215 	void ConstructL();
   216 private:
   217 	THlpStoreResolver iStoreResolver;
   218 	MPictureFactory *iPictureFactory;
   219 	TBool iHasRows;
   220 	};
   221 
   222 // CHlpTable class: concrete class used for writing to database tables
   223 class CHlpTable : public CHlpRowSet
   224 /**
   225 @internalComponent
   226 @released
   227 */
   228 	{
   229 public:
   230 	IMPORT_C	static CHlpTable* NewL(RDbView* aView);
   231 	IMPORT_C	static CHlpTable* NewLC(RDbView* aView);
   232 	~CHlpTable();
   233 public:
   234 	IMPORT_C	void InsertL();
   235 	IMPORT_C	void PutL();
   236 public:
   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);
   242 private:
   243 	void SetMarkupL(CRichText& aRichText, TDbColNo aMarkupCol);
   244 	void SetLongTextL(const TDesC& aText, TDbColNo aLongTextCol);
   245 private:
   246 	CHlpTable(RDbView* aView); 
   247 	void ConstructL();
   248 	};
   249 
   250 #endif