os/persistentdata/persistentstorage/dbms/utable/UT_STD.H
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include "U32STD.H"
sl@0
    17
#include <d32dbms.h>
sl@0
    18
#include "D32REC.H"
sl@0
    19
#include "D32TABLE.H"
sl@0
    20
#include "D32SQL.H"
sl@0
    21
#include <s32mem.h>
sl@0
    22
sl@0
    23
/**
sl@0
    24
@internalComponent
sl@0
    25
*/
sl@0
    26
enum TTablePanic
sl@0
    27
	{
sl@0
    28
	EDbInvalidColumn,
sl@0
    29
	EDbWrongType,
sl@0
    30
	EDbInUpdate,
sl@0
    31
	EDbNotInUpdate,
sl@0
    32
	EDbInvalidRow,
sl@0
    33
	EDbRowNotRead,
sl@0
    34
	EDbReadOnly,
sl@0
    35
	EDbTableOpen,
sl@0
    36
	EDbNotEvaluated,
sl@0
    37
	EDbStreamOpen,
sl@0
    38
	EDbRowSetConstraintMismatch,
sl@0
    39
	EDbBeginNestedTransaction,
sl@0
    40
	EDbUpdatesPendingOnCommit,
sl@0
    41
	EDbUpdatesPendingOnRollback,
sl@0
    42
	EDbNoCurrentTransaction,
sl@0
    43
	EDbStreamsPendingOnCommit,
sl@0
    44
	EDbStreamsPendingOnRollback,
sl@0
    45
	EDbInvalidBookmark
sl@0
    46
	};
sl@0
    47
sl@0
    48
/**
sl@0
    49
@internalComponent
sl@0
    50
*/
sl@0
    51
GLREF_C void Panic( TTablePanic aPanic );
sl@0
    52
sl@0
    53
class Validate
sl@0
    54
/**
sl@0
    55
@internalComponent
sl@0
    56
*/
sl@0
    57
	{
sl@0
    58
public:
sl@0
    59
	static void NameL( const TDesC& aName );
sl@0
    60
	static void ColSetL( const CDbColSet& aColSet );
sl@0
    61
	static void KeyL( const CDbKey& aKey, const HDbColumnSet& aColumns );
sl@0
    62
private:
sl@0
    63
	static void UniqueNameL( TDesC const** aNames, TInt aCount, const TDesC& aName );
sl@0
    64
	};
sl@0
    65
sl@0
    66
class CDbDataSource : public CBase
sl@0
    67
/**
sl@0
    68
@internalComponent
sl@0
    69
*/
sl@0
    70
	{
sl@0
    71
public:
sl@0
    72
	enum TGoto { ESuccess, ENoRow, EExhausted, ESynchFailure };
sl@0
    73
	enum TSynch { ESynch, ENoSynch };
sl@0
    74
	enum TDelete { EDeletedAtNext, EDeletedAtEnd, EDeletedInLimbo };
sl@0
    75
	enum TWrite { EReplace, EAppend };
sl@0
    76
protected:
sl@0
    77
	enum { EWorkToIterate = 1, EWorkToRead = 16 };
sl@0
    78
public:
sl@0
    79
	virtual RDbRow* RowBuffer() = 0;
sl@0
    80
	virtual TDbColumn Column( TDbColNo aColNo ) = 0;
sl@0
    81
	virtual void Reset() = 0;
sl@0
    82
	virtual TBool EvaluateL( TInt& aWork, TDbRecordId& aRecordId, TBool& aAtRow ) = 0;
sl@0
    83
	virtual TBool Unevaluated() = 0;
sl@0
    84
	virtual TInt CountL() = 0;
sl@0
    85
	virtual TGoto GotoL( TInt& aWork, TDbPosition aPosition, TDbRecordId& aRecordId ) = 0;
sl@0
    86
	TGoto GotoL( TDbPosition aPosition, TDbRecordId& aRecordId );
sl@0
    87
	virtual TBool GotoL( TDbRecordId aRecordId ) = 0;
sl@0
    88
	virtual void ReadRowL( TDbRecordId aRecordId ) = 0;
sl@0
    89
	virtual void NewRowL( TDbRecordId aCopyRecord ) = 0;
sl@0
    90
	virtual void PrepareToWriteRowL( TWrite aWrite ) = 0;
sl@0
    91
	virtual TDbRecordId WriteRowL( TWrite aWrite, TSynch aSynch = ESynch ) = 0;
sl@0
    92
	virtual TDelete DeleteRowL( TDbRecordId& aRecordId, TSynch aSynch = ESynch ) = 0;
sl@0
    93
	virtual TInt ColumnCount() const = 0;
sl@0
    94
	virtual const TDbColumnDef& ColumnDef( TDbColNo aCol ) const = 0;
sl@0
    95
//
sl@0
    96
	virtual void SetIndexL( const TDesC* anIndex ) = 0;
sl@0
    97
	virtual TBool SeekL( const TDbLookupKey& aKey, RDbTable::TComparison aComparison, TDbRecordId& aRecordId ) = 0;
sl@0
    98
	virtual CSqlSearchCondition* ParseConstraintLC( const TDesC& aCondition ) = 0;
sl@0
    99
protected:
sl@0
   100
	CDbDataSource() {};
sl@0
   101
	};
sl@0
   102
sl@0
   103
NONSHARABLE_CLASS(CDbTableSource) : public CDbDataSource
sl@0
   104
