persistentstorage/sql/SRC/Client/SqlBlob.cpp
branchRCL_3
changeset 24 cc28652e0254
parent 23 26645d81f48d
equal deleted inserted replaced
23:26645d81f48d 24:cc28652e0254
     1 // Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    13 // Description:
    13 // Description:
    14 //
    14 //
    15 
    15 
    16 #include <s32mem.h>
    16 #include <s32mem.h>
    17 #include "SqlDb.h"
    17 #include "SqlDb.h"
    18 #include "SqlAssert.h"
    18 #include "SqlPanic.h"
    19 #include "SqlDatabaseImpl.h"
    19 #include "SqlDatabaseImpl.h"
    20 #include "IPCBuf.h"
    20 #include "IPCBuf.h"
    21 #include "OstTraceDefinitions.h"
       
    22 #ifdef OST_TRACE_COMPILER_IN_USE
       
    23 #include "SqlBlobTraces.h"
       
    24 #endif
       
    25 #include "SqlTraceDef.h"
       
    26 
    21 
    27 // The maximum time (100 milliseconds) that a block of data is allowed to take to be read/written by TSqlBlob.
    22 // The maximum time (100 milliseconds) that a block of data is allowed to take to be read/written by TSqlBlob.
    28 // If the time taken is longer than this value then the next block size used will be less
    23 // If the time taken is longer than this value then the next block size used will be less
    29 const TInt KTimeThresholdInMicroSecs = 100000; 
    24 const TInt KTimeThresholdInMicroSecs = 100000; 
    30 // The largest block size used by TSqlBlob is 32Kb
    25 // The largest block size used by TSqlBlob is 32Kb
   106 		TTimeIntervalMicroSeconds readTime = t2.MicroSecondsFrom(t1);
   101 		TTimeIntervalMicroSeconds readTime = t2.MicroSecondsFrom(t1);
   107 		timeThresholdBreached = (readTime.Int64() > KTimeThresholdInMicroSecs);
   102 		timeThresholdBreached = (readTime.Int64() > KTimeThresholdInMicroSecs);
   108 	
   103 	
   109 		// Update how much data is still to be read, and the buffer pointer
   104 		// Update how much data is still to be read, and the buffer pointer
   110 		remainingDataSize -= blockSize;
   105 		remainingDataSize -= blockSize;
   111 		__ASSERT_DEBUG(remainingDataSize >= 0, __SQLPANIC2(ESqlPanicInternalError));
   106 		__SQLASSERT(remainingDataSize >= 0, ESqlPanicInternalError);
   112 		ptr.Set((TUint8*)(ptr.Ptr() + blockSize), 0, remainingDataSize);
   107 		ptr.Set((TUint8*)(ptr.Ptr() + blockSize), 0, remainingDataSize);
   113 		}	
   108 		}	
   114 	aDestBuffer.SetLength(aBlobSize);
   109 	aDestBuffer.SetLength(aBlobSize);
   115 	}
   110 	}
   116 	
   111 	
   135 		TTimeIntervalMicroSeconds writeTime = t2.MicroSecondsFrom(t1);
   130 		TTimeIntervalMicroSeconds writeTime = t2.MicroSecondsFrom(t1);
   136 		timeThresholdBreached = (writeTime.Int64() > KTimeThresholdInMicroSecs);
   131 		timeThresholdBreached = (writeTime.Int64() > KTimeThresholdInMicroSecs);
   137 	
   132 	
   138 		// Update how much data is still to be written
   133 		// Update how much data is still to be written
   139 		remainingDataSize -= blockSize;
   134 		remainingDataSize -= blockSize;
   140 		__ASSERT_DEBUG(remainingDataSize >= 0, __SQLPANIC2(ESqlPanicInternalError));
   135 		__SQLASSERT(remainingDataSize >= 0, ESqlPanicInternalError);
   141 		}	
   136 		}	
   142 	aStrm.CommitL();	
   137 	aStrm.CommitL();	
   143 	}
   138 	}
   144 	
   139 	
   145 // The data is returned in a UTF-8 buffer that is allocated on the heap
   140 // The data is returned in a UTF-8 buffer that is allocated on the heap
   174 	CleanupClosePushL(strm);
   169 	CleanupClosePushL(strm);
   175 	strm.OpenL(aDb, aTableName, aColumnName, aRowId, aDbName);		
   170 	strm.OpenL(aDb, aTableName, aColumnName, aRowId, aDbName);		
   176 	TInt blobSize = strm.SizeL(); // size of the blob, in bytes
   171 	TInt blobSize = strm.SizeL(); // size of the blob, in bytes
   177 	if(blobSize > aBuffer.MaxSize())
   172 	if(blobSize > aBuffer.MaxSize())
   178 		{
   173 		{
   179 		__SQLLEAVE2(KErrOverflow);
   174 		__SQLLEAVE(KErrOverflow);
   180 		}	
   175 		}	
   181 	DoReadInBlocksL(strm, aBuffer, blobSize);
   176 	DoReadInBlocksL(strm, aBuffer, blobSize);
   182 	CleanupStack::PopAndDestroy(); // strm
   177 	CleanupStack::PopAndDestroy(); // strm
   183 	}
   178 	}
   184 	
   179 	
   195 	strm.OpenL(aDb, aTableName, aColumnName, aRowId, aDbName);
   190 	strm.OpenL(aDb, aTableName, aColumnName, aRowId, aDbName);
   196 	TInt dataSize = aData.Size(); // size of the data, in bytes
   191 	TInt dataSize = aData.Size(); // size of the data, in bytes
   197 	TInt blobSize = strm.SizeL(); // size of the blob, in bytes
   192 	TInt blobSize = strm.SizeL(); // size of the blob, in bytes
   198 	if(dataSize > blobSize)
   193 	if(dataSize > blobSize)
   199 		{
   194 		{
   200 		__SQLLEAVE2(KErrEof);
   195 		__SQLLEAVE(KErrEof);
   201 		}	
   196 		}	
   202 	if(dataSize > 0)
   197 	if(dataSize > 0)
   203 		{
   198 		{
   204 		DoWriteInBlocksL(strm, aData, dataSize);
   199 		DoWriteInBlocksL(strm, aData, dataSize);
   205 		}	
   200 		}	
   239             RSqlSecurityPolicy::ESchemaPolicy database policy type, if the blob belongs to a secure database; 
   234             RSqlSecurityPolicy::ESchemaPolicy database policy type, if the blob belongs to a secure database; 
   240 */		
   235 */		
   241 EXPORT_C void RSqlBlobReadStream::OpenL(RSqlDatabase& aDb, const TDesC& aTableName, const TDesC& aColumnName, 
   236 EXPORT_C void RSqlBlobReadStream::OpenL(RSqlDatabase& aDb, const TDesC& aTableName, const TDesC& aColumnName, 
   242 										TInt64 aRowId, const TDesC& aDbName)
   237 										TInt64 aRowId, const TDesC& aDbName)
   243 	{
   238 	{
   244 	SQL_TRACE_BORDER(OstTraceExt5(TRACE_BORDER, RSQLBLOBREADSTREAM_OPENL_ENTRY, "Entry;0;RSqlBlobReadStream::OpenL;aDb=0x%X;aTableName=%S;aColumnName=%S;aDbName=%S;aRowId=%lld", (TUint)&aDb, __SQLPRNSTR(aTableName), __SQLPRNSTR(aColumnName), __SQLPRNSTR(aDbName), aRowId));
   239 	SQLUTRACE_PROFILER(this);
       
   240 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KRSqlBlobParam16, &aDb, &aTableName, 
       
   241 			&aColumnName, aRowId, &aDbName));
       
   242 	
   245 	HBufC8* ipcPrmBuf = ::PrepareIpcParamBufLC(aTableName, aColumnName, aRowId, ETrue, aDbName);
   243 	HBufC8* ipcPrmBuf = ::PrepareIpcParamBufLC(aTableName, aColumnName, aRowId, ETrue, aDbName);
   246 	MStreamBuf* strm = ::CreateIpcStreamL(aDb.Impl().Session(), ipcPrmBuf->Des());
   244 	MStreamBuf* strm = ::CreateIpcStreamL(aDb.Impl().Session(), ipcPrmBuf->Des());
   247 	Attach(strm);
   245 	Attach(strm);
   248 	CleanupStack::PopAndDestroy(ipcPrmBuf);	
   246 	CleanupStack::PopAndDestroy(ipcPrmBuf);	
   249     SQL_TRACE_BORDER(OstTraceExt2(TRACE_BORDER, RSQLBLOBREADSTREAM_OPENL_EXIT, "Exit;0x%x;RSqlBlobReadStream::OpenL;strm=0x%X", (TUint)this, (TUint)strm));
       
   250 	}
   247 	}
   251 	
   248 	
   252 /**
   249 /**
   253 Returns the size of the blob object, in bytes.
   250 Returns the size of the blob object, in bytes.
   254 
   251 
   260 	
   257 	
   261 @capability None
   258 @capability None
   262 */
   259 */
   263 EXPORT_C TInt RSqlBlobReadStream::SizeL()
   260 EXPORT_C TInt RSqlBlobReadStream::SizeL()
   264 	{
   261 	{
   265     SQL_TRACE_BORDER(OstTrace1(TRACE_BORDER, RSQLBLOBREADSTREAM_SIZEL_ENTRY, "Entry;0x%X;RSqlBlobReadStream::SizeL;", (TUint)this));
   262 	SQLUTRACE_PROFILER(this);
       
   263 	
   266 	MStreamBuf* src = Source();
   264 	MStreamBuf* src = Source();
   267 	__ASSERT_ALWAYS(src != NULL, __SQLPANIC(ESqlPanicInvalidObj));
   265 	__SQLASSERT_ALWAYS(src != NULL, ESqlPanicInvalidObj);
   268 	TInt size = src->SizeL();
   266 	return src->SizeL();
   269     SQL_TRACE_BORDER(OstTraceExt2(TRACE_BORDER, RSQLBLOBREADSTREAM_SIZEL_EXIT, "Exit;0x%X;RSqlBlobReadStream::SizeL;size=%d", (TUint)this, size));
       
   270 	return size;
       
   271 	}
   267 	}
   272 
   268 
   273 /**
   269 /**
   274 Gives access to a blob as a writeable stream of bytes.
   270 Gives access to a blob as a writeable stream of bytes.
   275 
   271 
   301             RSqlSecurityPolicy::ESchemaPolicy database policy type, if the blob belongs to a secure database; 
   297             RSqlSecurityPolicy::ESchemaPolicy database policy type, if the blob belongs to a secure database; 
   302 */							
   298 */							
   303 EXPORT_C void RSqlBlobWriteStream::OpenL(RSqlDatabase& aDb, const TDesC& aTableName, const TDesC& aColumnName, 
   299 EXPORT_C void RSqlBlobWriteStream::OpenL(RSqlDatabase& aDb, const TDesC& aTableName, const TDesC& aColumnName, 
   304 										 TInt64 aRowId, const TDesC& aDbName)
   300 										 TInt64 aRowId, const TDesC& aDbName)
   305 	{
   301 	{
   306     SQL_TRACE_BORDER(OstTraceExt5(TRACE_BORDER, RSQLBLOBWRITESTREAM_OPENL_ENTRY, "Entry;0;RSqlBlobWriteStream::OpenL;aDb=0x%X;aTableName=%S;aColumnName=%S;aDbName=%S;aRowId=%lld", (TUint)&aDb, __SQLPRNSTR(aTableName), __SQLPRNSTR(aColumnName), __SQLPRNSTR(aDbName), aRowId));
   302 	SQLUTRACE_PROFILER(this);
       
   303 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KRSqlBlobParam16, &aDb, &aTableName, 
       
   304 			&aColumnName, aRowId, &aDbName));
       
   305 	
   307 	HBufC8* ipcPrmBuf = ::PrepareIpcParamBufLC(aTableName, aColumnName, aRowId, EFalse, aDbName);
   306 	HBufC8* ipcPrmBuf = ::PrepareIpcParamBufLC(aTableName, aColumnName, aRowId, EFalse, aDbName);
   308 	MStreamBuf* strm = ::CreateIpcStreamL(aDb.Impl().Session(), ipcPrmBuf->Des());
   307 	MStreamBuf* strm = ::CreateIpcStreamL(aDb.Impl().Session(), ipcPrmBuf->Des());
   309 	Attach(strm);
   308 	Attach(strm);
   310 	CleanupStack::PopAndDestroy(ipcPrmBuf);		
   309 	CleanupStack::PopAndDestroy(ipcPrmBuf);		
   311     SQL_TRACE_BORDER(OstTraceExt2(TRACE_BORDER, RSQLBLOBWRITESTREAM_OPENL_EXIT, "Exit;0x%x;RSqlBlobWriteStream::OpenL;strm=0x%X", (TUint)this, (TUint)strm));
       
   312 	}
   310 	}
   313 
   311 
   314 /**
   312 /**
   315 Returns the size of the blob object, in bytes.
   313 Returns the size of the blob object, in bytes.
   316 
   314 
   322 	
   320 	
   323 @capability None
   321 @capability None
   324 */
   322 */
   325 EXPORT_C TInt RSqlBlobWriteStream::SizeL()
   323 EXPORT_C TInt RSqlBlobWriteStream::SizeL()
   326 	{
   324 	{
   327     SQL_TRACE_BORDER(OstTrace1(TRACE_BORDER, RSQLBLOBWRITESTREAM_SIZEL_ENTRY, "Entry;0x%X;RSqlBlobWriteStream::SizeL;", (TUint)this));
   325 	SQLUTRACE_PROFILER(this);
       
   326 
   328 	MStreamBuf* sink = Sink();
   327 	MStreamBuf* sink = Sink();
   329 	__ASSERT_ALWAYS(sink != NULL, __SQLPANIC(ESqlPanicInvalidObj));
   328 	__SQLASSERT_ALWAYS(sink != NULL, ESqlPanicInvalidObj);
   330 	TInt size =  sink->SizeL();
   329 	return sink->SizeL();
   331     SQL_TRACE_BORDER(OstTraceExt2(TRACE_BORDER, RSQLBLOBWRITESTREAM_SIZEL_EXIT, "Exit;0x%X;RSqlBlobWriteStream::SizeL;size=%d", (TUint)this, size));
       
   332     return size;
       
   333 	}
   330 	}
   334 
   331 
   335 /**
   332 /**
   336 Retrieves the entire content of a blob and returns it to the client 
   333 Retrieves the entire content of a blob and returns it to the client 
   337 in a heap allocated buffer which has been placed on the cleanup stack. 
   334 in a heap allocated buffer which has been placed on the cleanup stack. 
   368 					     	     const TDesC& aTableName, 
   365 					     	     const TDesC& aTableName, 
   369 					     		 const TDesC& aColumnName, 	
   366 					     		 const TDesC& aColumnName, 	
   370 					     		 TInt64 aRowId,
   367 					     		 TInt64 aRowId,
   371 					     		 const TDesC& aDbName)
   368 					     		 const TDesC& aDbName)
   372 	{
   369 	{
   373     SQL_TRACE_BORDER(OstTraceExt5(TRACE_BORDER, TSQLBLOB_GETLC_ENTRY, "Entry;0;TSqlBlob::GetLC;aDb=0x%X;aTableName=%S;aColumnName=%S;aDbName=%S;aRowId=%lld", (TUint)&aDb, __SQLPRNSTR(aTableName), __SQLPRNSTR(aColumnName), __SQLPRNSTR(aDbName), aRowId));
   370 	SQLUTRACE_PROFILER(0);
   374 	HBufC8* res = ReadLC(aDb, aTableName, aColumnName, aRowId, aDbName);
   371 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KRSqlBlobParam16, &aDb, &aTableName, 
   375     SQL_TRACE_BORDER(OstTraceExt2(TRACE_BORDER, TSQLBLOB_GETLC_EXIT, "Exit;0;TSqlBlob::GetLC;res=0x%X;res->Size()=%d", (TUint)res, res->Des().Size()));
   372 			&aColumnName, aRowId, &aDbName));
   376 	return res;
   373 	
       
   374 	return ReadLC(aDb, aTableName, aColumnName, aRowId, aDbName);
   377 	}
   375 	}
   378 	
   376 	
   379 /**
   377 /**
   380 Retrieves the entire content of a blob into a client specified buffer.
   378 Retrieves the entire content of a blob into a client specified buffer.
   381 
   379 
   412 					 	    const TDesC& aColumnName, 	
   410 					 	    const TDesC& aColumnName, 	
   413 					 	    TDes8& aBuffer,
   411 					 	    TDes8& aBuffer,
   414 					 		TInt64 aRowId,
   412 					 		TInt64 aRowId,
   415 					 	    const TDesC& aDbName)
   413 					 	    const TDesC& aDbName)
   416 	{
   414 	{
   417     SQL_TRACE_BORDER(OstTraceExt5(TRACE_BORDER, TSQLBLOB_GET_ENTRY, "Entry;0;TSqlBlob::Get;aDb=0x%X;aTableName=%S;aColumnName=%S;aDbName=%S;aRowId=%lld", (TUint)&aDb, __SQLPRNSTR(aTableName), __SQLPRNSTR(aColumnName), __SQLPRNSTR(aDbName), aRowId));
   415 	SQLUTRACE_PROFILER(0);
       
   416 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KRSqlBlobParam16, &aDb, &aTableName, 
       
   417 			&aColumnName, aRowId, &aDbName));
       
   418 	
   418 	TRAPD(err, ReadL(aDb, aTableName, aColumnName, aBuffer, aRowId, aDbName));
   419 	TRAPD(err, ReadL(aDb, aTableName, aColumnName, aBuffer, aRowId, aDbName));
   419     SQL_TRACE_BORDER(OstTraceExt2(TRACE_BORDER, TSQLBLOB_GET_EXIT, "Exit;0;TSqlBlob::Get;aBuffer.Ptr()=0x%X;aBuffer.Size()=%d", (TUint)aBuffer.Ptr(), aBuffer.Size()));
       
   420 	return err;	
   420 	return err;	
   421 	}
   421 	}
   422 
   422 
   423 /**
   423 /**
   424 Writes the data in a client specified buffer to a blob.
   424 Writes the data in a client specified buffer to a blob.
   456 					  		 const TDesC& aColumnName,
   456 					  		 const TDesC& aColumnName,
   457 					  		 const TDesC8& aData,	
   457 					  		 const TDesC8& aData,	
   458 					  		 TInt64 aRowId,
   458 					  		 TInt64 aRowId,
   459 					  		 const TDesC& aDbName)
   459 					  		 const TDesC& aDbName)
   460 	{
   460 	{
   461     SQL_TRACE_BORDER(OstTraceExt5(TRACE_BORDER, TSQLBLOB_SET_ENTRY, "Entry;0;TSqlBlob::Set;aDb=0x%X;aTableName=%S;aColumnName=%S;aDbName=%S;aRowId=%lld", (TUint)&aDb, __SQLPRNSTR(aTableName), __SQLPRNSTR(aColumnName), __SQLPRNSTR(aDbName), aRowId));
   461 	SQLUTRACE_PROFILER(0);
   462     SQL_TRACE_BORDER(OstTraceExt2(TRACE_BORDER, TSQLBLOB_SET_ENTRYEXT, "EntryExt;0;TSqlBlob::Set;aData.Ptr=0x%X;aData.Size()=%d", (TUint)aData.Ptr(), aData.Size()));
   462 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KRSqlBlobParam16, &aDb, &aTableName, 
       
   463 			&aColumnName, aRowId, &aDbName));
       
   464 	
   463 	WriteL(aDb, aTableName, aColumnName, aData,	aRowId, aDbName);
   465 	WriteL(aDb, aTableName, aColumnName, aData,	aRowId, aDbName);
   464     SQL_TRACE_BORDER(OstTrace0(TRACE_BORDER, TSQLBLOB_SET_EXIT, "Exit;0;TSqlBlob::Set"));
   466 	}
   465 	}
   467 
   466