#include <sqldb.h>
class RSqlBlobReadStream : public RReadStream |
Public Member Functions | |
---|---|
IMPORT_C void | OpenL(RSqlDatabase &, const TDesC &, const TDesC &, TInt64, const TDesC &) |
IMPORT_C TInt | SizeL() |
A direct handle to a blob, used for reading the content of the blob via a streaming interface.
The target blob is identified using the relevant database connection, table name, column name and ROWID of the record to which the blob belongs (also the attached database name if the blob is contained in an attached database).
A blob in this context refers to the content of a BLOB or TEXT column, and a read handle can be opened on both types of column. For TEXT columns it is important to note that no conversions are performed on data retrieved using this class - the data is returned as a stream of bytes.
The class derives from RReadStream and provides all of its streaming methods. The SizeL() method can be used to check the total size of the blob, in bytes.
It is strongly recommended to use this class for reading the content of large blobs because it significantly reduces the amount of RAM that is used when compared to using the RSqlColumnReadStream, RSqlStatement::ColumnBinary(L) or RSqlStatement::ColumnText(L) APIs.
Specifically, it is recommended to use this class for blobs over 2Mb in size. Indeed, in some circumstances where very large blobs are in use it may be impossible to read the blob content using the legacy APIs (due to the server's finite RAM capacity), and this class may provide the only way to access the data.
The following code illustrates typical use cases of this class:
CASE 1 - reading large blob data from the last inserted record.
RSqlDatabase db; CleanupClosePushL(db); <open/create "db" object>; RSqlBlobReadStream rdStrm; CleanupClosePushL(rdStrm); rdStrm.OpenL(db, <table_name>, <column_name>); HBufC8* buffer = HBufC8::NewLC(KBlockSize); TPtr8 bufPtr(buffer->Des()); TInt size = rdStrm.SizeL(); while(size) { TInt bytesToRead = (size >= KBlockSize) ? KBlockSize : size ; rdStrm.ReadL(bufPtr, bytesToRead); // read the next block of data <do something with the block of data> size =- bytesToRead; } CleanupStack::PopAndDestroy(3); // buffer, rdStrm, db
CASE 2 - reading large blob data from a selection of records.
RSqlDatabase db; CleanupClosePushL(db); <open/create "db" object>; RSqlStatement stmt; CleanupClosePushL(stmt); <prepare "stmt" object to SELECT the ROWIDs of a collection of blob objects>; TInt rc = 0; while((rc = stmt.Next()) == KSqlAtRow) { TInt64 rowid = stmt.ColumnInt64(0); RSqlBlobReadStream rdStrm; CleanupClosePushL(rdStrm); rdStrm.OpenL(db, <table_name>, <column_name>, rowid); HBufC8* buffer = HBufC8::NewLC(KBlockSize); TPtr8 bufPtr(buffer->Des()); TInt size = rdStrm.SizeL(); while(size) { TInt bytesToRead = (size >= KBlockSize) ? KBlockSize : size ; rdStrm.ReadL(bufPtr, bytesToRead); // read the next block of data <do something with the block of data> size =- bytesToRead; } CleanupStack::PopAndDestroy(2); // buffer, rdStrm } CleanupStack::PopAndDestroy(2); // stmt, db
See also: RSqlBlobWriteStream RSqlDatabase::LastInsertedRowId()
IMPORT_C void | OpenL | ( | RSqlDatabase & | aDb, |
const TDesC & | aTableName, | |||
const TDesC & | aColumnName, | |||
TInt64 | aRowId = KSqlLastInsertedRowId , | |||
const TDesC & | aDbName = KNullDesC | |||
) |
Gives access to a blob as a read-only stream of bytes.
Parameter | Description |
---|---|
aDb | A connection to the database that contains the blob |
aTableName | The name of the table that contains the blob |
aColumnName | The name of the column that contains the blob |
aRowId | The ROWID of the record that contains the blob, or KSqlLastInsertedRowId if the last inserted ROWID of the specified database connection is to be used |
aDbName | The name of the attached database if the blob is contained in an attached database |
IMPORT_C TInt | SizeL | ( | ) |
Returns the size of the blob object, in bytes.
Returns: The size of the blob object, in bytes