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.
williamr@4
     1
// Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
williamr@4
     2
// All rights reserved.
williamr@4
     3
// This component and the accompanying materials are made available
williamr@4
     4
// under the terms of "Eclipse Public License v1.0"
williamr@4
     5
// which accompanies this distribution, and is available
williamr@4
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
williamr@4
     7
//
williamr@4
     8
// Initial Contributors:
williamr@4
     9
// Nokia Corporation - initial contribution.
williamr@4
    10
//
williamr@4
    11
// Contributors:
williamr@4
    12
//
williamr@4
    13
// Description:
williamr@4
    14
//
williamr@4
    15
williamr@4
    16
#ifndef __DBWRITER_H__
williamr@4
    17
#define __DBWRITER_H__
williamr@4
    18
williamr@4
    19
#include <d32dbms.h>
williamr@4
    20
#include <e32std.h>
williamr@4
    21
#include <s32file.h>
williamr@4
    22
#include <bautils.h>
williamr@4
    23
#include <txtrich.h>
williamr@4
    24
#include <txtfmlyr.h>
williamr@4
    25
#include <txtmrtsr.h>
williamr@4
    26
#include <gdi.h>
williamr@4
    27
williamr@4
    28
// User includes
williamr@4
    29
#include "hlpconstants.h"
williamr@4
    30
williamr@4
    31
// Db writer constants
williamr@4
    32
const TInt KTopicTblTopicTitle = 1;
williamr@4
    33
const TInt KTopicTblCategoryTitle = 2;
williamr@4
    34
const TInt KTopicTblTopicText = 3;
williamr@4
    35
const TInt KTopicTblTopicMarkup = 4;
williamr@4
    36
const TInt KTopicTblSynonym = 5;
williamr@4
    37
const TInt KTopicTblTopicId = 6;
williamr@4
    38
const TInt KTopicTblCategoryUID = 7;
williamr@4
    39
williamr@4
    40
const TInt KIndexTblIndex = 1;
williamr@4
    41
const TInt KIndexTblIndexId = 2;
williamr@4
    42
williamr@4
    43
const TInt KTopicIndexTblTopicId = 1;
williamr@4
    44
const TInt KTopicIndexTblIndexId = 2;
williamr@4
    45
const TInt KTopicIndexTblCategoryUID = 3;
williamr@4
    46
const TInt KTopicIndexTblTopicTitle = 4;
williamr@4
    47
williamr@4
    48
const TInt KContextTblContext = 1;
williamr@4
    49
const TInt KContextTblTopicId = 2;
williamr@4
    50
williamr@4
    51
const TInt KImageTblImageId = 1;
williamr@4
    52
const TInt KImageTblImageCount = 2;
williamr@4
    53
const TInt KImageTblImage0 = 3;
williamr@4
    54
const TInt KImageTblImage1 = 4;
williamr@4
    55
const TInt KImageTblImage2 = 5;
williamr@4
    56
williamr@4
    57
williamr@4
    58
williamr@4
    59
// DML statements used in creating the database tables and indices
williamr@4
    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)");
williamr@4
    61
williamr@4
    62
// IndexeId's are unique on a per-helpfile basis, ie. all indexId's in one help file are unique.
williamr@4
    63
_LIT(KHlpDMLIndexTable,			"CREATE TABLE Index (Index CHAR(120), IndexId UNSIGNED INTEGER)");
williamr@4
    64
williamr@4
    65
// TopicId's are unique within a helpfile but not across a help file
williamr@4
    66
_LIT(KHlpDMLTopicIndexTable,	"CREATE TABLE TopicIndex (TopicId UNSIGNED INTEGER, IndexId UNSIGNED INTEGER, CategoryUID UNSIGNED INTEGER, TopicTitle CHAR(120))");
williamr@4
    67
williamr@4
    68
_LIT(KHlpDMLContextTable,		"CREATE TABLE Context (Context CHAR(30), TopicId UNSIGNED INTEGER)");
williamr@4
    69
williamr@4
    70
_LIT(KHlpDMLImageTable,			"CREATE TABLE Image (ImageId UNSIGNED INTEGER, ImageCount UNSIGNED INTEGER, Image0 LONG VARBINARY, Image1 LONG VARBINARY, Image2 LONG VARBINARY)");
williamr@4
    71
williamr@4
    72
williamr@4
    73
_LIT(KHlpDMLTopicTableIdx,		"CREATE UNIQUE INDEX TopicIdx ON Topic (TopicId)");
williamr@4
    74
_LIT(KHlpDMLIndexTableIdx,		"CREATE UNIQUE INDEX IndexIdx ON Index (IndexId)");
williamr@4
    75
_LIT(KHlpDMLTopicIndexTableIdx, "CREATE UNIQUE INDEX TopicIndexIdx ON TopicIndex (IndexId, TopicId)");
williamr@4
    76
_LIT(KHlpDMLContextTableIdx,	"CREATE UNIQUE INDEX ContextIdx ON Context (Context)");
williamr@4
    77
_LIT(KHlpDMLImageTableIdx,		"CREATE UNIQUE INDEX ImageIdx ON Image (ImageId)");
williamr@4
    78
