Reading to a Data Stream

This tutorial describes how to copy data from a database into a data stream.

Introduction

You can read data from the table into a data stream in one chunk or in bits as desired.

Basic procedure

The high level steps to read the data into a data stream are shown here:

  1. Configure your SQL statement and data stream.

  2. Read data to a stream.

  3. Clean up.

Detailed steps

To read the data into a data stream, do the following:

Configure your SQL statement and data stream

  1. As a first step instantiate an object of the RSqlStatement and RSqlColumnReadStream class. Also declare the variables as required.

             
              
             
             RSqlStatement myStatement;
    TInt err;
    TInt myColumnIndex;
    RSqlColumnReadStream myStream;
            
  2. Clean up the stack.

             
              
             
             CleanupClosePushL(myStream);
            

Read data to a stream

  1. Open the stream for read and associate the data with it.

             
              
             
             User::LeaveIfError(myStream.ColumnBinary(myStatement,myColumnIndex));
            
  2. Determine the column size.

             
              
             
             TInt size = myStatement.ColumnSize(myColumnIndex);
            
  3. Instantiate an object of the RBuf class. Create a buffer of the size of the column. Then read the data into the buffer.

             
              
             
             RBuf buf;
            buf.CreateL(size);
            CleanupClosePushL(buf);
            myStream.ReadL(buf,size);
            
  4. Close the buffer.

             
              
             
             CleanupStack::PopAndDestroy();
            

Clean up

Close the stream.

       
        
       
       CleanupStack::PopAndDestroy();
      

See also

Querying a Database

Inserting a Row into a Table

Deleting Rows from a Table

Reading to a Buffer

Reading to Memory

Reading to a Data Stream - This document

Writing to a Data Stream

Performing Scalar Queries