/**
sl@0
   105
@internalComponent
sl@0
   106
*/
sl@0
   107
	{
sl@0
   108
public:
sl@0
   109
	~CDbTableSource();
sl@0
   110
	CDbTableSource();
sl@0
   111
	void Construct( CDbTable* aTable );
sl@0
   112
	inline void SetIterator( CDbRecordIter* anIter );
sl@0
   113
	void ReverseIteratorL();
sl@0
   114
	inline const RDbTableRow& Row();
sl@0
   115
	inline CDbTable& Table();
sl@0
   116
//
sl@0
   117
	RDbRow* RowBuffer();
sl@0
   118
	TDbColumn Column( TDbColNo aColNo );
sl@0
   119
	void Reset();
sl@0
   120
	TBool EvaluateL( TInt& aWork, TDbRecordId& aRecordId, TBool& aAtRow );
sl@0
   121
	TBool Unevaluated();
sl@0
   122
	TInt CountL();
sl@0
   123
	TGoto GotoL( TInt& aWork, TDbPosition aPosition, TDbRecordId& aRecordId );
sl@0
   124
	TBool GotoL( TDbRecordId aRecordId );
sl@0
   125
	void NewRowL( TDbRecordId aCopyRecord );
sl@0
   126
	void PrepareToWriteRowL( TWrite aWrite );
sl@0
   127
	TDbRecordId WriteRowL( TWrite aWrite, TSynch aSynch );
sl@0
   128
	void ReadRowL( TDbRecordId aRecordId );
sl@0
   129
	TDelete DeleteRowL( TDbRecordId& aRecordId, TSynch aSynch );
sl@0
   130
	TInt ColumnCount() const;
sl@0
   131
	const TDbColumnDef& ColumnDef( TDbColNo aCol ) const;
sl@0
   132
	void SetIndexL( const TDesC* anIndex );
sl@0
   133
	TBool SeekL( const TDbLookupKey& aKey, RDbTable::TComparison aComparison, TDbRecordId& aRecordId );
sl@0
   134
	CSqlSearchCondition* ParseConstraintLC( const TDesC& aCondition );
sl@0
   135
private:
sl@0
   136
	TBool SynchL( TDbRecordId aRecordId );
sl@0
   137
	void OpenIteratorL();
sl@0
   138
private:
sl@0
   139
	CDbRecordIter* iIter;
sl@0
   140
	TDbGenerationMark iIterMark;
sl@0
   141
	RDbTableRow iRow;
sl@0
   142
	TBool iReset;
sl@0
   143
	};
sl@0
   144
sl@0
   145
NONSHARABLE_CLASS(CDbDataStage) : public CDbDataSource
sl@0
   146
/**
sl@0
   147
@internalComponent
sl@0
   148
*/
sl@0
   149
	{
sl@0
   150
public:
sl@0
   151
	~CDbDataStage();
sl@0
   152
	inline void SetSource( CDbDataSource* aSource );
sl@0
   153
protected:
sl@0
   154
	CDbDataStage() {};
sl@0
   155
	inline CDbDataSource& Source();
sl@0
   156
	inline const CDbDataSource& Source() const;
sl@0
   157
	RDbRow* RowBuffer();
sl@0
   158
	TDbColumn Column( TDbColNo aColNo );
sl@0
   159
	void Reset();
sl@0
   160
	TBool EvaluateL( TInt& aWork, TDbRecordId& aRecordId, TBool& aAtRow );
sl@0
   161
	TBool Unevaluated();
sl@0
   162
	TInt CountL();
sl@0
   163
	TGoto GotoL( TInt& aWork, TDbPosition aPosition, TDbRecordId& aRecordId );
sl@0
   164
	TBool GotoL( TDbRecordId aRecordId );
sl@0
   165
	void ReadRowL( TDbRecordId aRecordId );
sl@0
   166
	void NewRowL( TDbRecordId aCopyRecord );
sl@0
   167
	void PrepareToWriteRowL( TWrite aWrite );
sl@0
   168
	TDbRecordId WriteRowL( TWrite aWrite, TSynch aSynch );
sl@0
   169
	TDelete DeleteRowL( TDbRecordId& aRecordId, TSynch aSynch );
sl@0
   170
	TInt ColumnCount() const;
sl@0
   171
	const TDbColumnDef& ColumnDef( TDbColNo aCol ) const;
sl@0
   172
	void SetIndexL( const TDesC* anIndex );
sl@0
   173
	TBool SeekL( const TDbLookupKey& aKey, RDbTable::TComparison aComparison, TDbRecordId& aRecordId );
sl@0
   174
	CSqlSearchCondition* ParseConstraintLC( const TDesC& aCondition );
sl@0
   175
private:
sl@0
   176
	CDbDataSource* iSource;
sl@0
   177
	};
sl@0
   178
sl@0
   179
NONSHARABLE_CLASS(CDbRestrictStage) : public CDbDataStage
sl@0
   180
/**
sl@0
   181
@internalComponent
sl@0
   182
*/
sl@0
   183
	{
sl@0
   184
public:
sl@0
   185
	CDbRestrictStage( TDbTextComparison aComparison );
sl@0
   186
	~CDbRestrictStage();
sl@0
   187
	inline void SetRestriction( CSqlSearchCondition* aRestriction );
sl@0
   188
private:
sl@0
   189
	inline CSqlSearchCondition& Restriction() const;
sl@0
   190
	TBool FilterRowL( TDbRecordId aRecordId );
sl@0
   191
//
sl@0
   192
	TInt CountL();
sl@0
   193
	TGoto GotoL( TInt& aWork, TDbPosition aPosition, TDbRecordId& aRecordId );
sl@0
   194
	TBool GotoL( TDbRecordId aRecordId );
sl@0
   195
	TDelete DeleteRowL( TDbRecordId& aRecordId, TSynch aSynch );
sl@0
   196
private:
sl@0
   197
	CSqlSearchCondition* iRestriction;
sl@0
   198
	const TTextOps& iTextOp;
sl@0
   199
	};
sl@0
   200
sl@0
   201
class HDbColumnMap;
sl@0
   202
sl@0
   203
NONSHARABLE_CLASS(CDbProjectStage) : public CDbDataStage
sl@0
   204
