epoc32/include/app/dbwriter.h
branchSymbian3
changeset 4 837f303aceeb
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/app/dbwriter.h	Wed Mar 31 12:33:34 2010 +0100
     1.3 @@ -0,0 +1,250 @@
     1.4 +// Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#ifndef __DBWRITER_H__
    1.20 +#define __DBWRITER_H__
    1.21 +
    1.22 +#include <d32dbms.h>
    1.23 +#include <e32std.h>
    1.24 +#include <s32file.h>
    1.25 +#include <bautils.h>
    1.26 +#include <txtrich.h>
    1.27 +#include <txtfmlyr.h>
    1.28 +#include <txtmrtsr.h>
    1.29 +#include <gdi.h>
    1.30 +
    1.31 +// User includes
    1.32 +#include "hlpconstants.h"
    1.33 +
    1.34 +// Db writer constants
    1.35 +const TInt KTopicTblTopicTitle = 1;
    1.36 +const TInt KTopicTblCategoryTitle = 2;
    1.37 +const TInt KTopicTblTopicText = 3;
    1.38 +const TInt KTopicTblTopicMarkup = 4;
    1.39 +const TInt KTopicTblSynonym = 5;
    1.40 +const TInt KTopicTblTopicId = 6;
    1.41 +const TInt KTopicTblCategoryUID = 7;
    1.42 +
    1.43 +const TInt KIndexTblIndex = 1;
    1.44 +const TInt KIndexTblIndexId = 2;
    1.45 +
    1.46 +const TInt KTopicIndexTblTopicId = 1;
    1.47 +const TInt KTopicIndexTblIndexId = 2;
    1.48 +const TInt KTopicIndexTblCategoryUID = 3;
    1.49 +const TInt KTopicIndexTblTopicTitle = 4;
    1.50 +
    1.51 +const TInt KContextTblContext = 1;
    1.52 +const TInt KContextTblTopicId = 2;
    1.53 +
    1.54 +const TInt KImageTblImageId = 1;
    1.55 +const TInt KImageTblImageCount = 2;
    1.56 +const TInt KImageTblImage0 = 3;
    1.57 +const TInt KImageTblImage1 = 4;
    1.58 +const TInt KImageTblImage2 = 5;
    1.59 +
    1.60 +
    1.61 +
    1.62 +// DML statements used in creating the database tables and indices
    1.63 +_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)");
    1.64 +
    1.65 +// IndexeId's are unique on a per-helpfile basis, ie. all indexId's in one help file are unique.
    1.66 +_LIT(KHlpDMLIndexTable,			"CREATE TABLE Index (Index CHAR(120), IndexId UNSIGNED INTEGER)");
    1.67 +
    1.68 +// TopicId's are unique within a helpfile but not across a help file
    1.69 +_LIT(KHlpDMLTopicIndexTable,	"CREATE TABLE TopicIndex (TopicId UNSIGNED INTEGER, IndexId UNSIGNED INTEGER, CategoryUID UNSIGNED INTEGER, TopicTitle CHAR(120))");
    1.70 +
    1.71 +_LIT(KHlpDMLContextTable,		"CREATE TABLE Context (Context CHAR(30), TopicId UNSIGNED INTEGER)");
    1.72 +
    1.73 +_LIT(KHlpDMLImageTable,			"CREATE TABLE Image (ImageId UNSIGNED INTEGER, ImageCount UNSIGNED INTEGER, Image0 LONG VARBINARY, Image1 LONG VARBINARY, Image2 LONG VARBINARY)");
    1.74 +
    1.75 +
    1.76 +_LIT(KHlpDMLTopicTableIdx,		"CREATE UNIQUE INDEX TopicIdx ON Topic (TopicId)");
    1.77 +_LIT(KHlpDMLIndexTableIdx,		"CREATE UNIQUE INDEX IndexIdx ON Index (IndexId)");
    1.78 +_LIT(KHlpDMLTopicIndexTableIdx, "CREATE UNIQUE INDEX TopicIndexIdx ON TopicIndex (IndexId, TopicId)");
    1.79 +_LIT(KHlpDMLContextTableIdx,	"CREATE UNIQUE INDEX ContextIdx ON Context (Context)");
    1.80 +_LIT(KHlpDMLImageTableIdx,		"CREATE UNIQUE INDEX ImageIdx ON Image (ImageId)");
    1.81 +
    1.82 +// DDL statements used in opening tables for writing
    1.83 +_LIT(KHlpSQLTopicTable,			"SELECT * FROM Topic");
    1.84 +_LIT(KHlpSQLIndexTable,			"SELECT * FROM Index");
    1.85 +_LIT(KHlpSQLTopicIndexTable,	"SELECT * FROM TopicIndex");
    1.86 +_LIT(KHlpSQLContextTable,		"SELECT * FROM Context");
    1.87 +_LIT(KHlpSQLImageTable,			"SELECT * FROM Image");
    1.88 +
    1.89 +// enum for selecting a table for writing to
    1.90 +enum
    1.91 +	{
    1.92 +	ETopicTable,
    1.93 +	EIndexTable,
    1.94 +	ETopicIndexTable,
    1.95 +	EContextTable,
    1.96 +	EImageTable
    1.97 +	};
    1.98 +
    1.99 +
   1.100 +class CHlpTable;
   1.101 +
   1.102 +// CHlpDbWriter class: creates the store and the database, and provides the interface to write to the file
   1.103 +class CHlpDbWriter : public CBase
   1.104 +/**
   1.105 +@internalComponent
   1.106 +@released
   1.107 +*/
   1.108 +	{
   1.109 +public:
   1.110 +	IMPORT_C	~CHlpDbWriter();
   1.111 +	IMPORT_C	static CHlpDbWriter* NewL(RFs& aFs);
   1.112 +	IMPORT_C	static CHlpDbWriter* NewLC(RFs& aFs);
   1.113 +public:
   1.114 +	IMPORT_C	void CreateFileL(const TDesC& aFileName);
   1.115 +	IMPORT_C	void CreateDatabaseL();
   1.116 +	IMPORT_C	void CompressDatabaseL();
   1.117 +	IMPORT_C	void SetDatabaseUidL(TUid& aUid);
   1.118 +	IMPORT_C	void CloseFileL();
   1.119 +public:
   1.120 +	IMPORT_C	void AddBitmapL(TInt aBitmapId);
   1.121 +	IMPORT_C	TBool IsBitmapStored(TInt aBitmapId) const;
   1.122 +	IMPORT_C	TInt BitmapCount() const;
   1.123 +	IMPORT_C	TInt BitmapIdForIndex(TInt aIndex) const;
   1.124 +public:
   1.125 +	IMPORT_C	void BeginTransaction();
   1.126 +	IMPORT_C	void CommitTransaction();
   1.127 +public:
   1.128 +	IMPORT_C	CHlpTable* TopicTable();
   1.129 +	IMPORT_C	CHlpTable* IndexTable();
   1.130 +	IMPORT_C	CHlpTable* TopicIndexTable();
   1.131 +	IMPORT_C	CHlpTable* ContextTable();
   1.132 +	IMPORT_C	CHlpTable* ImageTable();
   1.133 +	IMPORT_C	void SetUidL(TUid aUid);
   1.134 +private:
   1.135 +	void DoCreateDatabaseL();
   1.136 +	CHlpTable* DoOpenTableLC(TInt aTable);
   1.137 +	void DoOpenTablesL();
   1.138 +	void StoreUidsL();
   1.139 +	void StoreStreamDictionaryL();
   1.140 +private:
   1.141 +	CHlpDbWriter(RFs& aFs);
   1.142 +	void ConstructL();
   1.143 +private:
   1.144 +	RFs& iFs;
   1.145 +	TFileName iFileName;
   1.146 +
   1.147 +	RDbStoreDatabase iDatabase;
   1.148 +	CArrayFixFlat<TUid>* iUids;
   1.149 +	CArrayPtrFlat<CHlpTable>* iTables;
   1.150 +	CArrayFixFlat<TUid>* iImagesAlreadyStored;
   1.151 +
   1.152 +	CPermanentFileStore* iStore;
   1.153 +	CStreamDictionary* iDictionary;
   1.154 +	};
   1.155 +
   1.156 +class THlpStoreResolver : public MRichTextStoreResolver
   1.157 +/**
   1.158 +@internalComponent
   1.159 +@released
   1.160 +*/
   1.161 +	{
   1.162 +public:
   1.163 +	virtual const CStreamStore& StreamStoreL(TInt aPos) const;
   1.164 +	CStreamStore* iStore;
   1.165 +	};
   1.166 +
   1.167 +// CHlpRowSet class: abstract class for accessing database tables
   1.168 +class CHlpRowSet : public CBase
   1.169 +/**
   1.170 +@internalComponent
   1.171 +@released
   1.172 +*/
   1.173 +	{
   1.174 +public:
   1.175 +	CHlpRowSet(RDbView* aView);
   1.176 +	IMPORT_C	virtual ~CHlpRowSet();
   1.177 +	IMPORT_C	TBool AtRow();
   1.178 +	IMPORT_C	TBool AtBeginning();	
   1.179 +	IMPORT_C	TBool AtEnd();
   1.180 +	IMPORT_C	TBool FirstL();
   1.181 +	IMPORT_C	TBool LastL();
   1.182 +	IMPORT_C	TInt  CountL();
   1.183 +public:
   1.184 +	IMPORT_C	void NextL();
   1.185 +	IMPORT_C	void PreviousL();
   1.186 +public:
   1.187 +	IMPORT_C	TDbColNo MapColNameToColNo(const TDbCol& aCol);
   1.188 +	IMPORT_C	TDbColNo MapColNameToColNo(const TDesC& aName);
   1.189 +	IMPORT_C	CDbColSet* ColSet();
   1.190 +
   1.191 +	IMPORT_C	RDbView* View();
   1.192 +private:
   1.193 +	RDbView* iView;
   1.194 +	};
   1.195 +
   1.196 +// CHlpView class: concrete class used for accessing database tables (for test code)
   1.197 +class CHlpView : public CHlpRowSet
   1.198 +/**
   1.199 +@internalComponent
   1.200 +@released
   1.201 +*/
   1.202 +	{
   1.203 +public:
   1.204 +	IMPORT_C	static CHlpView* NewL(RDbView* aView);
   1.205 +	IMPORT_C	static CHlpView* NewLC(RDbView* aView);
   1.206 +	~CHlpView();
   1.207 +public:
   1.208 +	inline void SetPictureFactory(MPictureFactory* aPictureFactory) {iPictureFactory=aPictureFactory;};
   1.209 +public:
   1.210 +	IMPORT_C	void GetTextL(TDbColNo aCol, TDes& aText);
   1.211 +	IMPORT_C	void GetRichTextL(TDbColNo aTextCol, TDbColNo aMarkupCol, CRichText& aRichText);
   1.212 +	IMPORT_C	void GetValL(TDbColNo aCol, TUint32& aValue);
   1.213 +	IMPORT_C	void GetL();
   1.214 +private:
   1.215 +	void GetMarkupL(CRichText& aRichText, TDbColNo aMarkupCol);
   1.216 +private:
   1.217 +	CHlpView(RDbView* aView);
   1.218 +	void ConstructL();
   1.219 +private:
   1.220 +	THlpStoreResolver iStoreResolver;
   1.221 +	MPictureFactory *iPictureFactory;
   1.222 +	TBool iHasRows;
   1.223 +	};
   1.224 +
   1.225 +// CHlpTable class: concrete class used for writing to database tables
   1.226 +class CHlpTable : public CHlpRowSet
   1.227 +/**
   1.228 +@internalComponent
   1.229 +@released
   1.230 +*/
   1.231 +	{
   1.232 +public:
   1.233 +	IMPORT_C	static CHlpTable* NewL(RDbView* aView);
   1.234 +	IMPORT_C	static CHlpTable* NewLC(RDbView* aView);
   1.235 +	~CHlpTable();
   1.236 +public:
   1.237 +	IMPORT_C	void InsertL();
   1.238 +	IMPORT_C	void PutL();
   1.239 +public:
   1.240 +	IMPORT_C	void SetColL(TDbColNo aCol, const TDesC& aText);
   1.241 +	IMPORT_C	void SetColL(TDbColNo aTextCol, TDbColNo aMarkupCol, CRichText& aRichText);
   1.242 +	IMPORT_C	void SetColL(TDbColNo aTextCol, CRichText& aRichText);
   1.243 +	IMPORT_C	void SetColL(TDbColNo aCol, TUint32 aValue);
   1.244 +	IMPORT_C	void SetColL(TDbColNo aCol, const CFbsBitmap& aBitmap);
   1.245 +private:
   1.246 +	void SetMarkupL(CRichText& aRichText, TDbColNo aMarkupCol);
   1.247 +	void SetLongTextL(const TDesC& aText, TDbColNo aLongTextCol);
   1.248 +private:
   1.249 +	CHlpTable(RDbView* aView); 
   1.250 +	void ConstructL();
   1.251 +	};
   1.252 +
   1.253 +#endif