williamr@4
    79
// DDL statements used in opening tables for writing
williamr@4
    80
_LIT(KHlpSQLTopicTable,			"SELECT * FROM Topic");
williamr@4
    81
_LIT(KHlpSQLIndexTable,			"SELECT * FROM Index");
williamr@4
    82
_LIT(KHlpSQLTopicIndexTable,	"SELECT * FROM TopicIndex");
williamr@4
    83
_LIT(KHlpSQLContextTable,		"SELECT * FROM Context");
williamr@4
    84
_LIT(KHlpSQLImageTable,			"SELECT * FROM Image");
williamr@4
    85
williamr@4
    86
// enum for selecting a table for writing to
williamr@4
    87
enum
williamr@4
    88
	{
williamr@4
    89
	ETopicTable,
williamr@4
    90
	EIndexTable,
williamr@4
    91
	ETopicIndexTable,
williamr@4
    92
	EContextTable,
williamr@4
    93
	EImageTable
williamr@4
    94
	};
williamr@4
    95
williamr@4
    96
williamr@4
    97
class CHlpTable;
williamr@4
    98
williamr@4
    99
// CHlpDbWriter class: creates the store and the database, and provides the interface to write to the file
williamr@4
   100
class CHlpDbWriter : public CBase
williamr@4
   101
/**
williamr@4
   102
@internalComponent
williamr@4
   103
@released
williamr@4
   104
*/
williamr@4
   105
	{
williamr@4
   106
public:
williamr@4
   107
	IMPORT_C	~CHlpDbWriter();
williamr@4
   108
	IMPORT_C	static CHlpDbWriter* NewL(RFs& aFs);
williamr@4
   109
	IMPORT_C	static CHlpDbWriter* NewLC(RFs& aFs);
williamr@4
   110
public:
williamr@4
   111
	IMPORT_C	void CreateFileL(const TDesC& aFileName);
williamr@4
   112
	IMPORT_C	void CreateDatabaseL();
williamr@4
   113
	IMPORT_C	void CompressDatabaseL();
williamr@4
   114
	IMPORT_C	void SetDatabaseUidL(TUid& aUid);
williamr@4
   115
	IMPORT_C	void CloseFileL();
williamr@4
   116
public:
williamr@4
   117
	IMPORT_C	void AddBitmapL(TInt aBitmapId);
williamr@4
   118
	IMPORT_C	TBool IsBitmapStored(TInt aBitmapId) const;
williamr@4
   119
	IMPORT_C	TInt BitmapCount() const;
williamr@4
   120
	IMPORT_C	TInt BitmapIdForIndex(TInt aIndex) const;
williamr@4
   121
public:
williamr@4
   122
	IMPORT_C	void BeginTransaction();
williamr@4
   123
	IMPORT_C	void CommitTransaction();
williamr@4
   124
public:
williamr@4
   125
	IMPORT_C	CHlpTable* TopicTable();
williamr@4
   126
	IMPORT_C	CHlpTable* IndexTable();
williamr@4
   127
	IMPORT_C	CHlpTable* TopicIndexTable();
williamr@4
   128
	IMPORT_C	CHlpTable* ContextTable();
williamr@4
   129
	IMPORT_C	CHlpTable* ImageTable();
williamr@4
   130
	IMPORT_C	void SetUidL(TUid aUid);
williamr@4
   131
private:
williamr@4
   132
	void DoCreateDatabaseL();
williamr@4
   133
	CHlpTable* DoOpenTableLC(TInt aTable);
williamr@4
   134
	void DoOpenTablesL();
williamr@4
   135
	void StoreUidsL();
williamr@4
   136
	void StoreStreamDictionaryL();
williamr@4
   137
private:
williamr@4
   138
	CHlpDbWriter(RFs& aFs);
williamr@4
   139
	void ConstructL();
williamr@4
   140
private:
williamr@4
   141
	RFs& iFs;
williamr@4
   142
	TFileName iFileName;
williamr@4
   143
williamr@4
   144
	RDbStoreDatabase iDatabase;
williamr@4
   145
	CArrayFixFlat<TUid>* iUids;
williamr@4
   146
	CArrayPtrFlat<CHlpTable>* iTables;
williamr@4
   147
	CArrayFixFlat<TUid>* iImagesAlreadyStored;
williamr@4
   148
williamr@4
   149
	CPermanentFileStore* iStore;
williamr@4
   150
	CStreamDictionary* iDictionary;
williamr@4
   151
	};
williamr@4
   152
williamr@4
   153
class THlpStoreResolver : public MRichTextStoreResolver
williamr@4
   154
/**
williamr@4
   155
@internalComponent
williamr@4
   156
@released
williamr@4
   157
*/
williamr@4
   158
	{
williamr@4
   159
public:
williamr@4
   160
	virtual const CStreamStore& StreamStoreL(TInt aPos) const;
williamr@4
   161
	CStreamStore* iStore;
williamr@4
   162
	};
williamr@4
   163
williamr@4
   164
// CHlpRowSet class: abstract class for accessing database tables
williamr@4
   165