/**
sl@0
   205
implement restricted column selection
sl@0
   206
@internalComponent
sl@0
   207
*/
sl@0
   208
	{
sl@0
   209
public:
sl@0
   210
	CDbProjectStage();
sl@0
   211
	~CDbProjectStage();
sl@0
   212
	void ConstructL( const RSqlColumnList& aSelect, const HDbColumnSet& aColumns );
sl@0
   213
private:
sl@0
   214
	RDbRow* RowBuffer();
sl@0
   215
	TDbColumn Column( TDbColNo aColNo );
sl@0
   216
	TInt ColumnCount() const;
sl@0
   217
	const TDbColumnDef& ColumnDef( TDbColNo aCol ) const;
sl@0
   218
private:
sl@0
   219
	HDbColumnMap* iMap;
sl@0
   220
	};
sl@0
   221
sl@0
   222
NONSHARABLE_CLASS(CDbBasicWindowStage) : public CDbDataStage
sl@0
   223
/**
sl@0
   224
@internalComponent
sl@0
   225
*/
sl@0
   226
	{
sl@0
   227
private:
sl@0
   228
	enum { EWindowArrayGranularity = 32 };	// 128 byte segments
sl@0
   229
public:
sl@0
   230
	CDbBasicWindowStage( const TDbWindow& aWindow );
sl@0
   231
protected:
sl@0
   232
// from CDbDataStage
sl@0
   233
	void Reset();
sl@0
   234
	TBool EvaluateL( TInt& aWork, TDbRecordId& aRecordId, TBool& aAtRow );
sl@0
   235
	TInt CountL();
sl@0
   236
	TGoto GotoL( TInt& aWork, TDbPosition aPosition, TDbRecordId& aRecordId );
sl@0
   237
	TBool GotoL( TDbRecordId aRecordId );
sl@0
   238
	void ReadRowL( TDbRecordId aRecordId );
sl@0
   239
	TDbRecordId WriteRowL( TWrite aWrite, TSynch aSynch );
sl@0
   240
	TDelete DeleteRowL( TDbRecordId& aRecordId, TSynch aSynch );
sl@0
   241
private:
sl@0
   242
	TBool GetRecord( TDbRecordId& aRecordId );
sl@0
   243
	TInt Find( TDbRecordId aRecordId, TInt& aPos );
sl@0
   244
	virtual TBool DoEvaluateL( TInt& aWork ) = 0;
sl@0
   245
protected:
sl@0
   246
	TDbWindow iWindow;		// the window shape
sl@0
   247
	CArrayFixSeg<TDbRecordId> iRecords;	// the window itself
sl@0
   248
	TInt iPos;				// the iterator over the window
sl@0
   249
	};
sl@0
   250
sl@0
   251
NONSHARABLE_CLASS(CDbWindowStage) : public CDbBasicWindowStage
sl@0
   252
/**
sl@0
   253
@internalComponent
sl@0
   254
*/
sl@0
   255
	{
sl@0
   256
private:
sl@0
   257
	enum TView { EBeginning, EMiddle, EEnd, EAll };
sl@0
   258
	enum TIterPos { EAtBeginning, EAtEnd };
sl@0
   259
public:
sl@0
   260
	CDbWindowStage( const TDbWindow& aWindow );
sl@0
   261
protected:
sl@0
   262
	void Reset();
sl@0
   263
	TBool DoEvaluateL( TInt& aWork );
sl@0
   264
	TBool Unevaluated();
sl@0
   265
private:
sl@0
   266
	TInt WhatToEvaluate();
sl@0
   267
	TDbPosition ResetIterToBeginningL();
sl@0
   268
	TDbPosition ResetIterToEndL();
sl@0
   269
	TDbPosition SetIteratorL( TInt anEval );
sl@0
   270
	void ExtendAtBeginningL( TInt aRecords, TDbPosition aFirst, TInt& aWork );
sl@0
   271
	void ExtendAtEndL( TInt aRecords, TDbPosition aFirst, TInt& aWork );
sl@0
   272
private:
sl@0
   273
	TIterPos iIterPos;		// where the underlying iterator is in our window
sl@0
   274
	TView iView;			// what part of the underlying set we see through the window
sl@0
   275
	};
sl@0
   276
sl@0
   277
NONSHARABLE_CLASS(CDbReorderWindowStage) : public CDbBasicWindowStage
sl@0
   278
/**
sl@0
   279
@internalComponent
sl@0
   280
*/
sl@0
   281
	{
sl@0
   282
private:
sl@0
   283
	enum TState { EReset, EEvaluate, EComplete, EFailed };
sl@0
   284
	enum { EGranularity = 32 };
sl@0
   285
public:
sl@0
   286
	CDbReorderWindowStage();
sl@0
   287
	~CDbReorderWindowStage();
sl@0
   288
protected:
sl@0
   289
	void Reset();
sl@0
   290
	TBool DoEvaluateL( TInt& aWork );
sl@0
   291
	TBool Unevaluated();
sl@0
   292
private:
sl@0
   293
	TBool ReadL( TInt& aWork, TDbPosition aNext );
sl@0
   294
private:
sl@0
   295
	TState iState;
sl@0
   296
	RArray<TUint> iRows;
sl@0
   297
	};
sl@0
   298
sl@0
   299
NONSHARABLE_CLASS(CDbOrderByStage) : public CDbBasicWindowStage
sl@0
   300
/**
sl@0
   301
@internalComponent
sl@0
   302
*/
sl@0
   303
	{
sl@0
   304
private:
sl@0
   305
	class HOrdering;
sl@0
   306
	class CKeys;
sl@0
   307
	enum TState { EReset, EEvaluate, ESort, EAdd, EComplete, EFailed };
sl@0
   308
public:
sl@0
   309
	CDbOrderByStage( const RDbTableRow& aRow );
sl@0
   310
	~CDbOrderByStage();
sl@0
   311
	void ConstructL( const CDbKey& aOrderBy );
sl@0
   312
protected:
sl@0
   313
	void Reset();
sl@0
   314
	TBool DoEvaluateL( TInt& aWork );
sl@0
   315
	TBool Unevaluated();
sl@0
   316
private:
sl@0
   317
	inline const RDbTableRow& Row();
sl@0
   318
	inline CKeys& Keys();
sl@0
   319
	inline const HOrdering& Order();
sl@0
   320
//
sl@0
   321
	TBool ReadL( TInt& aWork, TDbPosition aNext );
sl@0
   322
private:
sl@0
   323
	const RDbTableRow& iRow;
sl@0
   324
	TState iState;
sl@0
   325
	HOrdering* iOrder;
sl@0
   326
	CKeys* iKeys;
sl@0
   327
	};
