Update contrib.
     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".
 
     8 // Initial Contributors:
 
     9 // Nokia Corporation - initial contribution.
 
    18 // Class CDbTableCursor::HWriteBuf
 
    20 inline CDbTableCursor::HWriteBuf::HWriteBuf(CDbTableCursor& aCursor,const TDbColumn& aColumn,TDbColType aType)
 
    21 	: iCursor(aCursor),iColumn(aColumn),iType(aType),iBlob(0),iInlineBuf(0,0),iSize(0),iOverflowBuf(0)
 
    24 void CDbTableCursor::HWriteBuf::ConstructL()
 
    26 	iBlob=&iColumn.InitBlobL();
 
    27 	iInlineBuf.Set(iBlob->InlineBuffer(),0,iCursor.BlobsL().InlineLimit());
 
    31 CDbTableCursor::HWriteBuf* CDbTableCursor::HWriteBuf::NewL(CDbTableCursor& aCursor,const TDbColumn& aColumn,TDbColType aType)
 
    33 	__ASSERT(TDbCol::IsLong(aType));
 
    35 	HWriteBuf* self=new(ELeave) HWriteBuf(aCursor,aColumn,aType);
 
    42 inline CDbTableCursor::HWriteBuf::~HWriteBuf()
 
    45 		iOverflowBuf->Release();
 
    47 		iColumn.CommitBlob(*iBlob);
 
    48 	iCursor.ReleaseSink();
 
    51 void CDbTableCursor::HWriteBuf::DoRelease()
 
    56 inline TBool CDbTableCursor::HWriteBuf::IsBinary() const
 
    57 	{return iType==EDbColLongBinary;}
 
    59 #pragma warning(disable : 4701)			// disable not initialised before use warning.  
 
    61 void CDbTableCursor::HWriteBuf::FlipL()
 
    63 // switch from inline to out of line stream
 
    66 	__ASSERT( !iOverflowBuf );
 
    69 	if ( IsBinary() )	// seeking only allowed for binary (non-encrypted) data
 
    70 		rpos = TDesBuf::TellL( ERead );
 
    71 	iOverflowBuf = iCursor.BlobsL().CreateL( iBlobId, iType );
 
    72 	const TUint8* base = iInlineBuf.Ptr();
 
    73 	TInt len = Ptr( EWrite ) - base;
 
    75 		iOverflowBuf->WriteL( base, len );
 
    76 	if ( IsBinary() )	// seeking only allowed for binary (non-encrypted) data
 
    77 		iOverflowBuf->SeekL( ERead, rpos );
 
    80 #pragma warning(default : 4701)			// enable not initialised before use warning.  
 
    82 void CDbTableCursor::HWriteBuf::DoSynchL()
 
    84 // update the row buffer for the blob
 
    87 	MStreamBuf* buf=iOverflowBuf!=NULL ? iOverflowBuf : this;
 
    88 	TInt size=IsBinary() ? buf->SizeL() : iSize;
 
    89 	if (iOverflowBuf!=NULL)
 
    92 		iBlob->SetId(iBlobId);
 
    97 TInt CDbTableCursor::HWriteBuf::DoReadL(TAny* aPtr,TInt aMaxLength)
 
   101 	if (iOverflowBuf!=NULL)
 
   102 		return iOverflowBuf->ReadL(aPtr,aMaxLength);
 
   103 	return TDesBuf::DoReadL(aPtr,aMaxLength);
 
   106 TStreamTransfer CDbTableCursor::HWriteBuf::DoReadL(MStreamInput& aInput,TStreamTransfer aTransfer)
 
   108 	__ASSERT(IsBinary());
 
   110 	if (iOverflowBuf!=NULL)
 
   111 		return iOverflowBuf->ReadL(aInput,aTransfer);
 
   112 	return TDesBuf::DoReadL(aInput,aTransfer);
 
   115 void CDbTableCursor::HWriteBuf::DoWriteL(const TAny* aPtr,TInt aLength)
 
   117 	if (iOverflowBuf==NULL)
 
   119 		if (aLength<=Avail(EWrite))
 
   121 			TDesBuf::DoWriteL(aPtr,aLength);
 
   127 	iOverflowBuf->WriteL(aPtr,aLength);
 
   131 TStreamTransfer CDbTableCursor::HWriteBuf::DoWriteL(MStreamOutput& aOutput,TStreamTransfer aTransfer)
 
   134 	TStreamTransfer t1=aTransfer[KMaxTInt];
 
   135 	TStreamTransfer t2=iOverflowBuf ? iOverflowBuf->WriteL(aOutput,t1) : TDesBuf::DoWriteL(aOutput,t1);
 
   136 	TInt bytes=t1.Left()-t2.Left();
 
   138 	return aTransfer-bytes;
 
   141 TStreamPos CDbTableCursor::HWriteBuf::DoSeekL(TMark aMark,TStreamLocation aLocation,TInt aOffset)
 
   143 	__ASSERT(IsBinary());
 
   145 	if (iOverflowBuf!=NULL)
 
   146 		return iOverflowBuf->SeekL(aMark,aLocation,aOffset);
 
   147 	return TDesBuf::DoSeekL(aMark,aLocation,aOffset);
 
   150 // Class CDbTableCursor::HMemBuf
 
   152 CDbTableCursor::HMemBuf::HMemBuf(CDbTableCursor& aCursor)
 
   158 CDbTableCursor::HMemBuf* CDbTableCursor::HMemBuf::NewL(CDbTableCursor& aCursor,const TDesC8& aDes)
 
   160 	HMemBuf* self=new(ELeave) HMemBuf(aCursor);
 
   161 	TUint8* ptr=const_cast<TUint8*>(aDes.Ptr());
 
   162 	self->Set(ptr,ptr+aDes.Length(),ERead);
 
   166 inline CDbTableCursor::HMemBuf::~HMemBuf()
 
   167 	{iCursor.ReleaseSource();}
 
   169 void CDbTableCursor::HMemBuf::DoRelease()
 
   174 // Class CDbTableCursor::HHeapBuf
 
   176 inline CDbTableCursor::HHeapBuf::HHeapBuf( CDbTableCursor& aCursor )
 
   180 CDbTableCursor::HHeapBuf* CDbTableCursor::HHeapBuf::NewL( CDbTableCursor& aCursor, const TDbBlob& aBlob, TDbColType aType )
 
   182 	__ASSERT( aBlob.Size() <= EMaxBlobBuffer );
 
   183 	TAny* mem = User::AllocL(_FOFF(HHeapBuf,iBuf[aBlob.Size()]));	// get the extra size for the entries, leaves on error
 
   184 	HHeapBuf* self = new( mem ) HHeapBuf(aCursor);	// do an in place new, now we've got the memory
 
   186 	MStreamBuf* buf = aCursor.BlobsL().ReadLC( aBlob.Id(), aType );
 
   187 	__DEBUG( TInt sz = ) buf->ReadL( &self->iBuf[0], aBlob.Size() );
 
   188 	__ASSERT(sz == aBlob.Size());
 
   189 	CleanupStack::PopAndDestroy();	// buf
 
   190 	self->Set( &self->iBuf[0], &self->iBuf[aBlob.Size() ], ERead );
 
   191 	CleanupStack::Pop();			// self
 
   195 // Class CDbTableCursor::HReadBuf
 
   197 inline CDbTableCursor::HReadBuf::HReadBuf(CDbTableCursor& aCursor)
 
   198 	:iCursor(aCursor),iHost(0)
 
   199 	{aCursor.AddBlobSource();}
 
   201 CDbTableCursor::HReadBuf* CDbTableCursor::HReadBuf::NewLC(CDbTableCursor& aCursor)
 
   203 	HReadBuf* self=new(ELeave) HReadBuf(aCursor);
 
   208 inline CDbTableCursor::HReadBuf::~HReadBuf()
 
   212 	iCursor.ReleaseBlobSource();
 
   215 void CDbTableCursor::HReadBuf::DoRelease()
 
   220 TInt CDbTableCursor::HReadBuf::DoReadL(TAny* aPtr,TInt aMaxLength)
 
   223 	return iHost->ReadL(aPtr,aMaxLength);
 
   226 TStreamTransfer CDbTableCursor::HReadBuf::DoReadL(MStreamInput& aInput,TStreamTransfer aTransfer)
 
   229 	return iHost->ReadL(aInput,aTransfer);
 
   232 TStreamPos CDbTableCursor::HReadBuf::DoSeekL(TMark aMark,TStreamLocation aLocation,TInt aOffset)
 
   235 	return iHost->SeekL(aMark,aLocation,aOffset);