sl@0: // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include "UT_STD.H" sl@0: sl@0: // Class CDbTableCursor::HWriteBuf sl@0: sl@0: inline CDbTableCursor::HWriteBuf::HWriteBuf(CDbTableCursor& aCursor,const TDbColumn& aColumn,TDbColType aType) sl@0: : iCursor(aCursor),iColumn(aColumn),iType(aType),iBlob(0),iInlineBuf(0,0),iSize(0),iOverflowBuf(0) sl@0: {aCursor.AddSink();} sl@0: sl@0: void CDbTableCursor::HWriteBuf::ConstructL() sl@0: { sl@0: iBlob=&iColumn.InitBlobL(); sl@0: iInlineBuf.Set(iBlob->InlineBuffer(),0,iCursor.BlobsL().InlineLimit()); sl@0: Set(iInlineBuf); sl@0: } sl@0: sl@0: CDbTableCursor::HWriteBuf* CDbTableCursor::HWriteBuf::NewL(CDbTableCursor& aCursor,const TDbColumn& aColumn,TDbColType aType) sl@0: { sl@0: __ASSERT(TDbCol::IsLong(aType)); sl@0: // sl@0: HWriteBuf* self=new(ELeave) HWriteBuf(aCursor,aColumn,aType); sl@0: self->PushL(); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(); sl@0: return self; sl@0: } sl@0: sl@0: inline CDbTableCursor::HWriteBuf::~HWriteBuf() sl@0: { sl@0: if (iOverflowBuf) sl@0: iOverflowBuf->Release(); sl@0: if (iBlob) sl@0: iColumn.CommitBlob(*iBlob); sl@0: iCursor.ReleaseSink(); sl@0: } sl@0: sl@0: void CDbTableCursor::HWriteBuf::DoRelease() sl@0: { sl@0: delete this; sl@0: } sl@0: sl@0: inline TBool CDbTableCursor::HWriteBuf::IsBinary() const sl@0: {return iType==EDbColLongBinary;} sl@0: sl@0: #pragma warning(disable : 4701) // disable not initialised before use warning. sl@0: sl@0: void CDbTableCursor::HWriteBuf::FlipL() sl@0: // sl@0: // switch from inline to out of line stream sl@0: // sl@0: { sl@0: __ASSERT( !iOverflowBuf ); sl@0: // sl@0: TStreamPos rpos(0); sl@0: if ( IsBinary() ) // seeking only allowed for binary (non-encrypted) data sl@0: rpos = TDesBuf::TellL( ERead ); sl@0: iOverflowBuf = iCursor.BlobsL().CreateL( iBlobId, iType ); sl@0: const TUint8* base = iInlineBuf.Ptr(); sl@0: TInt len = Ptr( EWrite ) - base; sl@0: if ( len ) sl@0: iOverflowBuf->WriteL( base, len ); sl@0: if ( IsBinary() ) // seeking only allowed for binary (non-encrypted) data sl@0: iOverflowBuf->SeekL( ERead, rpos ); sl@0: } sl@0: sl@0: #pragma warning(default : 4701) // enable not initialised before use warning. sl@0: sl@0: void CDbTableCursor::HWriteBuf::DoSynchL() sl@0: // sl@0: // update the row buffer for the blob sl@0: // sl@0: { sl@0: MStreamBuf* buf=iOverflowBuf!=NULL ? iOverflowBuf : this; sl@0: TInt size=IsBinary() ? buf->SizeL() : iSize; sl@0: if (iOverflowBuf!=NULL) sl@0: { sl@0: buf->SynchL(); sl@0: iBlob->SetId(iBlobId); sl@0: } sl@0: iBlob->SetSize(size); sl@0: } sl@0: sl@0: TInt CDbTableCursor::HWriteBuf::DoReadL(TAny* aPtr,TInt aMaxLength) sl@0: { sl@0: __ASSERT(IsBinary()); sl@0: // sl@0: if (iOverflowBuf!=NULL) sl@0: return iOverflowBuf->ReadL(aPtr,aMaxLength); sl@0: return TDesBuf::DoReadL(aPtr,aMaxLength); sl@0: } sl@0: sl@0: TStreamTransfer CDbTableCursor::HWriteBuf::DoReadL(MStreamInput& aInput,TStreamTransfer aTransfer) sl@0: { sl@0: __ASSERT(IsBinary()); sl@0: // sl@0: if (iOverflowBuf!=NULL) sl@0: return iOverflowBuf->ReadL(aInput,aTransfer); sl@0: return TDesBuf::DoReadL(aInput,aTransfer); sl@0: } sl@0: sl@0: void CDbTableCursor::HWriteBuf::DoWriteL(const TAny* aPtr,TInt aLength) sl@0: { sl@0: if (iOverflowBuf==NULL) sl@0: { sl@0: if (aLength<=Avail(EWrite)) sl@0: { sl@0: TDesBuf::DoWriteL(aPtr,aLength); sl@0: iSize+=aLength; sl@0: return; sl@0: } sl@0: FlipL(); sl@0: } sl@0: iOverflowBuf->WriteL(aPtr,aLength); sl@0: iSize+=aLength; sl@0: } sl@0: sl@0: TStreamTransfer CDbTableCursor::HWriteBuf::DoWriteL(MStreamOutput& aOutput,TStreamTransfer aTransfer) sl@0: { sl@0: TInt size=iSize; sl@0: TStreamTransfer t1=aTransfer[KMaxTInt]; sl@0: TStreamTransfer t2=iOverflowBuf ? iOverflowBuf->WriteL(aOutput,t1) : TDesBuf::DoWriteL(aOutput,t1); sl@0: TInt bytes=t1.Left()-t2.Left(); sl@0: iSize=size+bytes; sl@0: return aTransfer-bytes; sl@0: } sl@0: sl@0: TStreamPos CDbTableCursor::HWriteBuf::DoSeekL(TMark aMark,TStreamLocation aLocation,TInt aOffset) sl@0: { sl@0: __ASSERT(IsBinary()); sl@0: // sl@0: if (iOverflowBuf!=NULL) sl@0: return iOverflowBuf->SeekL(aMark,aLocation,aOffset); sl@0: return TDesBuf::DoSeekL(aMark,aLocation,aOffset); sl@0: } sl@0: sl@0: // Class CDbTableCursor::HMemBuf sl@0: sl@0: CDbTableCursor::HMemBuf::HMemBuf(CDbTableCursor& aCursor) sl@0: :iCursor(aCursor) sl@0: { sl@0: aCursor.AddSource(); sl@0: } sl@0: sl@0: CDbTableCursor::HMemBuf* CDbTableCursor::HMemBuf::NewL(CDbTableCursor& aCursor,const TDesC8& aDes) sl@0: { sl@0: HMemBuf* self=new(ELeave) HMemBuf(aCursor); sl@0: TUint8* ptr=const_cast(aDes.Ptr()); sl@0: self->Set(ptr,ptr+aDes.Length(),ERead); sl@0: return self; sl@0: } sl@0: sl@0: inline CDbTableCursor::HMemBuf::~HMemBuf() sl@0: {iCursor.ReleaseSource();} sl@0: sl@0: void CDbTableCursor::HMemBuf::DoRelease() sl@0: { sl@0: delete this; sl@0: } sl@0: sl@0: // Class CDbTableCursor::HHeapBuf sl@0: sl@0: inline CDbTableCursor::HHeapBuf::HHeapBuf( CDbTableCursor& aCursor ) sl@0: :HMemBuf( aCursor ) sl@0: {} sl@0: sl@0: CDbTableCursor::HHeapBuf* CDbTableCursor::HHeapBuf::NewL( CDbTableCursor& aCursor, const TDbBlob& aBlob, TDbColType aType ) sl@0: { sl@0: __ASSERT( aBlob.Size() <= EMaxBlobBuffer ); sl@0: TAny* mem = User::AllocL(_FOFF(HHeapBuf,iBuf[aBlob.Size()])); // get the extra size for the entries, leaves on error sl@0: HHeapBuf* self = new( mem ) HHeapBuf(aCursor); // do an in place new, now we've got the memory sl@0: self->PushL(); sl@0: MStreamBuf* buf = aCursor.BlobsL().ReadLC( aBlob.Id(), aType ); sl@0: __DEBUG( TInt sz = ) buf->ReadL( &self->iBuf[0], aBlob.Size() ); sl@0: __ASSERT(sz == aBlob.Size()); sl@0: CleanupStack::PopAndDestroy(); // buf sl@0: self->Set( &self->iBuf[0], &self->iBuf[aBlob.Size() ], ERead ); sl@0: CleanupStack::Pop(); // self sl@0: return self; sl@0: } sl@0: sl@0: // Class CDbTableCursor::HReadBuf sl@0: sl@0: inline CDbTableCursor::HReadBuf::HReadBuf(CDbTableCursor& aCursor) sl@0: :iCursor(aCursor),iHost(0) sl@0: {aCursor.AddBlobSource();} sl@0: sl@0: CDbTableCursor::HReadBuf* CDbTableCursor::HReadBuf::NewLC(CDbTableCursor& aCursor) sl@0: { sl@0: HReadBuf* self=new(ELeave) HReadBuf(aCursor); sl@0: self->PushL(); sl@0: return self; sl@0: } sl@0: sl@0: inline CDbTableCursor::HReadBuf::~HReadBuf() sl@0: { sl@0: if (iHost) sl@0: iHost->Release(); sl@0: iCursor.ReleaseBlobSource(); sl@0: } sl@0: sl@0: void CDbTableCursor::HReadBuf::DoRelease() sl@0: { sl@0: delete this; sl@0: } sl@0: sl@0: TInt CDbTableCursor::HReadBuf::DoReadL(TAny* aPtr,TInt aMaxLength) sl@0: { sl@0: __ASSERT(iHost); sl@0: return iHost->ReadL(aPtr,aMaxLength); sl@0: } sl@0: sl@0: TStreamTransfer CDbTableCursor::HReadBuf::DoReadL(MStreamInput& aInput,TStreamTransfer aTransfer) sl@0: { sl@0: __ASSERT(iHost); sl@0: return iHost->ReadL(aInput,aTransfer); sl@0: } sl@0: sl@0: TStreamPos CDbTableCursor::HReadBuf::DoSeekL(TMark aMark,TStreamLocation aLocation,TInt aOffset) sl@0: { sl@0: __ASSERT(iHost); sl@0: return iHost->SeekL(aMark,aLocation,aOffset); sl@0: }