sl@0
   328
sl@0
   329
class RDbAccessPlan
sl@0
   330
/**
sl@0
   331
@internalComponent
sl@0
   332
*/
sl@0
   333
	{
sl@0
   334
public:
sl@0
   335
	inline RDbAccessPlan( CSqlQuery* aQuery, TDbTextComparison aComparison );
sl@0
   336
	inline RDbAccessPlan();
sl@0
   337
	void BuildLC( CDbTableDatabase& aDatabase, RDbRowSet::TAccess aAccess, const TDbWindow& aWindow );
sl@0
   338
	void BuildLC( CDbTableDatabase& aDatabase, const TDesC& aTable, RDbRowSet::TAccess aAccess );
sl@0
   339
	inline CDbTable& Table();
sl@0
   340
	inline CDbDataSource& Source();
sl@0
   341
	inline CDbDataSource* Adopt();
sl@0
   342
private:
sl@0
   343
	class TPlan
sl@0
   344
		{
sl@0
   345
	public:
sl@0
   346
		enum 
sl@0
   347
			{
sl@0
   348
			EOrder = 0x1, ERestrict = 0x2, EReorder = 0x4,
sl@0
   349
			EIndex = 0x8, EBounded = 0x10,
sl@0
   350
			EWindow = 0x20, EReverse = 0x40,
sl@0
   351
			EMask = 0x1f
sl@0
   352
			};
sl@0
   353
		enum TType 
sl@0
   354
			{
sl@0
   355
			EPlanA = 0, EPlanB = 0, EPlanC = 0, EPlanD = 0, EPlanEF = 1, EPlanGH = 7, EPlanIJ = 2,
sl@0
   356
			EPlanKL = 5, EPlanMN = 4, EPlanOP = 3, EPlanQR = 6, EPlanST = 8
sl@0
   357
			};
sl@0
   358
	public:
sl@0
   359
		inline TPlan();
sl@0
   360
		inline TBool operator!=( const TPlan& aPlan ) const;
sl@0
   361
		TType Type() const;
sl@0
   362
		static TInt OrderByPlan( const TPlan& aLeft, const TPlan& aRight );
sl@0
   363
	public:
sl@0
   364
		TUint iFlags;
sl@0
   365
		const CDbTableIndexDef* iIndex;
sl@0
   366
		CSqlCompPredicate* iLower;
sl@0
   367
		CSqlCompPredicate* iUpper;		
sl@0
   368
		};	
sl@0
   369
private:
sl@0
   370
	CDbTableSource* TableLC( CDbTableDatabase& aDatabase, const TDesC& aTable );
sl@0
   371
	void Insert( CDbDataStage* aStage );
sl@0
   372
	CDbRecordIter* IteratorL( const TPlan& aPlan );
sl@0
   373
	CDbRecordIter* BoundedIteratorL( const TPlan& aPlan );
sl@0
   374
	void RestrictionL();
sl@0
   375
	void OrderByL( const RDbTableRow& aRowBuf );
sl@0
   376
	void ProjectionL();
sl@0
   377
	void WindowL( const TPlan& aPlan, const TDbWindow& aWindow );
sl@0
   378
	static void Cleanup( TAny* aPtr );
sl@0
   379
	TBool IsBoundedIteratorL( TPlan& aPlan, const CDbTableIndexDef* aIndex );
sl@0
   380
	TBool IsIndexIteratorL( TPlan& aPlan, const CDbTableIndexDef* aIndex );
sl@0
   381
	void EvaluateWindowStage( TPlan& aPlan );
sl@0
   382
	void EvaluateReorderStage( TPlan& aPlan, const CDbTableIndexDef* aIndex );
sl@0
   383
	void EvaluatePlansL();
sl@0
   384
	void ChoosePlanL( TPlan& aPlan );
sl@0
   385
	void PrepareQueryL( CDbTableSource* aSource );
sl@0
   386
	TInt GetTightestRestrictionL( TPlan& aPlan, TPlan::TType aType );
sl@0
   387
	TInt GetSmallestKeySize( TPlan& aPlan, TPlan::TType aType );
sl@0
   388
	TInt IndexSpanL( const TPlan& aPlan );
sl@0
   389
	void ReducePlans();
sl@0
   390
	void CreateTableIteratorPlan( TPlan& aPlan );
sl@0
   391
	TUint FindMatchL( const CDbTableIndexDef* aIndex );
sl@0
   392
	TBool TextKeyL( const CDbKey& anOrder );
sl@0
   393
private:
sl@0
   394
	enum { EGranularity = 4 };
sl@0
   395
	enum { EMatch = 0x1, EReverse = 0x2, ETruncated = 0x4 };
sl@0
   396
	//
sl@0
   397
	class TBounds;
sl@0
   398
	class CDbCompPredicateList;
sl@0
   399
private:
sl@0
   400
	RArray<TPlan> iPlans;
sl@0
   401
	CDbDataSource* iSource;
sl@0
   402
	CDbTable* iTable;
sl@0
   403
	TDbTextComparison iComparison;
sl@0
   404
	CSqlQuery* iQuery;
sl@0
   405
	TBool iWindow;
sl@0
   406
	RDbRowSet::TAccess iAccess;
sl@0
   407
	};
sl@0
   408
sl@0
   409
