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