Inserting Data
Similarly, when inserting data, the entire value must fit in memory at one time. For example, using RWDBTBuffer we would write:
 
RWDBOSql sql("insert into mytable values(:ph0, :ph1)");
RWDBTBuffer<long> id(1);
RWDBTBuffer<RWDBBlob> image(1);
populateBuffers(id, image, 1);
sql << id << image;
sql.execute(aConnection);
When RWDBOSql::execute(..) is called, one row of data is inserted into the table. The data is read from the memory associated with the RWDBTBuffer instances.
The following diagram illustrates this operation:
Figure 10 – Inserting data without using a data callback class
Once again, the amount of memory used can be limited by supplying a data callback class in place of the RWDBTBuffer instances to send the data.
 
RWDBOSql sql("insert into mytable values(:ph0, :ph1)");
RWDBTBuffer<long> id(1);
MyDataCallback image(1);
populateBuffer(id, 1);
sql << id << image;
sql.execute(aConnection);
When RWDBOSql::execute(..) is called to send the data, the id value is read from the RWDBTBuffer in the usual manner. The image data, however, is obtained from the instance of MyDataCallback by invoking the callback method to get the data and send it to the server one piece at a time. The callback is invoked as many times as needed to send all the pieces to the server.
Here is the illustration for the operation:
Figure 11 – Inserting data with a data callback class