class RDbAccessPlan::TBounds
sl@0
   410
	{
sl@0
   411
public:
sl@0
   412
	TBounds( const TPlan& aPlan );
sl@0
   413
private:
sl@0
   414
	void GetLookupKey( const CSqlCompPredicate& aCompPredicate, TDbLookupKey& aLookup );
sl@0
   415
	void SetLowerBounds();
sl@0
   416
	void SetUpperBounds();
sl@0
   417
public:
sl@0
   418
	CSqlCompPredicate* iLowerPred;
sl@0
   419
	CSqlCompPredicate* iUpperPred;		
sl@0
   420
	TDbLookupKey iLowerKey;
sl@0
   421
	TDbLookupKey iUpperKey;
sl@0
   422
	TDbLookupKey* iLower;
sl@0
   423
	TDbLookupKey* iUpper;
sl@0
   424
	TUint iInclusion;
sl@0
   425
	};
sl@0
   426
sl@0
   427
class RDbAccessPlan::CDbCompPredicateList : public CArrayFixFlat<CSqlCompPredicate*>
sl@0
   428
	{
sl@0
   429
public:
sl@0
   430
	enum
sl@0
   431
		{
sl@0
   432
		EAnd = 0x1,
sl@0
   433
		ELess = 0x2,
sl@0
   434
		ELessEqual = 0x4,
sl@0
   435
		EEqual = 0x8,
sl@0
   436
		EGreaterEqual = 0x10,
sl@0
   437
		EGreater = 0x20,
sl@0
   438
		ECompPred = ELess | ELessEqual | EEqual | EGreaterEqual | EGreater,
sl@0
   439
		ENone = 0
sl@0
   440
		};
sl@0
   441
public:
sl@0
   442
	static CDbCompPredicateList* NewLC( CSqlQuery& aQuery, TDbTextComparison aComparison, const CDbTableDef& aTableDef );
sl@0
   443
	CSqlCompPredicate* CompPredicate( TDbColNo aColNo, TUint aType = ECompPred );
sl@0
   444
	TUint Type( CSqlSearchCondition::TType aType ) const;
sl@0
   445
	inline TBool IsRestriction();
sl@0
   446
private:
sl@0
   447
	inline CDbCompPredicateList( const CDbTableDef& aTableDef, TDbTextComparison aComparison );
sl@0
   448
	void ConstructL( CSqlSearchCondition& aSeachCondition );
sl@0
   449
	TBool IsIndexed( const TDesC& aColumnName );
sl@0
   450
private:
sl@0
   451
	enum { EGranularity = 4 };
sl@0
   452
private:
sl@0
   453
	const CDbTableDef& iTableDef;
sl@0
   454
	TDbTextComparison iComparison;
sl@0
   455
	TBool iRestriction;
sl@0
   456
	};
sl@0
   457
sl@0
   458
class CDbTable::TValid
sl@0
   459
/**
sl@0
   460
@internalComponent
sl@0
   461
*/
sl@0
   462
	{
sl@0
   463
public:
sl@0
   464
	TValid(CDbTable& aTable);
sl@0
   465
	TBool Reset();
sl@0
   466
//
sl@0
   467
	inline operator TAny*() const;
sl@0
   468
	void CheckL() const;
sl@0
   469
//
sl@0
   470
	inline RDbTransaction& Transaction() const;
sl@0
   471
	inline CDbTable& Table() const;
sl@0
   472
private:
sl@0
   473
	CDbTable& iTable;
sl@0
   474
	TDbGenerationMark iRollback;
sl@0
   475
	};
sl@0
   476
sl@0
   477
NONSHARABLE_CLASS(CDbTableCursor) : public CDbCursor
sl@0
   478
