Bulk/Array Input
Along with input binding of single values to placeholders, some databases allow arrays of data to be bound into an SQL statement. When an array is bound, the database executes the SQL statement once for each array entry. This operation is often termed bulk binding or array binding. Since RWDBTBuffer can encapsulate either a single value or an array, using the array binding capabilities of your database is simply a matter of supplying RWDBTBuffers with more than one entry. Here’s an example using Sybase syntax:
 
RWCString someData[1000]; //1
populateStrings(someData, 1000); //2
RWDBOSql inserter(“INSERT INTO STRINGS VALUES (@p1)”); //3
RWDBTBuffer<RWCString> dataBuffer(someData, 1000); //4
inserter << dataBuffer; //5
inserter.execute(aConn); //6
On //1, we create an array of RWCStrings, which is populated on //2 by a function defined elsewhere. On //3, we create an RWDBOSql, which will be used for inserting the data into the STRINGS table. On //4, an RWDBTBuffer is created to encapsulate the array created earlier, and on //5, the RWDBTBuffer is bound into the RWDBOSql. Line //6 executes the statement, causing all 1000 entries to be inserted into the STRINGS table.
If you bind multiple RWDBTBuffers to an RWDBOSql with multiple placeholders, the RWDBOSql uses the size of the smallest RWDBTBuffer to determine how many times to execute its encapsulated SQL statement. For example, consider a statement with three placeholders, and three RWDBTBuffers of lengths 20, 40, and 50 entries, respectively. In this case, only the first 20 entries of each buffer are used when execute() is invoked, because the entries of the smallest buffer total 20.