persistentstorage/sql/SRC/Client/SqlBlob.cpp
changeset 0 08ec8eefde2f
child 23 26645d81f48d
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 2008-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 <s32mem.h>
       
    17 #include "SqlDb.h"
       
    18 #include "SqlPanic.h"
       
    19 #include "SqlDatabaseImpl.h"
       
    20 #include "IPCBuf.h"
       
    21 
       
    22 // The maximum time (100 milliseconds) that a block of data is allowed to take to be read/written by TSqlBlob.
       
    23 // If the time taken is longer than this value then the next block size used will be less
       
    24 const TInt KTimeThresholdInMicroSecs = 100000; 
       
    25 // The largest block size used by TSqlBlob is 32Kb
       
    26 const TInt KLargestBlockSize = 32 * 1024; 
       
    27 // The client-side buffer will be used instead if the calculated block size is 2Kb or less 
       
    28 const TInt KUseClientBufferThreshold = 2 * 1024; 
       
    29 
       
    30 // Prepare an IPC buffer containing the parameter values
       
    31 static HBufC8* PrepareIpcParamBufLC(const TDesC& aTableName, const TDesC& aColumnName, TInt64 aRowId, 
       
    32 								  TBool aReadOnly, const TDesC& aDbName)
       
    33 	{
       
    34 	HBufC8* ipcPrmBuf = HBufC8::NewLC(aTableName.Size() + sizeof(TDesC) + 
       
    35 									  aColumnName.Size() + sizeof(TDesC) +
       
    36 									  sizeof(aRowId) + sizeof(aReadOnly) + 
       
    37 									  aDbName.Size() + sizeof(TDesC) + sizeof(TInt32) * 3);
       
    38 	TPtr8 ipcPrmDes = ipcPrmBuf->Des();
       
    39 	RDesWriteStream strm(ipcPrmDes);
       
    40 	
       
    41 	strm << static_cast <TInt32> (aTableName.Length()) 
       
    42 	     << aTableName 
       
    43 	     << static_cast <TInt32> (aColumnName.Length()) 
       
    44 	     << aColumnName 
       
    45 	     << aRowId 
       
    46 	     << static_cast<TInt32>(aReadOnly) 
       
    47 	     << static_cast <TInt32> (aDbName.Length()) 
       
    48 	     << aDbName;
       
    49 	strm.CommitL();
       
    50 	strm.Close();
       
    51 	return ipcPrmBuf;
       
    52 	}
       
    53 
       
    54 // Create an IPC stream, sending the IPC buffer containing the parameter values
       
    55 static MStreamBuf* CreateIpcStreamL(RSqlDbSession& aDbSession, const TDesC8& aIpcPrmBuf)
       
    56 	{
       
    57 	TIpcArgs ipcArgs;
       
    58 	ipcArgs.Set(0, aIpcPrmBuf.Length());
       
    59 	ipcArgs.Set(1, &aIpcPrmBuf);
       
    60 	HIpcBuf* ipcBuf = HIpcBuf::NewL(aDbSession, ::MakeMsgCode(ESqlSrvDbBlobSource, ESqlSrvNoHandle, 0), ipcArgs);
       
    61 	return ipcBuf;
       
    62 	}	
       
    63 	
       
    64 // Used by TSqlBlob to calculate the appropriate block size to use for the next transfer of blob data
       
    65 static TInt CalculateBlockSize(TInt aRemainingDataSize, TInt aPreviousBlockSize, TBool aTimeThresholdBreached)
       
    66 	{
       
    67 	TInt blockSize = aPreviousBlockSize;
       
    68 	if(aTimeThresholdBreached)
       
    69 		{
       
    70 		// The time threshold was breached using the previous block size
       
    71 		// so we will reduce the block size by a factor of 2
       
    72 		blockSize /= 2;
       
    73 		if(blockSize <= KUseClientBufferThreshold)
       
    74 			{
       
    75 			// Just use the client-side IPC buffer size if things get to this stage
       
    76 			blockSize = KIpcBufSize; 
       
    77 			}
       
    78 		}	
       
    79 	return aRemainingDataSize <= blockSize ? aRemainingDataSize : blockSize;
       
    80 	}
       
    81 		
       
    82 // Retrieve the data in blocks
       
    83 static void DoReadInBlocksL(RSqlBlobReadStream& aStrm, TDes8& aDestBuffer, TInt aBlobSize)
       
    84 	{
       
    85 	TInt remainingDataSize = aBlobSize;	
       
    86 	TBool timeThresholdBreached = EFalse;
       
    87 	TInt blockSize = KLargestBlockSize;
       
    88 	TPtr8 ptr((TUint8*)aDestBuffer.Ptr(), aDestBuffer.MaxSize());
       
    89 	
       
    90 	while(remainingDataSize > 0)
       
    91 		{	
       
    92 		// Calculate the block size to use for this iteration, based on 
       
    93 		// how much data is remaining and how fast the previous read was
       
    94 		blockSize = CalculateBlockSize(remainingDataSize, blockSize, timeThresholdBreached);
       
    95 		
       
    96 		// Read the block of data, timing how long it takes
       
    97 		TTime t1, t2;
       
    98 		t1.HomeTime();
       
    99 		aStrm.ReadL(ptr, blockSize);
       
   100 		t2.HomeTime();
       
   101 		TTimeIntervalMicroSeconds readTime = t2.MicroSecondsFrom(t1);
       
   102 		timeThresholdBreached = (readTime.Int64() > KTimeThresholdInMicroSecs);
       
   103 	
       
   104 		// Update how much data is still to be read, and the buffer pointer
       
   105 		remainingDataSize -= blockSize;
       
   106 		__SQLASSERT(remainingDataSize >= 0, ESqlPanicInternalError);
       
   107 		ptr.Set((TUint8*)(ptr.Ptr() + blockSize), 0, remainingDataSize);
       
   108 		}	
       
   109 	aDestBuffer.SetLength(aBlobSize);
       
   110 	}
       
   111 	
       
   112 // Send the data in blocks
       
   113 static void DoWriteInBlocksL(RSqlBlobWriteStream& aStrm, const TDesC8& aData, TInt aDataSize)
       
   114 	{
       
   115 	TInt remainingDataSize = aDataSize;	
       
   116 	TBool timeThresholdBreached = EFalse;
       
   117 	TInt blockSize = KLargestBlockSize;
       
   118 	
       
   119 	while(remainingDataSize > 0)
       
   120 		{	
       
   121 		// Calculate the block size to use for this iteration, based on 
       
   122 		// how much data is remaining and how fast the previous write was
       
   123 		blockSize = CalculateBlockSize(remainingDataSize, blockSize, timeThresholdBreached);
       
   124 
       
   125 		// Write the block of data, timing how long it takes
       
   126 		TTime t1, t2;
       
   127 		t1.HomeTime();
       
   128 		aStrm.WriteL(aData.Right(remainingDataSize), blockSize);
       
   129 		t2.HomeTime();
       
   130 		TTimeIntervalMicroSeconds writeTime = t2.MicroSecondsFrom(t1);
       
   131 		timeThresholdBreached = (writeTime.Int64() > KTimeThresholdInMicroSecs);
       
   132 	
       
   133 		// Update how much data is still to be written
       
   134 		remainingDataSize -= blockSize;
       
   135 		__SQLASSERT(remainingDataSize >= 0, ESqlPanicInternalError);
       
   136 		}	
       
   137 	aStrm.CommitL();	
       
   138 	}
       
   139 	
       
   140 // The data is returned in a UTF-8 buffer that is allocated on the heap
       
   141 static HBufC8* ReadLC(RSqlDatabase& aDb, 	
       
   142 				   	  const TDesC& aTableName, 
       
   143 				   	  const TDesC& aColumnName, 
       
   144 				   	  TInt64 aRowId,
       
   145 				   	  const TDesC& aDbName)	
       
   146 	{
       
   147 	RSqlBlobReadStream strm;
       
   148 	CleanupClosePushL(strm);
       
   149 	strm.OpenL(aDb, aTableName, aColumnName, aRowId, aDbName);		
       
   150 	TInt blobSize = strm.SizeL(); // size of the blob, in bytes
       
   151 	HBufC8* buf = HBufC8::NewLC(blobSize);
       
   152 	TPtr8 ptr = buf->Des();	
       
   153 	DoReadInBlocksL(strm, ptr, blobSize);
       
   154 	CleanupStack::Pop(); // buf
       
   155 	CleanupStack::PopAndDestroy(); // strm
       
   156 	CleanupStack::PushL(buf);
       
   157 	return buf;	
       
   158 	}
       
   159 
       
   160 // The data is returned in the UTF-8 buffer passed in
       
   161 static void ReadL(RSqlDatabase& aDb, 	
       
   162 				  const TDesC& aTableName, 
       
   163 				  const TDesC& aColumnName, 	
       
   164 				  TDes8& aBuffer,
       
   165 				  TInt64 aRowId,
       
   166 				  const TDesC& aDbName)
       
   167 	{	
       
   168 	RSqlBlobReadStream strm;
       
   169 	CleanupClosePushL(strm);
       
   170 	strm.OpenL(aDb, aTableName, aColumnName, aRowId, aDbName);		
       
   171 	TInt blobSize = strm.SizeL(); // size of the blob, in bytes
       
   172 	if(blobSize > aBuffer.MaxSize())
       
   173 		{
       
   174 		__SQLLEAVE(KErrOverflow);
       
   175 		}	
       
   176 	DoReadInBlocksL(strm, aBuffer, blobSize);
       
   177 	CleanupStack::PopAndDestroy(); // strm
       
   178 	}
       
   179 	
       
   180 // The data in the client-specified UTF-8 buffer is written
       
   181 static void WriteL(RSqlDatabase& aDb, 	
       
   182 				   const TDesC& aTableName, 
       
   183 				   const TDesC& aColumnName,
       
   184 				   const TDesC8& aData,	
       
   185 				   TInt64 aRowId,
       
   186 				   const TDesC& aDbName)
       
   187 	{
       
   188 	RSqlBlobWriteStream strm;
       
   189 	CleanupClosePushL(strm);
       
   190 	strm.OpenL(aDb, aTableName, aColumnName, aRowId, aDbName);
       
   191 	TInt dataSize = aData.Size(); // size of the data, in bytes
       
   192 	TInt blobSize = strm.SizeL(); // size of the blob, in bytes
       
   193 	if(dataSize > blobSize)
       
   194 		{
       
   195 		__SQLLEAVE(KErrEof);
       
   196 		}	
       
   197 	if(dataSize > 0)
       
   198 		{
       
   199 		DoWriteInBlocksL(strm, aData, dataSize);
       
   200 		}	
       
   201 	CleanupStack::PopAndDestroy(); // strm
       
   202 	}
       
   203 
       
   204 ////////////////////////////////////////////////////////////////////////////////	
       
   205 			
       
   206 /**
       
   207 Gives access to a blob as a read-only stream of bytes.
       
   208 
       
   209 @param aDb        	  A connection to the database that contains the blob
       
   210 @param aTableName     The name of the table that contains the blob
       
   211 @param aColumnName    The name of the column that contains the blob
       
   212 @param aRowId         The ROWID of the record that contains the blob,
       
   213 					  or KSqlLastInsertedRowId if the last inserted ROWID 
       
   214 					  of the specified database connection is to be used
       
   215 @param aDbName  	  The name of the attached database if the blob is 
       
   216 					  contained in an attached database
       
   217 
       
   218 @leave KSqlErrGeneral, 		 Invalid database connection or table name or column name 
       
   219 							 or column type or ROWID or database name;							 
       
   220 	   KErrNoMemory, 		 An out of memory condition occurred;	   
       
   221 	   KErrArgument, 		 The ROWID is zero or negative or a UTF-16 to UTF-8 string conversion failed;
       
   222   	   KErrBadName,  		 The table name, column name or database name has an invalid length;
       
   223 	   KErrPermissionDenied, The client does not have the required security capabilites for this operation; 						 
       
   224        						 Note that the function may also leave with some other system wide errors or 
       
   225                      		 database specific errors categorised as ESqlDbError.
       
   226 	     
       
   227 @panic SqlDb 2 The database object is not yet created
       
   228 @panic SqlDb 3 Server failed to create a handle to the blob
       
   229 @panic SqlDb 4 In _DEBUG mode. Bad parameter value
       
   230 @panic SqlDb 7 In _DEBUG mode. NULL blob handle
       
   231 
       
   232 @capability None, if the aDb parameter represents a handle which operates on a non-secure database;
       
   233             RSqlSecurityPolicy::EReadPolicy or 
       
   234             RSqlSecurityPolicy::ESchemaPolicy database policy type, if the blob belongs to a secure database; 
       
   235 */		
       
   236 EXPORT_C void RSqlBlobReadStream::OpenL(RSqlDatabase& aDb, const TDesC& aTableName, const TDesC& aColumnName, 
       
   237 										TInt64 aRowId, const TDesC& aDbName)
       
   238 	{
       
   239 	SQLUTRACE_PROFILER(this);
       
   240 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KRSqlBlobParam16, &aDb, &aTableName, 
       
   241 			&aColumnName, aRowId, &aDbName));
       
   242 	
       
   243 	HBufC8* ipcPrmBuf = ::PrepareIpcParamBufLC(aTableName, aColumnName, aRowId, ETrue, aDbName);
       
   244 	MStreamBuf* strm = ::CreateIpcStreamL(aDb.Impl().Session(), ipcPrmBuf->Des());
       
   245 	Attach(strm);
       
   246 	CleanupStack::PopAndDestroy(ipcPrmBuf);	
       
   247 	}
       
   248 	
       
   249 /**
       
   250 Returns the size of the blob object, in bytes.
       
   251 
       
   252 @return The size of the blob object, in bytes
       
   253 
       
   254 @leave One of the system-wide error codes
       
   255 
       
   256 @panic SqlDb 2 The stream buffer is NULL
       
   257 	
       
   258 @capability None
       
   259 */
       
   260 EXPORT_C TInt RSqlBlobReadStream::SizeL()
       
   261 	{
       
   262 	SQLUTRACE_PROFILER(this);
       
   263 	
       
   264 	MStreamBuf* src = Source();
       
   265 	__SQLASSERT_ALWAYS(src != NULL, ESqlPanicInvalidObj);
       
   266 	return src->SizeL();
       
   267 	}
       
   268 
       
   269 /**
       
   270 Gives access to a blob as a writeable stream of bytes.
       
   271 
       
   272 @param aDb        	  A connection to the database that contains the blob
       
   273 @param aTableName     The name of the table that contains the blob
       
   274 @param aColumnName    The name of the column that contains the blob
       
   275 @param aRowId         The ROWID of the record that contains the blob,
       
   276 					  or KSqlLastInsertedRowId if the last inserted ROWID 
       
   277 					  of the specified database connection is to be used
       
   278 @param aDbName  	  The name of the attached database if the blob is 
       
   279 					  contained in an attached database
       
   280 
       
   281 @leave KSqlErrGeneral, 		 Invalid database connection or table name or column name or column 
       
   282 							 type or ROWID or database name, or the specified column is indexed;
       
   283 	   KErrNoMemory, 		 An out of memory condition occurred;	   
       
   284 	   KErrArgument, 		 The ROWID is zero or negative or a UTF-16 to UTF-8 string conversion failed;
       
   285   	   KErrBadName,  		 The table name, column name or database name has an invalid length;
       
   286 	   KErrPermissionDenied, The client does not have the required security capabilites for this operation; 						 
       
   287        						 Note that the function may also leave with some other system wide errors or 
       
   288                      		 database specific errors categorised as ESqlDbError.
       
   289 	     
       
   290 @panic SqlDb 2 The database object is not yet created
       
   291 @panic SqlDb 3 Server failed to create a handle to the blob
       
   292 @panic SqlDb 4 In _DEBUG mode. Bad parameter value
       
   293 @panic SqlDb 7 In _DEBUG mode. NULL blob handle
       
   294 
       
   295 @capability None, if the aDb parameter represents a handle which operates on a non-secure database;
       
   296             RSqlSecurityPolicy::EWritePolicy or 
       
   297             RSqlSecurityPolicy::ESchemaPolicy database policy type, if the blob belongs to a secure database; 
       
   298 */							
       
   299 EXPORT_C void RSqlBlobWriteStream::OpenL(RSqlDatabase& aDb, const TDesC& aTableName, const TDesC& aColumnName, 
       
   300 										 TInt64 aRowId, const TDesC& aDbName)
       
   301 	{
       
   302 	SQLUTRACE_PROFILER(this);
       
   303 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KRSqlBlobParam16, &aDb, &aTableName, 
       
   304 			&aColumnName, aRowId, &aDbName));
       
   305 	
       
   306 	HBufC8* ipcPrmBuf = ::PrepareIpcParamBufLC(aTableName, aColumnName, aRowId, EFalse, aDbName);
       
   307 	MStreamBuf* strm = ::CreateIpcStreamL(aDb.Impl().Session(), ipcPrmBuf->Des());
       
   308 	Attach(strm);
       
   309 	CleanupStack::PopAndDestroy(ipcPrmBuf);		
       
   310 	}
       
   311 
       
   312 /**
       
   313 Returns the size of the blob object, in bytes.
       
   314 
       
   315 @return The size of the blob object, in bytes
       
   316 
       
   317 @leave One of the system-wide error codes
       
   318 
       
   319 @panic SqlDb 2 The stream buffer is NULL
       
   320 	
       
   321 @capability None
       
   322 */
       
   323 EXPORT_C TInt RSqlBlobWriteStream::SizeL()
       
   324 	{
       
   325 	SQLUTRACE_PROFILER(this);
       
   326 
       
   327 	MStreamBuf* sink = Sink();
       
   328 	__SQLASSERT_ALWAYS(sink != NULL, ESqlPanicInvalidObj);
       
   329 	return sink->SizeL();
       
   330 	}
       
   331 
       
   332 /**
       
   333 Retrieves the entire content of a blob and returns it to the client 
       
   334 in a heap allocated buffer which has been placed on the cleanup stack. 
       
   335 It is the responsibility of the client to destroy the returned buffer.
       
   336 
       
   337 @param aDb        	  A connection to the database that contains the blob
       
   338 @param aTableName     The name of the table that contains the blob
       
   339 @param aColumnName    The name of the column that contains the blob
       
   340 @param aRowId         The ROWID of the record that contains the blob,
       
   341 					  or KSqlLastInsertedRowId if the last inserted ROWID 
       
   342 					  of the specified database connection is to be used
       
   343 @param aDbName  	  The name of the attached database if the blob is 
       
   344 					  contained in an attached database
       
   345 
       
   346 @leave KSqlErrGeneral, 		 Invalid database connection or table name or column name 
       
   347 							 or column type or ROWID or database name;							 
       
   348 	   KErrNoMemory, 		 An out of memory condition occurred;	   
       
   349 	   KErrArgument, 		 The ROWID is zero or negative or a UTF-16 to UTF-8 string conversion failed;
       
   350   	   KErrBadName,  		 The table name, column name or database name has an invalid length;
       
   351 	   KErrPermissionDenied, The client does not have the required security capabilites for this operation; 						 
       
   352        						 Note that the function may also leave with some other system wide errors or 
       
   353                      		 database specific errors categorised as ESqlDbError.
       
   354 	     
       
   355 @panic SqlDb 2 The database object is not yet created
       
   356 @panic SqlDb 3 Server failed to create a handle to the blob
       
   357 @panic SqlDb 4 In _DEBUG mode. Bad parameter value
       
   358 @panic SqlDb 7 In _DEBUG mode. NULL blob handle or miscalculation of remaining data to be read
       
   359 
       
   360 @capability None, if the aDb parameter represents a handle which operates on a non-secure database;
       
   361             RSqlSecurityPolicy::EReadPolicy or 
       
   362             RSqlSecurityPolicy::ESchemaPolicy database policy type, if the blob belongs to a secure database; 
       
   363 */
       
   364 EXPORT_C HBufC8* TSqlBlob::GetLC(RSqlDatabase& aDb, 	
       
   365 					     	     const TDesC& aTableName, 
       
   366 					     		 const TDesC& aColumnName, 	
       
   367 					     		 TInt64 aRowId,
       
   368 					     		 const TDesC& aDbName)
       
   369 	{
       
   370 	SQLUTRACE_PROFILER(0);
       
   371 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KRSqlBlobParam16, &aDb, &aTableName, 
       
   372 			&aColumnName, aRowId, &aDbName));
       
   373 	
       
   374 	return ReadLC(aDb, aTableName, aColumnName, aRowId, aDbName);
       
   375 	}
       
   376 	
       
   377 /**
       
   378 Retrieves the entire content of a blob into a client specified buffer.
       
   379 
       
   380 @param aDb        	  A connection to the database that contains the blob
       
   381 @param aTableName     The name of the table that contains the blob
       
   382 @param aColumnName    The name of the column that contains the blob
       
   383 @param aRowId         The ROWID of the record that contains the blob,
       
   384 					  or KSqlLastInsertedRowId if the last inserted ROWID 
       
   385 					  of the specified database connection is to be used
       
   386 @param aDbName  	  The name of the attached database if the blob is 
       
   387 					  contained in an attached database
       
   388 
       
   389 @return KSqlErrGeneral, 	  Invalid database connection or table name or column name 
       
   390 							  or column type or ROWID or database name;							 
       
   391 	    KErrNoMemory, 		  An out of memory condition occurred;	   
       
   392 	    KErrArgument, 		  The ROWID is zero or negative or a UTF-16 to UTF-8 string conversion failed;
       
   393  	    KErrOverflow, 		  The specified buffer is not big enough to hold the entire blob;
       
   394   	    KErrBadName,  		  The table name, column name or database name has an invalid length;
       
   395 	    KErrPermissionDenied, The client does not have the required security capabilites for this operation; 						 
       
   396        						  Note that the function may also leave with some other system wide errors or 
       
   397                      		  database specific errors categorised as ESqlDbError.                    		 
       
   398 	     
       
   399 @panic SqlDb 2 The database object is not yet created
       
   400 @panic SqlDb 3 Server failed to create a handle to the blob
       
   401 @panic SqlDb 4 In _DEBUG mode. Bad parameter value
       
   402 @panic SqlDb 7 In _DEBUG mode. NULL blob handle or miscalculation of remaining data to be read
       
   403 
       
   404 @capability None, if the aDb parameter represents a handle which operates on a non-secure database;
       
   405             RSqlSecurityPolicy::EReadPolicy or 
       
   406             RSqlSecurityPolicy::ESchemaPolicy database policy type, if the blob belongs to a secure database; 
       
   407 */
       
   408 EXPORT_C TInt TSqlBlob::Get(RSqlDatabase& aDb, 	
       
   409 					 		const TDesC& aTableName, 
       
   410 					 	    const TDesC& aColumnName, 	
       
   411 					 	    TDes8& aBuffer,
       
   412 					 		TInt64 aRowId,
       
   413 					 	    const TDesC& aDbName)
       
   414 	{
       
   415 	SQLUTRACE_PROFILER(0);
       
   416 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KRSqlBlobParam16, &aDb, &aTableName, 
       
   417 			&aColumnName, aRowId, &aDbName));
       
   418 	
       
   419 	TRAPD(err, ReadL(aDb, aTableName, aColumnName, aBuffer, aRowId, aDbName));
       
   420 	return err;	
       
   421 	}
       
   422 
       
   423 /**
       
   424 Writes the data in a client specified buffer to a blob.
       
   425 
       
   426 @param aDb        	  A connection to the database that contains the blob
       
   427 @param aTableName     The name of the table that contains the blob
       
   428 @param aColumnName    The name of the column that contains the blob
       
   429 @param aRowId         The ROWID of the record that contains the blob,
       
   430 					  or KSqlLastInsertedRowId if the last inserted ROWID 
       
   431 					  of the specified database connection is to be used
       
   432 @param aDbName  	  The name of the attached database if the blob is 
       
   433 					  contained in an attached database
       
   434 
       
   435 @leave KSqlErrGeneral, 		 Invalid database connection or table name or column name or column 
       
   436 							 type or ROWID or database name, or the specified column is indexed;
       
   437 	   KErrNoMemory, 		 An out of memory condition occurred;	   
       
   438 	   KErrArgument, 		 The ROWID is zero or negative or a UTF-16 to UTF-8 string conversion failed;
       
   439 	   KErrEof,	     		 The data in the specified buffer is larger in size than the blob object;
       
   440   	   KErrBadName,  		 The table name, column name or database name has an invalid length;
       
   441 	   KErrPermissionDenied, The client does not have the required security capabilites for this operation; 						 
       
   442        						 Note that the function may also leave with some other system wide errors or 
       
   443                      		 database specific errors categorised as ESqlDbError.
       
   444 	     
       
   445 @panic SqlDb 2 The database object is not yet created
       
   446 @panic SqlDb 3 Server failed to create a handle to the blob
       
   447 @panic SqlDb 4 In _DEBUG mode. Bad parameter value
       
   448 @panic SqlDb 7 In _DEBUG mode. NULL blob handle or miscalculation of remaining data to be written
       
   449 
       
   450 @capability None, if the aDb parameter represents a handle which operates on a non-secure database;
       
   451             RSqlSecurityPolicy::EWritePolicy or 
       
   452             RSqlSecurityPolicy::ESchemaPolicy database policy type, if the blob belongs to a secure database; 
       
   453 */
       
   454 EXPORT_C void TSqlBlob::SetL(RSqlDatabase& aDb, 	
       
   455 					  		 const TDesC& aTableName, 
       
   456 					  		 const TDesC& aColumnName,
       
   457 					  		 const TDesC8& aData,	
       
   458 					  		 TInt64 aRowId,
       
   459 					  		 const TDesC& aDbName)
       
   460 	{
       
   461 	SQLUTRACE_PROFILER(0);
       
   462 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KRSqlBlobParam16, &aDb, &aTableName, 
       
   463 			&aColumnName, aRowId, &aDbName));
       
   464 	
       
   465 	WriteL(aDb, aTableName, aColumnName, aData,	aRowId, aDbName);
       
   466 	}
       
   467