class CHlpRowSet : public CBase
williamr@4
   166
/**
williamr@4
   167
@internalComponent
williamr@4
   168
@released
williamr@4
   169
*/
williamr@4
   170
	{
williamr@4
   171
public:
williamr@4
   172
	CHlpRowSet(RDbView* aView);
williamr@4
   173
	IMPORT_C	virtual ~CHlpRowSet();
williamr@4
   174
	IMPORT_C	TBool AtRow();
williamr@4
   175
	IMPORT_C	TBool AtBeginning();	
williamr@4
   176
	IMPORT_C	TBool AtEnd();
williamr@4
   177
	IMPORT_C	TBool FirstL();
williamr@4
   178
	IMPORT_C	TBool LastL();
williamr@4
   179
	IMPORT_C	TInt  CountL();
williamr@4
   180
public:
williamr@4
   181
	IMPORT_C	void NextL();
williamr@4
   182
	IMPORT_C	void PreviousL();
williamr@4
   183
public:
williamr@4
   184
	IMPORT_C	TDbColNo MapColNameToColNo(const TDbCol& aCol);
williamr@4
   185
	IMPORT_C	TDbColNo MapColNameToColNo(const TDesC& aName);
williamr@4
   186
	IMPORT_C	CDbColSet* ColSet();
williamr@4
   187
williamr@4
   188
	IMPORT_C	RDbView* View();
williamr@4
   189
private:
williamr@4
   190
	RDbView* iView;
williamr@4
   191
	};
williamr@4
   192
williamr@4
   193
// CHlpView class: concrete class used for accessing database tables (for test code)
williamr@4
   194
class CHlpView : public CHlpRowSet
williamr@4
   195
/**
williamr@4
   196
@internalComponent
williamr@4
   197
@released
williamr@4
   198
*/
williamr@4
   199
	{
williamr@4
   200
public:
williamr@4
   201
	IMPORT_C	static CHlpView* NewL(RDbView* aView);
williamr@4
   202
	IMPORT_C	static CHlpView* NewLC(RDbView* aView);
williamr@4
   203
	~CHlpView();
williamr@4
   204
public:
williamr@4
   205
	inline void SetPictureFactory(MPictureFactory* aPictureFactory) {iPictureFactory=aPictureFactory;};
williamr@4
   206
public:
williamr@4
   207
	IMPORT_C	void GetTextL(TDbColNo aCol, TDes& aText);
williamr@4
   208
	IMPORT_C	void GetRichTextL(TDbColNo aTextCol, TDbColNo aMarkupCol, CRichText& aRichText);
williamr@4
   209
	IMPORT_C	void GetValL(TDbColNo aCol, TUint32& aValue);
williamr@4
   210
	IMPORT_C	void GetL();
williamr@4
   211
private:
williamr@4
   212
	void GetMarkupL(CRichText& aRichText, TDbColNo aMarkupCol);
williamr@4
   213
private:
williamr@4
   214
	CHlpView(RDbView* aView);
williamr@4
   215
	void ConstructL();
williamr@4
   216
private:
williamr@4
   217
	THlpStoreResolver iStoreResolver;
williamr@4
   218
	MPictureFactory *iPictureFactory;
williamr@4
   219
	TBool iHasRows;
williamr@4
   220
	};
williamr@4
   221
williamr@4
   222
// CHlpTable class: concrete class used for writing to database tables
williamr@4
   223
class CHlpTable : public CHlpRowSet
williamr@4
   224
/**
williamr@4
   225
@internalComponent
williamr@4
   226
@released
williamr@4
   227
*/
williamr@4
   228
	{
williamr@4
   229
public:
williamr@4
   230
	IMPORT_C	static CHlpTable* NewL(RDbView* aView);
williamr@4
   231
	IMPORT_C	static CHlpTable* NewLC(RDbView* aView);
williamr@4
   232
	~CHlpTable();
williamr@4
   233
public:
williamr@4
   234
	IMPORT_C	void InsertL();
williamr@4
   235
	IMPORT_C	void PutL();
williamr@4
   236
public:
williamr@4
   237
	IMPORT_C	void SetColL(TDbColNo aCol, const TDesC& aText);
williamr@4
   238
	IMPORT_C	void SetColL(TDbColNo aTextCol, TDbColNo aMarkupCol, CRichText& aRichText);
williamr@4
   239
	IMPORT_C	void SetColL(TDbColNo aTextCol, CRichText& aRichText);
williamr@4
   240
	IMPORT_C	void SetColL(TDbColNo aCol, TUint32 aValue);
williamr@4
   241
	IMPORT_C	void SetColL(TDbColNo aCol, const CFbsBitmap& aBitmap);
williamr@4
   242
private:
williamr@4
   243
	void SetMarkupL(CRichText& aRichText, TDbColNo aMarkupCol);
williamr@4
   244
	void SetLongTextL(const TDesC& aText, TDbColNo aLongTextCol);
williamr@4
   245
private:
williamr@4
   246
	CHlpTable(RDbView* aView); 
williamr@4
   247
	void ConstructL();
williamr@4
   248
	};
williamr@4
   249
williamr@4
   250
#endif