1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sql/SRC/Client/SqlBlob.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,466 @@
1.4 +// Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include <s32mem.h>
1.20 +#include "SqlDb.h"
1.21 +#include "SqlAssert.h"
1.22 +#include "SqlDatabaseImpl.h"
1.23 +#include "IPCBuf.h"
1.24 +#include "OstTraceDefinitions.h"
1.25 +#ifdef OST_TRACE_COMPILER_IN_USE
1.26 +#include "SqlBlobTraces.h"
1.27 +#endif
1.28 +#include "SqlTraceDef.h"
1.29 +
1.30 +// The maximum time (100 milliseconds) that a block of data is allowed to take to be read/written by TSqlBlob.
1.31 +// If the time taken is longer than this value then the next block size used will be less
1.32 +const TInt KTimeThresholdInMicroSecs = 100000;
1.33 +// The largest block size used by TSqlBlob is 32Kb
1.34 +const TInt KLargestBlockSize = 32 * 1024;
1.35 +// The client-side buffer will be used instead if the calculated block size is 2Kb or less
1.36 +const TInt KUseClientBufferThreshold = 2 * 1024;
1.37 +
1.38 +// Prepare an IPC buffer containing the parameter values
1.39 +static HBufC8* PrepareIpcParamBufLC(const TDesC& aTableName, const TDesC& aColumnName, TInt64 aRowId,
1.40 + TBool aReadOnly, const TDesC& aDbName)
1.41 + {
1.42 + HBufC8* ipcPrmBuf = HBufC8::NewLC(aTableName.Size() + sizeof(TDesC) +
1.43 + aColumnName.Size() + sizeof(TDesC) +
1.44 + sizeof(aRowId) + sizeof(aReadOnly) +
1.45 + aDbName.Size() + sizeof(TDesC) + sizeof(TInt32) * 3);
1.46 + TPtr8 ipcPrmDes = ipcPrmBuf->Des();
1.47 + RDesWriteStream strm(ipcPrmDes);
1.48 +
1.49 + strm << static_cast <TInt32> (aTableName.Length())
1.50 + << aTableName
1.51 + << static_cast <TInt32> (aColumnName.Length())
1.52 + << aColumnName
1.53 + << aRowId
1.54 + << static_cast<TInt32>(aReadOnly)
1.55 + << static_cast <TInt32> (aDbName.Length())
1.56 + << aDbName;
1.57 + strm.CommitL();
1.58 + strm.Close();
1.59 + return ipcPrmBuf;
1.60 + }
1.61 +
1.62 +// Create an IPC stream, sending the IPC buffer containing the parameter values
1.63 +static MStreamBuf* CreateIpcStreamL(RSqlDbSession& aDbSession, const TDesC8& aIpcPrmBuf)
1.64 + {
1.65 + TIpcArgs ipcArgs;
1.66 + ipcArgs.Set(0, aIpcPrmBuf.Length());
1.67 + ipcArgs.Set(1, &aIpcPrmBuf);
1.68 + HIpcBuf* ipcBuf = HIpcBuf::NewL(aDbSession, ::MakeMsgCode(ESqlSrvDbBlobSource, ESqlSrvNoHandle, 0), ipcArgs);
1.69 + return ipcBuf;
1.70 + }
1.71 +
1.72 +// Used by TSqlBlob to calculate the appropriate block size to use for the next transfer of blob data
1.73 +static TInt CalculateBlockSize(TInt aRemainingDataSize, TInt aPreviousBlockSize, TBool aTimeThresholdBreached)
1.74 + {
1.75 + TInt blockSize = aPreviousBlockSize;
1.76 + if(aTimeThresholdBreached)
1.77 + {
1.78 + // The time threshold was breached using the previous block size
1.79 + // so we will reduce the block size by a factor of 2
1.80 + blockSize /= 2;
1.81 + if(blockSize <= KUseClientBufferThreshold)
1.82 + {
1.83 + // Just use the client-side IPC buffer size if things get to this stage
1.84 + blockSize = KIpcBufSize;
1.85 + }
1.86 + }
1.87 + return aRemainingDataSize <= blockSize ? aRemainingDataSize : blockSize;
1.88 + }
1.89 +
1.90 +// Retrieve the data in blocks
1.91 +static void DoReadInBlocksL(RSqlBlobReadStream& aStrm, TDes8& aDestBuffer, TInt aBlobSize)
1.92 + {
1.93 + TInt remainingDataSize = aBlobSize;
1.94 + TBool timeThresholdBreached = EFalse;
1.95 + TInt blockSize = KLargestBlockSize;
1.96 + TPtr8 ptr((TUint8*)aDestBuffer.Ptr(), aDestBuffer.MaxSize());
1.97 +
1.98 + while(remainingDataSize > 0)
1.99 + {
1.100 + // Calculate the block size to use for this iteration, based on
1.101 + // how much data is remaining and how fast the previous read was
1.102 + blockSize = CalculateBlockSize(remainingDataSize, blockSize, timeThresholdBreached);
1.103 +
1.104 + // Read the block of data, timing how long it takes
1.105 + TTime t1, t2;
1.106 + t1.HomeTime();
1.107 + aStrm.ReadL(ptr, blockSize);
1.108 + t2.HomeTime();
1.109 + TTimeIntervalMicroSeconds readTime = t2.MicroSecondsFrom(t1);
1.110 + timeThresholdBreached = (readTime.Int64() > KTimeThresholdInMicroSecs);
1.111 +
1.112 + // Update how much data is still to be read, and the buffer pointer
1.113 + remainingDataSize -= blockSize;
1.114 + __ASSERT_DEBUG(remainingDataSize >= 0, __SQLPANIC2(ESqlPanicInternalError));
1.115 + ptr.Set((TUint8*)(ptr.Ptr() + blockSize), 0, remainingDataSize);
1.116 + }
1.117 + aDestBuffer.SetLength(aBlobSize);
1.118 + }
1.119 +
1.120 +// Send the data in blocks
1.121 +static void DoWriteInBlocksL(RSqlBlobWriteStream& aStrm, const TDesC8& aData, TInt aDataSize)
1.122 + {
1.123 + TInt remainingDataSize = aDataSize;
1.124 + TBool timeThresholdBreached = EFalse;
1.125 + TInt blockSize = KLargestBlockSize;
1.126 +
1.127 + while(remainingDataSize > 0)
1.128 + {
1.129 + // Calculate the block size to use for this iteration, based on
1.130 + // how much data is remaining and how fast the previous write was
1.131 + blockSize = CalculateBlockSize(remainingDataSize, blockSize, timeThresholdBreached);
1.132 +
1.133 + // Write the block of data, timing how long it takes
1.134 + TTime t1, t2;
1.135 + t1.HomeTime();
1.136 + aStrm.WriteL(aData.Right(remainingDataSize), blockSize);
1.137 + t2.HomeTime();
1.138 + TTimeIntervalMicroSeconds writeTime = t2.MicroSecondsFrom(t1);
1.139 + timeThresholdBreached = (writeTime.Int64() > KTimeThresholdInMicroSecs);
1.140 +
1.141 + // Update how much data is still to be written
1.142 + remainingDataSize -= blockSize;
1.143 + __ASSERT_DEBUG(remainingDataSize >= 0, __SQLPANIC2(ESqlPanicInternalError));
1.144 + }
1.145 + aStrm.CommitL();
1.146 + }
1.147 +
1.148 +// The data is returned in a UTF-8 buffer that is allocated on the heap
1.149 +static HBufC8* ReadLC(RSqlDatabase& aDb,
1.150 + const TDesC& aTableName,
1.151 + const TDesC& aColumnName,
1.152 + TInt64 aRowId,
1.153 + const TDesC& aDbName)
1.154 + {
1.155 + RSqlBlobReadStream strm;
1.156 + CleanupClosePushL(strm);
1.157 + strm.OpenL(aDb, aTableName, aColumnName, aRowId, aDbName);
1.158 + TInt blobSize = strm.SizeL(); // size of the blob, in bytes
1.159 + HBufC8* buf = HBufC8::NewLC(blobSize);
1.160 + TPtr8 ptr = buf->Des();
1.161 + DoReadInBlocksL(strm, ptr, blobSize);
1.162 + CleanupStack::Pop(); // buf
1.163 + CleanupStack::PopAndDestroy(); // strm
1.164 + CleanupStack::PushL(buf);
1.165 + return buf;
1.166 + }
1.167 +
1.168 +// The data is returned in the UTF-8 buffer passed in
1.169 +static void ReadL(RSqlDatabase& aDb,
1.170 + const TDesC& aTableName,
1.171 + const TDesC& aColumnName,
1.172 + TDes8& aBuffer,
1.173 + TInt64 aRowId,
1.174 + const TDesC& aDbName)
1.175 + {
1.176 + RSqlBlobReadStream strm;
1.177 + CleanupClosePushL(strm);
1.178 + strm.OpenL(aDb, aTableName, aColumnName, aRowId, aDbName);
1.179 + TInt blobSize = strm.SizeL(); // size of the blob, in bytes
1.180 + if(blobSize > aBuffer.MaxSize())
1.181 + {
1.182 + __SQLLEAVE2(KErrOverflow);
1.183 + }
1.184 + DoReadInBlocksL(strm, aBuffer, blobSize);
1.185 + CleanupStack::PopAndDestroy(); // strm
1.186 + }
1.187 +
1.188 +// The data in the client-specified UTF-8 buffer is written
1.189 +static void WriteL(RSqlDatabase& aDb,
1.190 + const TDesC& aTableName,
1.191 + const TDesC& aColumnName,
1.192 + const TDesC8& aData,
1.193 + TInt64 aRowId,
1.194 + const TDesC& aDbName)
1.195 + {
1.196 + RSqlBlobWriteStream strm;
1.197 + CleanupClosePushL(strm);
1.198 + strm.OpenL(aDb, aTableName, aColumnName, aRowId, aDbName);
1.199 + TInt dataSize = aData.Size(); // size of the data, in bytes
1.200 + TInt blobSize = strm.SizeL(); // size of the blob, in bytes
1.201 + if(dataSize > blobSize)
1.202 + {
1.203 + __SQLLEAVE2(KErrEof);
1.204 + }
1.205 + if(dataSize > 0)
1.206 + {
1.207 + DoWriteInBlocksL(strm, aData, dataSize);
1.208 + }
1.209 + CleanupStack::PopAndDestroy(); // strm
1.210 + }
1.211 +
1.212 +////////////////////////////////////////////////////////////////////////////////
1.213 +
1.214 +/**
1.215 +Gives access to a blob as a read-only stream of bytes.
1.216 +
1.217 +@param aDb A connection to the database that contains the blob
1.218 +@param aTableName The name of the table that contains the blob
1.219 +@param aColumnName The name of the column that contains the blob
1.220 +@param aRowId The ROWID of the record that contains the blob,
1.221 + or KSqlLastInsertedRowId if the last inserted ROWID
1.222 + of the specified database connection is to be used
1.223 +@param aDbName The name of the attached database if the blob is
1.224 + contained in an attached database
1.225 +
1.226 +@leave KSqlErrGeneral, Invalid database connection or table name or column name
1.227 + or column type or ROWID or database name;
1.228 + KErrNoMemory, An out of memory condition occurred;
1.229 + KErrArgument, The ROWID is zero or negative or a UTF-16 to UTF-8 string conversion failed;
1.230 + KErrBadName, The table name, column name or database name has an invalid length;
1.231 + KErrPermissionDenied, The client does not have the required security capabilites for this operation;
1.232 + Note that the function may also leave with some other system wide errors or
1.233 + database specific errors categorised as ESqlDbError.
1.234 +
1.235 +@panic SqlDb 2 The database object is not yet created
1.236 +@panic SqlDb 3 Server failed to create a handle to the blob
1.237 +@panic SqlDb 4 In _DEBUG mode. Bad parameter value
1.238 +@panic SqlDb 7 In _DEBUG mode. NULL blob handle
1.239 +
1.240 +@capability None, if the aDb parameter represents a handle which operates on a non-secure database;
1.241 + RSqlSecurityPolicy::EReadPolicy or
1.242 + RSqlSecurityPolicy::ESchemaPolicy database policy type, if the blob belongs to a secure database;
1.243 +*/
1.244 +EXPORT_C void RSqlBlobReadStream::OpenL(RSqlDatabase& aDb, const TDesC& aTableName, const TDesC& aColumnName,
1.245 + TInt64 aRowId, const TDesC& aDbName)
1.246 + {
1.247 + 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));
1.248 + HBufC8* ipcPrmBuf = ::PrepareIpcParamBufLC(aTableName, aColumnName, aRowId, ETrue, aDbName);
1.249 + MStreamBuf* strm = ::CreateIpcStreamL(aDb.Impl().Session(), ipcPrmBuf->Des());
1.250 + Attach(strm);
1.251 + CleanupStack::PopAndDestroy(ipcPrmBuf);
1.252 + SQL_TRACE_BORDER(OstTraceExt2(TRACE_BORDER, RSQLBLOBREADSTREAM_OPENL_EXIT, "Exit;0x%x;RSqlBlobReadStream::OpenL;strm=0x%X", (TUint)this, (TUint)strm));
1.253 + }
1.254 +
1.255 +/**
1.256 +Returns the size of the blob object, in bytes.
1.257 +
1.258 +@return The size of the blob object, in bytes
1.259 +
1.260 +@leave One of the system-wide error codes
1.261 +
1.262 +@panic SqlDb 2 The stream buffer is NULL
1.263 +
1.264 +@capability None
1.265 +*/
1.266 +EXPORT_C TInt RSqlBlobReadStream::SizeL()
1.267 + {
1.268 + SQL_TRACE_BORDER(OstTrace1(TRACE_BORDER, RSQLBLOBREADSTREAM_SIZEL_ENTRY, "Entry;0x%X;RSqlBlobReadStream::SizeL;", (TUint)this));
1.269 + MStreamBuf* src = Source();
1.270 + __ASSERT_ALWAYS(src != NULL, __SQLPANIC(ESqlPanicInvalidObj));
1.271 + TInt size = src->SizeL();
1.272 + SQL_TRACE_BORDER(OstTraceExt2(TRACE_BORDER, RSQLBLOBREADSTREAM_SIZEL_EXIT, "Exit;0x%X;RSqlBlobReadStream::SizeL;size=%d", (TUint)this, size));
1.273 + return size;
1.274 + }
1.275 +
1.276 +/**
1.277 +Gives access to a blob as a writeable stream of bytes.
1.278 +
1.279 +@param aDb A connection to the database that contains the blob
1.280 +@param aTableName The name of the table that contains the blob
1.281 +@param aColumnName The name of the column that contains the blob
1.282 +@param aRowId The ROWID of the record that contains the blob,
1.283 + or KSqlLastInsertedRowId if the last inserted ROWID
1.284 + of the specified database connection is to be used
1.285 +@param aDbName The name of the attached database if the blob is
1.286 + contained in an attached database
1.287 +
1.288 +@leave KSqlErrGeneral, Invalid database connection or table name or column name or column
1.289 + type or ROWID or database name, or the specified column is indexed;
1.290 + KErrNoMemory, An out of memory condition occurred;
1.291 + KErrArgument, The ROWID is zero or negative or a UTF-16 to UTF-8 string conversion failed;
1.292 + KErrBadName, The table name, column name or database name has an invalid length;
1.293 + KErrPermissionDenied, The client does not have the required security capabilites for this operation;
1.294 + Note that the function may also leave with some other system wide errors or
1.295 + database specific errors categorised as ESqlDbError.
1.296 +
1.297 +@panic SqlDb 2 The database object is not yet created
1.298 +@panic SqlDb 3 Server failed to create a handle to the blob
1.299 +@panic SqlDb 4 In _DEBUG mode. Bad parameter value
1.300 +@panic SqlDb 7 In _DEBUG mode. NULL blob handle
1.301 +
1.302 +@capability None, if the aDb parameter represents a handle which operates on a non-secure database;
1.303 + RSqlSecurityPolicy::EWritePolicy or
1.304 + RSqlSecurityPolicy::ESchemaPolicy database policy type, if the blob belongs to a secure database;
1.305 +*/
1.306 +EXPORT_C void RSqlBlobWriteStream::OpenL(RSqlDatabase& aDb, const TDesC& aTableName, const TDesC& aColumnName,
1.307 + TInt64 aRowId, const TDesC& aDbName)
1.308 + {
1.309 + 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));
1.310 + HBufC8* ipcPrmBuf = ::PrepareIpcParamBufLC(aTableName, aColumnName, aRowId, EFalse, aDbName);
1.311 + MStreamBuf* strm = ::CreateIpcStreamL(aDb.Impl().Session(), ipcPrmBuf->Des());
1.312 + Attach(strm);
1.313 + CleanupStack::PopAndDestroy(ipcPrmBuf);
1.314 + SQL_TRACE_BORDER(OstTraceExt2(TRACE_BORDER, RSQLBLOBWRITESTREAM_OPENL_EXIT, "Exit;0x%x;RSqlBlobWriteStream::OpenL;strm=0x%X", (TUint)this, (TUint)strm));
1.315 + }
1.316 +
1.317 +/**
1.318 +Returns the size of the blob object, in bytes.
1.319 +
1.320 +@return The size of the blob object, in bytes
1.321 +
1.322 +@leave One of the system-wide error codes
1.323 +
1.324 +@panic SqlDb 2 The stream buffer is NULL
1.325 +
1.326 +@capability None
1.327 +*/
1.328 +EXPORT_C TInt RSqlBlobWriteStream::SizeL()
1.329 + {
1.330 + SQL_TRACE_BORDER(OstTrace1(TRACE_BORDER, RSQLBLOBWRITESTREAM_SIZEL_ENTRY, "Entry;0x%X;RSqlBlobWriteStream::SizeL;", (TUint)this));
1.331 + MStreamBuf* sink = Sink();
1.332 + __ASSERT_ALWAYS(sink != NULL, __SQLPANIC(ESqlPanicInvalidObj));
1.333 + TInt size = sink->SizeL();
1.334 + SQL_TRACE_BORDER(OstTraceExt2(TRACE_BORDER, RSQLBLOBWRITESTREAM_SIZEL_EXIT, "Exit;0x%X;RSqlBlobWriteStream::SizeL;size=%d", (TUint)this, size));
1.335 + return size;
1.336 + }
1.337 +
1.338 +/**
1.339 +Retrieves the entire content of a blob and returns it to the client
1.340 +in a heap allocated buffer which has been placed on the cleanup stack.
1.341 +It is the responsibility of the client to destroy the returned buffer.
1.342 +
1.343 +@param aDb A connection to the database that contains the blob
1.344 +@param aTableName The name of the table that contains the blob
1.345 +@param aColumnName The name of the column that contains the blob
1.346 +@param aRowId The ROWID of the record that contains the blob,
1.347 + or KSqlLastInsertedRowId if the last inserted ROWID
1.348 + of the specified database connection is to be used
1.349 +@param aDbName The name of the attached database if the blob is
1.350 + contained in an attached database
1.351 +
1.352 +@leave KSqlErrGeneral, Invalid database connection or table name or column name
1.353 + or column type or ROWID or database name;
1.354 + KErrNoMemory, An out of memory condition occurred;
1.355 + KErrArgument, The ROWID is zero or negative or a UTF-16 to UTF-8 string conversion failed;
1.356 + KErrBadName, The table name, column name or database name has an invalid length;
1.357 + KErrPermissionDenied, The client does not have the required security capabilites for this operation;
1.358 + Note that the function may also leave with some other system wide errors or
1.359 + database specific errors categorised as ESqlDbError.
1.360 +
1.361 +@panic SqlDb 2 The database object is not yet created
1.362 +@panic SqlDb 3 Server failed to create a handle to the blob
1.363 +@panic SqlDb 4 In _DEBUG mode. Bad parameter value
1.364 +@panic SqlDb 7 In _DEBUG mode. NULL blob handle or miscalculation of remaining data to be read
1.365 +
1.366 +@capability None, if the aDb parameter represents a handle which operates on a non-secure database;
1.367 + RSqlSecurityPolicy::EReadPolicy or
1.368 + RSqlSecurityPolicy::ESchemaPolicy database policy type, if the blob belongs to a secure database;
1.369 +*/
1.370 +EXPORT_C HBufC8* TSqlBlob::GetLC(RSqlDatabase& aDb,
1.371 + const TDesC& aTableName,
1.372 + const TDesC& aColumnName,
1.373 + TInt64 aRowId,
1.374 + const TDesC& aDbName)
1.375 + {
1.376 + 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));
1.377 + HBufC8* res = ReadLC(aDb, aTableName, aColumnName, aRowId, aDbName);
1.378 + SQL_TRACE_BORDER(OstTraceExt2(TRACE_BORDER, TSQLBLOB_GETLC_EXIT, "Exit;0;TSqlBlob::GetLC;res=0x%X;res->Size()=%d", (TUint)res, res->Des().Size()));
1.379 + return res;
1.380 + }
1.381 +
1.382 +/**
1.383 +Retrieves the entire content of a blob into a client specified buffer.
1.384 +
1.385 +@param aDb A connection to the database that contains the blob
1.386 +@param aTableName The name of the table that contains the blob
1.387 +@param aColumnName The name of the column that contains the blob
1.388 +@param aRowId The ROWID of the record that contains the blob,
1.389 + or KSqlLastInsertedRowId if the last inserted ROWID
1.390 + of the specified database connection is to be used
1.391 +@param aDbName The name of the attached database if the blob is
1.392 + contained in an attached database
1.393 +
1.394 +@return KSqlErrGeneral, Invalid database connection or table name or column name
1.395 + or column type or ROWID or database name;
1.396 + KErrNoMemory, An out of memory condition occurred;
1.397 + KErrArgument, The ROWID is zero or negative or a UTF-16 to UTF-8 string conversion failed;
1.398 + KErrOverflow, The specified buffer is not big enough to hold the entire blob;
1.399 + KErrBadName, The table name, column name or database name has an invalid length;
1.400 + KErrPermissionDenied, The client does not have the required security capabilites for this operation;
1.401 + Note that the function may also leave with some other system wide errors or
1.402 + database specific errors categorised as ESqlDbError.
1.403 +
1.404 +@panic SqlDb 2 The database object is not yet created
1.405 +@panic SqlDb 3 Server failed to create a handle to the blob
1.406 +@panic SqlDb 4 In _DEBUG mode. Bad parameter value
1.407 +@panic SqlDb 7 In _DEBUG mode. NULL blob handle or miscalculation of remaining data to be read
1.408 +
1.409 +@capability None, if the aDb parameter represents a handle which operates on a non-secure database;
1.410 + RSqlSecurityPolicy::EReadPolicy or
1.411 + RSqlSecurityPolicy::ESchemaPolicy database policy type, if the blob belongs to a secure database;
1.412 +*/
1.413 +EXPORT_C TInt TSqlBlob::Get(RSqlDatabase& aDb,
1.414 + const TDesC& aTableName,
1.415 + const TDesC& aColumnName,
1.416 + TDes8& aBuffer,
1.417 + TInt64 aRowId,
1.418 + const TDesC& aDbName)
1.419 + {
1.420 + 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));
1.421 + TRAPD(err, ReadL(aDb, aTableName, aColumnName, aBuffer, aRowId, aDbName));
1.422 + 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()));
1.423 + return err;
1.424 + }
1.425 +
1.426 +/**
1.427 +Writes the data in a client specified buffer to a blob.
1.428 +
1.429 +@param aDb A connection to the database that contains the blob
1.430 +@param aTableName The name of the table that contains the blob
1.431 +@param aColumnName The name of the column that contains the blob
1.432 +@param aRowId The ROWID of the record that contains the blob,
1.433 + or KSqlLastInsertedRowId if the last inserted ROWID
1.434 + of the specified database connection is to be used
1.435 +@param aDbName The name of the attached database if the blob is
1.436 + contained in an attached database
1.437 +
1.438 +@leave KSqlErrGeneral, Invalid database connection or table name or column name or column
1.439 + type or ROWID or database name, or the specified column is indexed;
1.440 + KErrNoMemory, An out of memory condition occurred;
1.441 + KErrArgument, The ROWID is zero or negative or a UTF-16 to UTF-8 string conversion failed;
1.442 + KErrEof, The data in the specified buffer is larger in size than the blob object;
1.443 + KErrBadName, The table name, column name or database name has an invalid length;
1.444 + KErrPermissionDenied, The client does not have the required security capabilites for this operation;
1.445 + Note that the function may also leave with some other system wide errors or
1.446 + database specific errors categorised as ESqlDbError.
1.447 +
1.448 +@panic SqlDb 2 The database object is not yet created
1.449 +@panic SqlDb 3 Server failed to create a handle to the blob
1.450 +@panic SqlDb 4 In _DEBUG mode. Bad parameter value
1.451 +@panic SqlDb 7 In _DEBUG mode. NULL blob handle or miscalculation of remaining data to be written
1.452 +
1.453 +@capability None, if the aDb parameter represents a handle which operates on a non-secure database;
1.454 + RSqlSecurityPolicy::EWritePolicy or
1.455 + RSqlSecurityPolicy::ESchemaPolicy database policy type, if the blob belongs to a secure database;
1.456 +*/
1.457 +EXPORT_C void TSqlBlob::SetL(RSqlDatabase& aDb,
1.458 + const TDesC& aTableName,
1.459 + const TDesC& aColumnName,
1.460 + const TDesC8& aData,
1.461 + TInt64 aRowId,
1.462 + const TDesC& aDbName)
1.463 + {
1.464 + 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));
1.465 + 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()));
1.466 + WriteL(aDb, aTableName, aColumnName, aData, aRowId, aDbName);
1.467 + SQL_TRACE_BORDER(OstTrace0(TRACE_BORDER, TSQLBLOB_SET_EXIT, "Exit;0;TSqlBlob::Set"));
1.468 + }
1.469 +