Reading to a Buffer

This tutorial describes how to read the data from the table into a buffer.

Introduction

This query allows you to retrieve the data in a field. You can retrieve one entry or multiple entries in the same column by executing the query in a loop.

Basic procedure

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

  1. Configure the SQL statement.

  2. Allocate memory and copy data.

  3. Deallocate memory.

Detailed steps

The steps to read data to a buffer are as follows:

Configure the SQL statement

Instantiate an RSqlStatement object and declare the variables as required.

       
        
       
       RSqlStatement myStatement;
TInt err;
      

Allocate memory and copy data

To retrieve all the entries, use a loop. The steps to be performed within the loop are as described below:

  1. Instantiate an object of the RBuf class.

             
              
             
             while((err = myStatement.Next()) == KSqlAtRow)
        {
        RBuf myBuffer;
            
  2. Allocate enough memory to hold the column data using the CreateL() function as shown below.

             
              
             
             err = myBuffer.CreateL(myStatement.ColumnSize(columnIndex));
            
  3. Copy the data from the table into the buffer using RSqlStatement::ColumnBinary(TInt,TDes8 &)const function.

             
              
             
             err = myStatement.ColumnBinary(myColumnIndex,myBuffer);
        ...
        // process data
            

Deallocate memory

Deallocate the memory assigned to the RBuf object.

       
        
       
       myBuffer.Close();
    }