An Open SQL Insert Example
This example shows how to use the Open SQL class RWDBOSql in a Sybase Client-Library insert operation. The insert is done on a foo table with an int column and a float column.
 
#define NUMBER_OF_ROWS 10
 
RWDBOSql openSql;
 
RWDBTBuffer<int> intBuffer(NUMBER_OF_ROWS); //1
RWDBTBuffer<float> floatBuffer(NUMBER_OF_ROWS);
 
FillupValues(intBuffer, floatBuffer, NUMBER_OF_ROWS); //2
 
RWCString sybaseSyntaxSql("INSERT INTO foo VALUES(@c1, @c2)"); //3
openSql.statement(sybaseSyntaxSql); //4
 
openSql << intBuffer; //5
openSql << floatBuffer;
 
openSql.execute(conn); //6
 
if( !openSql.isValid() ) //7
cout << “Insert Into Foo Has Failed” << endl;
//1 These two lines create an int buffer and a float buffer, each of size 10.
//2 Fills the buffers with values using a predefined function.
//3 Declares a Sybase-specific SQL syntax for insertion into a foo table.
//4 Associates the SQL with the RWDBOSql object.
//5 These two lines associate the buffer with the RWDBOSql object.
//6 Executes the SQL statement.
//7 Checks the validity of the execution. If an error handler is associated with the connection or with the RWDBOSql object, the error handler is invoked if the operation fails. When error handlers are associated, explicit error checking is unnecessary.