persistentstorage/sql/SRC/Common/SqlBufIterator.h
changeset 0 08ec8eefde2f
child 23 26645d81f48d
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #ifndef __SQLBUFITERATOR_H__
       
    17 #define __SQLBUFITERATOR_H__
       
    18 
       
    19 #include <sqldb.h>			//TSqlColumnType
       
    20 #include "SqlBufFlat.h"		//RSqlBufFlat
       
    21 #include "SqlPanic.h"	
       
    22 
       
    23 //Forward declarations
       
    24 class MStreamBuf;
       
    25 
       
    26 /**
       
    27 ZeroBlob column type. Used internally.
       
    28 @internalComponent
       
    29 */
       
    30 enum {ESqlZeroBlob = ESqlBinary + 1};
       
    31 
       
    32 inline TBool IsSequenceSqlType(TInt aType)
       
    33 	{
       
    34 	return aType == ESqlNull || aType == ESqlText || aType == ESqlBinary;
       
    35 	}
       
    36 
       
    37 //////////////////////////////////////////////////////////////////////////////////////
       
    38 /////////////////////  Column type conversion table  /////////////////////////////////
       
    39 //////////////////////////////////////////////////////////////////////////////////////
       
    40 //|--------------------------------------------------------------------------------|//
       
    41 //|Column type | ColumnInt() ColumnInt64() ColumnReal() ColumnText() ColumnBinary()|//
       
    42 //|--------------------------------------------------------------------------------|//
       
    43 //|Null........|.0...........0.............0.0..........KNullDesC....KNullDesC8....|//
       
    44 //|Int.........|.Int.........Int64.........Real.........KNullDesC....KNullDesC8....|//
       
    45 //|Int64.......|.clamp.......Int64.........Real.........KNullDesC....KNullDesC8....|//
       
    46 //|Real........|.round.......round.........Real.........KNullDesC....KNullDesC8....|//
       
    47 //|Text........|.0...........0.............0.0..........Text.........KNullDesC8....|//   
       
    48 //|Binary......|.0...........0.............0.0..........KNullDesC....Binary........|//
       
    49 //|--------------------------------------------------------------------------------|//
       
    50 //- "clamp": return KMinTInt or KMaxTInt if the value is outside the range that can //
       
    51 //  be represented by the type returned by the accessor function.                   //
       
    52 //- "round": the floating point value will be rounded up to the nearest integer.    //
       
    53 //  If the result is outside the range that can be represented by the type returned //
       
    54 //  by the accessor function, then it will be clamped.                              //
       
    55 //////////////////////////////////////////////////////////////////////////////////////
       
    56 
       
    57 /**
       
    58 TSqlBufRIterator iterator gives read-only access to the flat buffer content (RSqlBufFlat class).
       
    59 For convenience TSqlBufRIterator can represent the flat buffer fields content as one of the basic
       
    60 SQL types: TInt, TInt64, TReal, 16-bit text, 8-bit binary block.
       
    61 The text and binary fields may be accessed also as a byte stream.
       
    62 
       
    63 @see RSqlBufFlat
       
    64 
       
    65 @internalComponent
       
    66 */
       
    67 class TSqlBufRIterator
       
    68 	{
       
    69 public:	
       
    70 	inline void Set(const RSqlBufFlat& aBuf);
       
    71 	inline TBool Next();
       
    72 	inline void MoveTo(TInt aIndex);
       
    73 	
       
    74 	inline TBool IsPresent() const;
       
    75 	inline TInt Type() const;
       
    76 	inline TInt Size() const;
       
    77 	
       
    78 	TInt Int() const;
       
    79 	TInt64 Int64() const;
       
    80 	TReal Real() const;
       
    81 	TPtrC8 Binary() const;
       
    82 	TPtrC16 Text() const;
       
    83 	
       
    84 	MStreamBuf* StreamL() const;
       
    85 
       
    86 private:
       
    87 	inline TInt AsInt() const;
       
    88 	inline TInt64 AsInt64() const;
       
    89 	inline TReal AsReal() const;
       
    90 	
       
    91 private:
       
    92 	const RSqlBufFlat::TCell*	iCurrent;
       
    93 	const RSqlBufFlat::TCell*	iBegin;
       
    94 	const RSqlBufFlat::TCell*	iEnd;
       
    95 	
       
    96 	};
       
    97 
       
    98 /**
       
    99 TSqlBufWIterator iterator gives write-only access to the flat buffer content (RSqlBufFlat class).
       
   100 For convenience, with TSqlBufWIterator flat buffer fields can be set as:
       
   101 TInt, TInt64, TReal, 16-bit text, 8-bit binary block.
       
   102 
       
   103 @see RSqlBufFlat
       
   104 
       
   105 @internalComponent
       
   106 */
       
   107 class TSqlBufWIterator
       
   108 	{
       
   109 public:
       
   110 	inline void Set(RSqlBufFlat& aBuf);
       
   111 	inline TBool Next();
       
   112 	inline void MoveTo(TInt aIndex);
       
   113 	
       
   114 	inline void SetNull();
       
   115 	inline void SetAsNotPresent(TInt aType, TInt aLength);
       
   116 	inline TInt SetInt(TInt aValue);
       
   117 	inline TInt SetInt64(TInt64 aValue);
       
   118 	inline TInt SetReal(TReal aValue);
       
   119 	inline TInt SetBinary(const TDesC8& aValue);
       
   120 	inline TInt SetText(const TDesC16& aValue);
       
   121 	inline TInt SetZeroBlob(TInt aSize);
       
   122 	
       
   123 private:
       
   124 	RSqlBufFlat*	iBuf;
       
   125 	TInt			iIndex;
       
   126 	
       
   127 	};
       
   128 
       
   129 #include "SqlBufIterator.inl"
       
   130 
       
   131 #endif //__SQLBUFITERATOR_H__