/**
sl@0
   479
@internalComponent
sl@0
   480
*/
sl@0
   481
	{
sl@0
   482
public:
sl@0
   483
	static CDbTableCursor* NewL( RDbAccessPlan& aPlan, RDbRowSet::TAccess aAccess );
sl@0
   484
//
sl@0
   485
	inline CDbBlobSpace& BlobsL() const;
sl@0
   486
	inline void AddSink();
sl@0
   487
	inline void ReleaseSink();
sl@0
   488
	inline void AddSource();
sl@0
   489
	inline void ReleaseSource();
sl@0
   490
	void AddBlobSource();
sl@0
   491
	void ReleaseBlobSource();
sl@0
   492
private:
sl@0
   493
	CDbTableCursor( RDbAccessPlan& aPlan, RDbRowSet::TAccess anAccess );
sl@0
   494
	~CDbTableCursor();
sl@0
   495
//
sl@0
   496
	void Reset();
sl@0
   497
	TBool EvaluateL();
sl@0
   498
	void Evaluate( TRequestStatus& aStatus );
sl@0
   499
	TBool Unevaluated();
sl@0
   500
//
sl@0
   501
	void SetIndexL( const TDesC* anIndex );
sl@0
   502
	TBool SeekL( const TDbLookupKey& aKey, RDbTable::TComparison aComparison );
sl@0
   503
	CDbRowConstraint* OpenConstraintL( const TDbQuery& aCriteria );
sl@0
   504
	TBool MatchL( CDbRowConstraint& aConstraint );
sl@0
   505
//
sl@0
   506
	TInt CountL( RDbRowSet::TAccuracy aAccuracy );
sl@0
   507
	TBool AtBeginning();
sl@0
   508
	TBool AtEnd();
sl@0
   509
	TBool AtRow();
sl@0
   510
	TBool GotoL( RDbRowSet::TPosition aPosition );
sl@0
   511
	void Bookmark( TDbBookmark::TMark& aMark );
sl@0
   512
	void GotoL( const TDbBookmark::TMark& aMark );
sl@0
   513
	void GetL();
sl@0
   514
	void InsertL( TInsert aClearRow );
sl@0
   515
	void UpdateL();
sl@0
   516
	void Cancel();
sl@0
   517
	void PutL();
sl@0
   518
	void DeleteL();
sl@0
   519
//
sl@0
   520
	TInt ColumnCount();
sl@0
   521
	TDbColType ColumnType( TDbColNo aCol );
sl@0
   522
	void ColumnDef( TDbCol& aCol, TDbColNo aColNo );
sl@0
   523
//
sl@0
   524
	RDbRow* RowBuffer();
sl@0
   525
	TDbColumnC ColumnC( TDbColNo aCol );	// non-writeable row buffer
sl@0
   526
	TDbColumn Column( TDbColNo aCol );		// writeable row buffer
sl@0
   527
	void SetNullL( TDbColNo aCol );
sl@0
   528
	TInt ColumnSize( TDbColNo aCol );
sl@0
   529
	MStreamBuf* ColumnSourceL( TDbColNo aCol );
sl@0
   530
	MStreamBuf* ColumnSinkL( TDbColNo aCol );
sl@0
   531
//
sl@0
   532
	TDbColType Type( TDbColNo aCol ) const;
sl@0
   533
	void ReplaceBlobL( TDbColumn& aColumn );
sl@0
   534
	inline TBool InUpdate() const;
sl@0
   535
	inline RDbTransaction& Transaction();
sl@0
   536
	void CheckStateL() const;
sl@0
   537
	void CheckReadL() const;
sl@0
   538
	void CheckUpdateL() const;
sl@0
   539
	void AssertValidRow() const;
sl@0
   540
	void AssertNotInUpdate() const;
sl@0
   541
	void AssertInUpdate() const;
sl@0
   542
	void AssertNoStreams() const;
sl@0
   543
private:
sl@0
   544
	enum TState
sl@0
   545
		{
sl@0
   546
		ERowBeginning,
sl@0
   547
		ERowOK,
sl@0
   548
		ERowEnd,
sl@0
   549
		ERowInvalid,
sl@0
   550
		ERowDeletedAtNext,
sl@0
   551
		ERowDeletedAtEnd,
sl@0
   552
		ERowInLimbo
sl@0
   553
		};	// keep these in same order as CDbDataSource::TDelete
sl@0
   554
	enum
sl@0
   555
		{
sl@0
   556
		EUpdatable = 0x01,
sl@0
   557
		EReadable = 0x02,
sl@0
   558
		ERead = 0x04,
sl@0
   559
		EUpdating = 0x08,
sl@0
   560
		EInserting = 0x10,
sl@0
   561
		EDirty = 0x20,
sl@0
   562
		EWriteBuf = 0x40
sl@0
   563
		};
sl@0
   564
	enum { EMaxReadBuf = 255 };
sl@0
   565
	class HColumns;
sl@0
   566
	class CConstraint;
sl@0
   567
	class HMemBuf;
sl@0
   568
	class HWriteBuf;
sl@0
   569
	class HReadBuf;
sl@0
   570
	class HHeapBuf;
sl@0
   571
private:
sl@0
   572
	TUint8 iState;
sl@0
   573
	TUint8 iFlags;
sl@0
   574
	TUint8 iReadBuf;
sl@0
   575
	CDbTable::TValid iValid;
sl@0
   576
	CDbDataSource* iDataSource;
sl@0
   577
	TDbRecordId iRecord;
sl@0
   578
	HColumns* iColumns;
sl@0
   579
	};
sl@0
   580
sl@0
   581
sl@0
   582
NONSHARABLE_CLASS(CDbTableCursor::HWriteBuf) : public TDesBuf
sl@0
   583
	{
sl@0
   584
public:
sl@0
   585
	static HWriteBuf* NewL( CDbTableCursor& aCursor, const TDbColumn& aColumn, TDbColType aType );
sl@0
   586
private:
sl@0
   587
	inline HWriteBuf( CDbTableCursor& aCursor, const TDbColumn& aColumn, TDbColType aType );
sl@0
   588
	virtual inline ~HWriteBuf();
sl@0
   589
	void ConstructL();
sl@0
   590
//
sl@0
   591
	inline TBool IsBinary() const;
sl@0
   592
	void FlipL();
sl@0
   593
// for MStreamBuf
sl@0
   594
	void DoRelease();
sl@0
   595
	void DoSynchL();
sl@0
   596
	TInt DoReadL( TAny* aPtr, TInt aMaxLength );
sl@0
   597
	TStreamTransfer DoReadL( MStreamInput& aInput, TStreamTransfer aTransfer );
sl@0
   598
	void DoWriteL( const TAny* aPtr, TInt aLength );
sl@0
   599
	TStreamTransfer DoWriteL( MStreamOutput& aOutput, TStreamTransfer aTransfer );
sl@0
   600
	TStreamPos DoSeekL( TMark aMark, TStreamLocation aLocation, TInt aOffset );
sl@0
   601
private:
sl@0
   602
	CDbTableCursor& iCursor;
sl@0
   603
	TDbColumn iColumn;
sl@0
   604
	TDbColType iType;
sl@0
   605
	TDbBlob* iBlob;
sl@0
   606
	TPtr8 iInlineBuf;
sl@0
   607
	TDbBlobId iBlobId;
sl@0
   608
	TInt iSize;
sl@0
   609
	MStreamBuf* iOverflowBuf;
sl@0
   610
	};
sl@0
   611
sl@0
   612
NONSHARABLE_CLASS(CDbTableCursor::HMemBuf) : public TMemBuf
sl@0
   613
	{
sl@0
   614
public:
sl@0
   615
	static HMemBuf* NewL( CDbTableCursor& aCursor, const TDesC8& aDes );
sl@0
   616
protected:
sl@0
   617
	HMemBuf( CDbTableCursor& aCursor );
sl@0
   618
	virtual inline ~HMemBuf();
sl@0
   619
private:
sl@0
   620
	void DoRelease();
sl@0
   621
private:
sl@0
   622
	CDbTableCursor& iCursor;
sl@0
   623
	};
sl@0
   624
sl@0
   625
class CDbTableCursor::HHeapBuf : public CDbTableCursor::HMemBuf
sl@0
   626
	{
sl@0
   627
public:
sl@0
   628
	enum { EMaxBlobBuffer = 0x600 };	// 1.5K to match KDbsStreamBufSize
sl@0
   629
public:
sl@0
   630
	static HHeapBuf* NewL( CDbTableCursor& aCursor, const TDbBlob& aBlob, TDbColType aType );
sl@0
   631
private:
sl@0
   632
	inline HHeapBuf( CDbTableCursor& aCursor );
sl@0
   633
private:
sl@0
   634
	TUint8 iBuf[1];
sl@0
   635
	};
