An Open SQL Insert Example
This example shows how to use the Open SQL class RWDBOSql in an Oracle insert operation. The insert is done on a foo table with an int column and a float column.
 
const size_t NUMBER_OF_ROWS = 10;
 
RWDBOSql openSql;
 
RWDBTBuffer<int> intBuffer(NUMBER_OF_ROWS); //1
RWDBTBuffer<float> floatBuffer(NUMBER_OF_ROWS); //2
 
RWCString oracleSyntaxSql("INSERT INTO foo VALUES(:c1, :c2)"); //3
openSql.statement(oracleSyntaxSql); //4
 
openSql << intBuffer; //5
openSql << floatBuffer; //6
 
while (FillupValues(intBuffer, floatBuffer, NUMBER_OF_ROWS)){ //7
openSql.execute(conn); //8
if (!openSql.isValid()) { //9
cout << "Insert Into foo Has Failed" << endl;
break;
}
}
//1-//2 Creates int and float buffers of size 10; in other words, the buffers hold up to 10 rows of data.
//3 Declares an Oracle-specific SQL syntax for inserting into a foo table. Note the placeholder syntax.
//4 The SQL is associated with the RWDBOSql object.
//5-6 Associates the buffer with the RWDBOSql object.
//7 The function FillupValues() is assumed to be a user-defined function which places NUMBER_OF_ROWS data entries into the int and float buffers every time it is called and returns true if it is able to do so.
//8 If FillupValues() succeeds, this line executes the inserter and inserts NUMBER_OF_ROWS new rows into the table named foo. If the execution of the SQL statement fails, the error handler associated with the connection is invoked.
//9 Checks the validity of the execution and breaks out of the while loop on failure.