RSqlBlobReadStream Class Reference

#include <sqldb.h>

Link against: sqldb.lib

class RSqlBlobReadStream : public RReadStream

Inherits from

  • RSqlBlobReadStream

    Detailed Description

    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()

    Member Function Documentation

    OpenL ( RSqlDatabase &, const TDesC &, const TDesC &, TInt64, const TDesC & )

    IMPORT_C voidOpenL(RSqlDatabase &aDb,
    const TDesC &aTableName,
    const TDesC &aColumnName,
    TInt64aRowId =  KSqlLastInsertedRowId ,
    const TDesC &aDbName =  KNullDesC
    )

    Gives access to a blob as a read-only stream of bytes.

    leave
    KSqlErrGeneral, Invalid database connection or table name or column name or column type or ROWID or database name; KErrNoMemory, An out of memory condition occurred; KErrArgument, The ROWID is zero or negative or a UTF-16 to UTF-8 string conversion failed; KErrBadName, The table name, column name or database name has an invalid length; KErrPermissionDenied, The client does not have the required security capabilites for this operation; Note that the function may also leave with some other system wide errors or database specific errors categorised as ESqlDbError.
    panic
    SqlDb 2 The database object is not yet created
    panic
    SqlDb 3 Server failed to create a handle to the blob
    panic
    SqlDb 4 In _DEBUG mode. Bad parameter value
    panic
    SqlDb 7 In _DEBUG mode. NULL blob handle
    capability
    None, if the aDb parameter represents a handle which operates on a non-secure database; RSqlSecurityPolicy::EReadPolicy or RSqlSecurityPolicy::ESchemaPolicy database policy type, if the blob belongs to a secure database;
    ParameterDescription
    aDbA connection to the database that contains the blob
    aTableNameThe name of the table that contains the blob
    aColumnNameThe name of the column that contains the blob
    aRowIdThe ROWID of the record that contains the blob, or KSqlLastInsertedRowId if the last inserted ROWID of the specified database connection is to be used
    aDbNameThe name of the attached database if the blob is contained in an attached database

    SizeL ( )

    IMPORT_C TIntSizeL()

    Returns the size of the blob object, in bytes.

    leave
    One of the system-wide error codes
    panic
    SqlDb 2 The stream buffer is NULL
    capability
    None

    Returns: The size of the blob object, in bytes