sl@0
   636
sl@0
   637
NONSHARABLE_CLASS(CDbTableCursor::HReadBuf) : public MStreamBuf
sl@0
   638
	{
sl@0
   639
public:
sl@0
   640
	static HReadBuf* NewLC( CDbTableCursor& aCursor );
sl@0
   641
	inline void Set( MStreamBuf* aHost );
sl@0
   642
private:
sl@0
   643
	inline HReadBuf( CDbTableCursor& aCursor );
sl@0
   644
	virtual inline ~HReadBuf();
sl@0
   645
// from MStreamBuf
sl@0
   646
	void DoRelease();
sl@0
   647
	TInt DoReadL( TAny* aPtr, TInt aMaxLength );
sl@0
   648
	TStreamTransfer DoReadL( MStreamInput& aInput, TStreamTransfer aTransfer );
sl@0
   649
	TStreamPos DoSeekL( TMark aMark, TStreamLocation aLocation, TInt aOffset );
sl@0
   650
private:
sl@0
   651
	CDbTableCursor& iCursor;
sl@0
   652
	MStreamBuf* iHost;
sl@0
   653
	};
sl@0
   654
sl@0
   655
NONSHARABLE_CLASS(CDbTableDatabase::CIncremental) : public CDbSyncIncremental
sl@0
   656
/**
sl@0
   657
@internalComponent
sl@0
   658
*/
sl@0
   659
	{
sl@0
   660
protected:
sl@0
   661
	enum { ELastStep = 1 };
sl@0
   662
	enum TState { ERunning = 0, EFailed, ECommitted };
sl@0
   663
public:
sl@0
   664
	inline void Construct( CStepper* aStepper );
sl@0
   665
protected:
sl@0
   666
	CIncremental( RDbTransaction& aTransaction );
sl@0
   667
	~CIncremental();
sl@0
   668
	inline RDbTransaction& Transaction();
sl@0
   669
	inline CDbTableDatabase& Database();
sl@0
   670
	inline TBool IsCommitted() const;
sl@0
   671
private:
sl@0
   672
	TBool NextL( TInt& aStep );
sl@0
   673
	virtual TInt DoNextL( TInt aStep );
sl@0
   674
	virtual void DoLastL() =0;
sl@0
   675
private:
sl@0
   676
	RDbTransaction& iTransaction;
sl@0
   677
	CStepper* iStepper;
sl@0
   678
	TState iState;
sl@0
   679
	};
sl@0
   680
sl@0
   681
NONSHARABLE_CLASS(CDbTableDatabase::CIncrementalDDL) : public CDbTableDatabase::CIncremental
sl@0
   682
/**
sl@0
   683
@internalComponent
sl@0
   684
*/
sl@0
   685
	{
sl@0
   686
protected:
sl@0
   687
	CIncrementalDDL( RDbTransaction& aTransaction );
sl@0
   688
	~CIncrementalDDL();
sl@0
   689
// from CIncremental
sl@0
   690
	void DoLastL();
sl@0
   691
	};
sl@0
   692
sl@0
   693
class CDbTableDatabase::CCreateIndex : public CDbTableDatabase::CIncrementalDDL
sl@0
   694
/**
sl@0
   695
@internalComponent
sl@0
   696
*/
sl@0
   697
	{
sl@0
   698
public:
sl@0
   699
	static CCreateIndex* NewLC( RDbTransaction& aTransaction );
sl@0
   700
	TInt ConstructL( const CDbTableDef& aTable, const CDbTableIndexDef& anIndex );
sl@0
   701
private:
sl@0
   702
	inline CCreateIndex( RDbTransaction& aTransaction );
sl@0
   703
	};
sl@0
   704
sl@0
   705
NONSHARABLE_CLASS(CDbTableDatabase::CDropIndex) : public CDbTableDatabase::CIncrementalDDL
sl@0
   706
/**
sl@0
   707
@internalComponent
sl@0
   708
*/
sl@0
   709
	{
sl@0
   710
public:
sl@0
   711
	static CDropIndex* NewL( RDbTransaction& aTransaction, const CDbTableDef& aTable, CDbTableIndexDef* anIndex, TInt& aStep );
sl@0
   712
	~CDropIndex();
sl@0
   713
private:
sl@0
   714
	inline CDropIndex( RDbTransaction& aTransaction );
sl@0
   715
private:
sl@0
   716
	CDbTableIndexDef* iDef;
sl@0
   717
	};
sl@0
   718
sl@0
   719
NONSHARABLE_CLASS(CDbTableDatabase::CDropTable) : public CDbTableDatabase::CIncrementalDDL
sl@0
   720
/**
sl@0
   721
@internalComponent
sl@0
   722
*/
sl@0
   723
	{
sl@0
   724
public:
sl@0
   725
	static CDropTable* NewL( RDbTransaction& aTransaction, CDbTableDef* aTable, TInt& aStep );
sl@0
   726
	~CDropTable();
sl@0
   727
private:
sl@0
   728
	inline CDropTable( RDbTransaction& aTransaction );
sl@0
   729
private:
sl@0
   730
	CDbTableDef* iDef;
sl@0
   731
	};
sl@0
   732
sl@0
   733
NONSHARABLE_CLASS(CDbTableDatabase::CAlterTable) : public CDbTableDatabase::CIncrementalDDL
sl@0
   734
/**
sl@0
   735
@internalComponent
sl@0
   736
*/
sl@0
   737
	{
sl@0
   738
public:
sl@0
   739
	static CAlterTable* NewL( RDbTransaction& aTransaction, CDbTableDef& aTable, const CDbColSet& aNewDef, TInt& aStep );
sl@0
   740
	~CAlterTable();
sl@0
   741
private:
sl@0
   742
	inline CAlterTable( RDbTransaction& aTransaction, CDbTableDef& aDef );
sl@0
   743
	void ConstructL( const CDbColSet& aNewDef, TInt& aStep );
sl@0
   744
// from CIncremental
sl@0
   745
	void DoLastL();
sl@0
   746
private:
sl@0
   747
	CDbTableDef& iDef;
sl@0
   748
	HDbColumnSet* iNewSet;
sl@0
   749
	};
