Reading to Memory

This tutorial describes how to copy data from the table to a memory location.

Introduction

You can avoid making a local copy of the data by directly writing the retrieved data into a memory location. This can be achieved by copying to an object of the TPtrC class. For more details on copying data to a buffer see Reading to a Buffer.

Basic procedure

The high level steps to copy the data retrieved from a table to a memory location are shown below:

  1. Configure your SQL statement.

  2. Copy to memory.

Detailed steps

Configure your SQL statement

Instantiate an object of the RSqlStatement class and declare the required variables as shown.

RSqlStatement myStatement;
TInt err;

Copy to memory

To retrieve all the entries, use a loop.

1. Instantiate an object of the TPtrc class. This object may be used to reference constant strings or data.

...
while((err = myStatement.Next()) == KSqlAtRow)
    	{
    	TPtrC myData;
 		TInt err;
	

2 Read the data into the specified memory location..

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