1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
1 // Copyright (c) 2008-2010 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 "SqlPanic.h" |
18 #include "SqlAssert.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" |
21 |
26 |
22 // The maximum time (100 milliseconds) that a block of data is allowed to take to be read/written by TSqlBlob. |
27 // 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 |
28 // If the time taken is longer than this value then the next block size used will be less |
24 const TInt KTimeThresholdInMicroSecs = 100000; |
29 const TInt KTimeThresholdInMicroSecs = 100000; |
25 // The largest block size used by TSqlBlob is 32Kb |
30 // The largest block size used by TSqlBlob is 32Kb |
101 TTimeIntervalMicroSeconds readTime = t2.MicroSecondsFrom(t1); |
106 TTimeIntervalMicroSeconds readTime = t2.MicroSecondsFrom(t1); |
102 timeThresholdBreached = (readTime.Int64() > KTimeThresholdInMicroSecs); |
107 timeThresholdBreached = (readTime.Int64() > KTimeThresholdInMicroSecs); |
103 |
108 |
104 // Update how much data is still to be read, and the buffer pointer |
109 // Update how much data is still to be read, and the buffer pointer |
105 remainingDataSize -= blockSize; |
110 remainingDataSize -= blockSize; |
106 __SQLASSERT(remainingDataSize >= 0, ESqlPanicInternalError); |
111 __ASSERT_DEBUG(remainingDataSize >= 0, __SQLPANIC2(ESqlPanicInternalError)); |
107 ptr.Set((TUint8*)(ptr.Ptr() + blockSize), 0, remainingDataSize); |
112 ptr.Set((TUint8*)(ptr.Ptr() + blockSize), 0, remainingDataSize); |
108 } |
113 } |
109 aDestBuffer.SetLength(aBlobSize); |
114 aDestBuffer.SetLength(aBlobSize); |
110 } |
115 } |
111 |
116 |
130 TTimeIntervalMicroSeconds writeTime = t2.MicroSecondsFrom(t1); |
135 TTimeIntervalMicroSeconds writeTime = t2.MicroSecondsFrom(t1); |
131 timeThresholdBreached = (writeTime.Int64() > KTimeThresholdInMicroSecs); |
136 timeThresholdBreached = (writeTime.Int64() > KTimeThresholdInMicroSecs); |
132 |
137 |
133 // Update how much data is still to be written |
138 // Update how much data is still to be written |
134 remainingDataSize -= blockSize; |
139 remainingDataSize -= blockSize; |
135 __SQLASSERT(remainingDataSize >= 0, ESqlPanicInternalError); |
140 __ASSERT_DEBUG(remainingDataSize >= 0, __SQLPANIC2(ESqlPanicInternalError)); |
136 } |
141 } |
137 aStrm.CommitL(); |
142 aStrm.CommitL(); |
138 } |
143 } |
139 |
144 |
140 // The data is returned in a UTF-8 buffer that is allocated on the heap |
145 // The data is returned in a UTF-8 buffer that is allocated on the heap |
169 CleanupClosePushL(strm); |
174 CleanupClosePushL(strm); |
170 strm.OpenL(aDb, aTableName, aColumnName, aRowId, aDbName); |
175 strm.OpenL(aDb, aTableName, aColumnName, aRowId, aDbName); |
171 TInt blobSize = strm.SizeL(); // size of the blob, in bytes |
176 TInt blobSize = strm.SizeL(); // size of the blob, in bytes |
172 if(blobSize > aBuffer.MaxSize()) |
177 if(blobSize > aBuffer.MaxSize()) |
173 { |
178 { |
174 __SQLLEAVE(KErrOverflow); |
179 __SQLLEAVE2(KErrOverflow); |
175 } |
180 } |
176 DoReadInBlocksL(strm, aBuffer, blobSize); |
181 DoReadInBlocksL(strm, aBuffer, blobSize); |
177 CleanupStack::PopAndDestroy(); // strm |
182 CleanupStack::PopAndDestroy(); // strm |
178 } |
183 } |
179 |
184 |
190 strm.OpenL(aDb, aTableName, aColumnName, aRowId, aDbName); |
195 strm.OpenL(aDb, aTableName, aColumnName, aRowId, aDbName); |
191 TInt dataSize = aData.Size(); // size of the data, in bytes |
196 TInt dataSize = aData.Size(); // size of the data, in bytes |
192 TInt blobSize = strm.SizeL(); // size of the blob, in bytes |
197 TInt blobSize = strm.SizeL(); // size of the blob, in bytes |
193 if(dataSize > blobSize) |
198 if(dataSize > blobSize) |
194 { |
199 { |
195 __SQLLEAVE(KErrEof); |
200 __SQLLEAVE2(KErrEof); |
196 } |
201 } |
197 if(dataSize > 0) |
202 if(dataSize > 0) |
198 { |
203 { |
199 DoWriteInBlocksL(strm, aData, dataSize); |
204 DoWriteInBlocksL(strm, aData, dataSize); |
200 } |
205 } |
234 RSqlSecurityPolicy::ESchemaPolicy database policy type, if the blob belongs to a secure database; |
239 RSqlSecurityPolicy::ESchemaPolicy database policy type, if the blob belongs to a secure database; |
235 */ |
240 */ |
236 EXPORT_C void RSqlBlobReadStream::OpenL(RSqlDatabase& aDb, const TDesC& aTableName, const TDesC& aColumnName, |
241 EXPORT_C void RSqlBlobReadStream::OpenL(RSqlDatabase& aDb, const TDesC& aTableName, const TDesC& aColumnName, |
237 TInt64 aRowId, const TDesC& aDbName) |
242 TInt64 aRowId, const TDesC& aDbName) |
238 { |
243 { |
239 SQLUTRACE_PROFILER(this); |
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)); |
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); |
245 HBufC8* ipcPrmBuf = ::PrepareIpcParamBufLC(aTableName, aColumnName, aRowId, ETrue, aDbName); |
244 MStreamBuf* strm = ::CreateIpcStreamL(aDb.Impl().Session(), ipcPrmBuf->Des()); |
246 MStreamBuf* strm = ::CreateIpcStreamL(aDb.Impl().Session(), ipcPrmBuf->Des()); |
245 Attach(strm); |
247 Attach(strm); |
246 CleanupStack::PopAndDestroy(ipcPrmBuf); |
248 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)); |
247 } |
250 } |
248 |
251 |
249 /** |
252 /** |
250 Returns the size of the blob object, in bytes. |
253 Returns the size of the blob object, in bytes. |
251 |
254 |
257 |
260 |
258 @capability None |
261 @capability None |
259 */ |
262 */ |
260 EXPORT_C TInt RSqlBlobReadStream::SizeL() |
263 EXPORT_C TInt RSqlBlobReadStream::SizeL() |
261 { |
264 { |
262 SQLUTRACE_PROFILER(this); |
265 SQL_TRACE_BORDER(OstTrace1(TRACE_BORDER, RSQLBLOBREADSTREAM_SIZEL_ENTRY, "Entry;0x%X;RSqlBlobReadStream::SizeL;", (TUint)this)); |
263 |
|
264 MStreamBuf* src = Source(); |
266 MStreamBuf* src = Source(); |
265 __SQLASSERT_ALWAYS(src != NULL, ESqlPanicInvalidObj); |
267 __ASSERT_ALWAYS(src != NULL, __SQLPANIC(ESqlPanicInvalidObj)); |
266 return src->SizeL(); |
268 TInt size = 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; |
267 } |
271 } |
268 |
272 |
269 /** |
273 /** |
270 Gives access to a blob as a writeable stream of bytes. |
274 Gives access to a blob as a writeable stream of bytes. |
271 |
275 |
297 RSqlSecurityPolicy::ESchemaPolicy database policy type, if the blob belongs to a secure database; |
301 RSqlSecurityPolicy::ESchemaPolicy database policy type, if the blob belongs to a secure database; |
298 */ |
302 */ |
299 EXPORT_C void RSqlBlobWriteStream::OpenL(RSqlDatabase& aDb, const TDesC& aTableName, const TDesC& aColumnName, |
303 EXPORT_C void RSqlBlobWriteStream::OpenL(RSqlDatabase& aDb, const TDesC& aTableName, const TDesC& aColumnName, |
300 TInt64 aRowId, const TDesC& aDbName) |
304 TInt64 aRowId, const TDesC& aDbName) |
301 { |
305 { |
302 SQLUTRACE_PROFILER(this); |
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)); |
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 HBufC8* ipcPrmBuf = ::PrepareIpcParamBufLC(aTableName, aColumnName, aRowId, EFalse, aDbName); |
307 MStreamBuf* strm = ::CreateIpcStreamL(aDb.Impl().Session(), ipcPrmBuf->Des()); |
308 MStreamBuf* strm = ::CreateIpcStreamL(aDb.Impl().Session(), ipcPrmBuf->Des()); |
308 Attach(strm); |
309 Attach(strm); |
309 CleanupStack::PopAndDestroy(ipcPrmBuf); |
310 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)); |
310 } |
312 } |
311 |
313 |
312 /** |
314 /** |
313 Returns the size of the blob object, in bytes. |
315 Returns the size of the blob object, in bytes. |
314 |
316 |
320 |
322 |
321 @capability None |
323 @capability None |
322 */ |
324 */ |
323 EXPORT_C TInt RSqlBlobWriteStream::SizeL() |
325 EXPORT_C TInt RSqlBlobWriteStream::SizeL() |
324 { |
326 { |
325 SQLUTRACE_PROFILER(this); |
327 SQL_TRACE_BORDER(OstTrace1(TRACE_BORDER, RSQLBLOBWRITESTREAM_SIZEL_ENTRY, "Entry;0x%X;RSqlBlobWriteStream::SizeL;", (TUint)this)); |
326 |
|
327 MStreamBuf* sink = Sink(); |
328 MStreamBuf* sink = Sink(); |
328 __SQLASSERT_ALWAYS(sink != NULL, ESqlPanicInvalidObj); |
329 __ASSERT_ALWAYS(sink != NULL, __SQLPANIC(ESqlPanicInvalidObj)); |
329 return sink->SizeL(); |
330 TInt size = 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; |
330 } |
333 } |
331 |
334 |
332 /** |
335 /** |
333 Retrieves the entire content of a blob and returns it to the client |
336 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. |
337 in a heap allocated buffer which has been placed on the cleanup stack. |
365 const TDesC& aTableName, |
368 const TDesC& aTableName, |
366 const TDesC& aColumnName, |
369 const TDesC& aColumnName, |
367 TInt64 aRowId, |
370 TInt64 aRowId, |
368 const TDesC& aDbName) |
371 const TDesC& aDbName) |
369 { |
372 { |
370 SQLUTRACE_PROFILER(0); |
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)); |
371 SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KRSqlBlobParam16, &aDb, &aTableName, |
374 HBufC8* res = ReadLC(aDb, aTableName, aColumnName, aRowId, aDbName); |
372 &aColumnName, aRowId, &aDbName)); |
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())); |
373 |
376 return res; |
374 return ReadLC(aDb, aTableName, aColumnName, aRowId, aDbName); |
|
375 } |
377 } |
376 |
378 |
377 /** |
379 /** |
378 Retrieves the entire content of a blob into a client specified buffer. |
380 Retrieves the entire content of a blob into a client specified buffer. |
379 |
381 |
410 const TDesC& aColumnName, |
412 const TDesC& aColumnName, |
411 TDes8& aBuffer, |
413 TDes8& aBuffer, |
412 TInt64 aRowId, |
414 TInt64 aRowId, |
413 const TDesC& aDbName) |
415 const TDesC& aDbName) |
414 { |
416 { |
415 SQLUTRACE_PROFILER(0); |
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)); |
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)); |
418 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 SQLUTRACE_PROFILER(0); |
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)); |
462 SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KRSqlBlobParam16, &aDb, &aTableName, |
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())); |
463 &aColumnName, aRowId, &aDbName)); |
|
464 |
|
465 WriteL(aDb, aTableName, aColumnName, aData, aRowId, aDbName); |
463 WriteL(aDb, aTableName, aColumnName, aData, aRowId, aDbName); |
466 } |
464 SQL_TRACE_BORDER(OstTrace0(TRACE_BORDER, TSQLBLOB_SET_EXIT, "Exit;0;TSqlBlob::Set")); |
467 |
465 } |
|
466 |