sl@0
   750
sl@0
   751
NONSHARABLE_CLASS(CDbTableDatabase::CUtility) : public CDbTableDatabase::CIncremental
sl@0
   752
/**
sl@0
   753
@internalComponent
sl@0
   754
*/
sl@0
   755
	{
sl@0
   756
public:
sl@0
   757
	static CUtility* NewL( RDbTransaction& aTransaction, CDbDatabase::TUtility aType, TInt& aStep );
sl@0
   758
	~CUtility();
sl@0
   759
private:
sl@0
   760
	inline CUtility( RDbTransaction& aTransaction, CDbDatabase::TUtility aType );
sl@0
   761
private:
sl@0
   762
	void DoLastL();
sl@0
   763
	};
sl@0
   764
sl@0
   765
NONSHARABLE_CLASS(CDbIncrementalDML) : public CDbSyncIncremental
sl@0
   766
/**
sl@0
   767
@internalComponent
sl@0
   768
*/
sl@0
   769
	{
sl@0
   770
public:
sl@0
   771
	static CDbIncrementalDML* NewL( CSqlModifyStatement& aStatement, CDbTableDatabase& aDatabase, TDbTextComparison aComparison );
sl@0
   772
	~CDbIncrementalDML();
sl@0
   773
private:
sl@0
   774
	enum TState { EInitialising = 0, EEvaluating, EUpdating, EDeleting, ECommitted, EFailed };
sl@0
   775
private:
sl@0
   776
	inline CDbIncrementalDML( RDbAccessPlan& aPlan );
sl@0
   777
	inline RDbTransaction& Transaction();
sl@0
   778
	inline TBool IsUpdate() const;
sl@0
   779
	inline void	SetState( TState aState );
sl@0
   780
// from CDbSyncIncremental
sl@0
   781
	TBool NextL( TInt& aRows );
sl@0
   782
private:
sl@0
   783
	TState iState;
sl@0
   784
	CDbTable& iTable;
sl@0
   785
	CDbDataSource* iSource;
sl@0
   786
	TDbRecordId iRecord;
sl@0
   787
	CSqlValues* iValues;
sl@0
   788
	};
sl@0
   789
sl@0
   790
NONSHARABLE_CLASS(CDbTableDatabase::CInterface) : public CDbDatabase
sl@0
   791
/**
sl@0
   792
the interface implementation class for the Table database framework
sl@0
   793
@internalComponent
sl@0
   794
*/
sl@0
   795
	{
sl@0
   796
public:
sl@0
   797
	CInterface(CDbTableDatabase& aDatabase);
sl@0
   798
private:
sl@0
   799
	~CInterface();
sl@0
   800
	inline CDbTableDatabase& Database();
sl@0
   801
	void PrepareDDLL();
sl@0
   802
//	from the interface framework
sl@0
   803
	TInt Destroy();
sl@0
   804
	TInt Begin();
sl@0
   805
	TInt Commit();
sl@0
   806
	void Rollback();
sl@0
   807
	TInt Property( TProperty aProperty );
sl@0
   808
	void CreateTableL( const TDesC& aName, const CDbColSet& aColSet, const CDbKey* aPrimaryKey );
sl@0
   809
	void TablesL( CDbTableNames& aNames );
sl@0
   810
	void ColumnsL( CDbColSet& aColSet, const TDesC& aName );
sl@0
   811
	void IndexesL( CDbIndexNames& aNames, const TDesC& aTable );
sl@0
   812
	void KeysL( CDbKey& aKey, const TDesC& aName, const TDesC& aTable );
sl@0
   813
	CDbNotifier* OpenNotifierL();
sl@0
   814
	CDbCursor* PrepareViewL( const TDbQuery& aQuery, const TDbWindow& aWindow, RDbRowSet::TAccess anAccess );
sl@0
   815
	CDbCursor* OpenTableL( const TDesC& aName, RDbRowSet::TAccess anAccess );
sl@0
   816
	CDbIncremental* OpenDropTableL( const TDesC& aTable, TInt& aStep );
sl@0
   817
	CDbIncremental* OpenAlterTableL( const TDesC& aTable, const CDbColSet& aNewDef, TInt& aStep );
sl@0
   818
	CDbIncremental* OpenCreateIndexL( const TDesC& aName, const TDesC& aTable, const CDbKey& aKey, TInt& aStep );
sl@0
   819
	CDbIncremental* OpenDropIndexL( const TDesC& aName, const TDesC& aTable, TInt& aStep );
sl@0
   820
	CDbIncremental* OpenUtilityL( CDbDatabase::TUtility aType, TInt& aStep );
sl@0
   821
	CDbIncremental* OpenExecuteL( const TDesC& aSql, TDbTextComparison aComparison, TInt& aInit );
sl@0
   822
private:
sl@0
   823
	CDbTableDatabase& iDatabase;
sl@0
   824
	};
sl@0
   825
sl@0
   826
NONSHARABLE_CLASS(CDbTableDatabase::CSource) : public CDbSource
sl@0
   827
/**
sl@0
   828
@internalComponent
sl@0
   829
*/
sl@0
   830
	{
sl@0
   831
public:
sl@0
   832
	CSource( CDbTableDatabase& aDatabase );
sl@0
   833
private:
sl@0
   834
	~CSource();
sl@0
   835
	inline CDbTableDatabase& Database();
sl@0
   836
	// from the framework
sl@0
   837
	CDbDatabase* AuthenticateL();
sl@0
   838
	CDbNotifier* OpenNotifierL();
sl@0
   839
private:
sl@0
   840
	CDbTableDatabase& iDatabase;
sl@0
   841
	};
sl@0
   842
sl@0
   843
#include "UT_STD.INL"