Writing from a Data Stream

This tutorial describes how to write data from a data stream to a database.

Introduction

This is useful when populating your database with the results of some other operation.

Basic procedure

The high level steps to write from a data stream to a database table are shown here:

  1. Instantiate the necessary objects.

  2. Write data into the table.

  3. Commit the stream.

Writing from a data stream into a table

The process of writing data from a data stream into a table can be explained as follows:

Instantiate the necessary objects

  1. Instantiate an object of the RSqlStatement and RSqlParamWriteStream class. Also declare the variables as shown.

             
              
             
             RSqlStatement myStatement;
    TInt err;
    TInt myParameterIndex;
    RSqlParamWriteStream myStream;
    RBuf buf;
            
  2. Clean up the stack.

             
              
             
             CleanupClosePushL(myStream);
            

Write data into the table

  1. Obtain access to the data as a stream of characters.

             
              
             
             User::LeaveIfErrormyStream.BindTextL(myStatement,myParameterIndex));
            
  2. Write the buffer.

             
              
             
             myStream.WriteL(buf);
            

Commit the stream

Commit the stream. This ensures that the streamed data is written into the table and cannot be rolled back.

       
        
       
       myStream.CommitL();