Insert Operation
Instances of RWDBCursor may be used to insert rows in a table. This use is an encapsulation of the SQL statement:
 
INSERT tableName WHERE CURRENT OF cursorName
The following example allows users to insert new rows in the customer table:
 
RWDBConnection conn = aDatabase.connection();
RWDBTable customers = aDatabase.table("customer");
RWDBSelector aSelector = aDatabase.selector();
aSelector << customers["name"] << customers["address"];
 
conn.beginTransaction();
RWDBCursor aCursor =
aSelector.cursor(conn, RWDBCursor::Scrolling, RWDBCursor::Write);
RWCString customerName, customerAddress;
aCursor << &customerName << &customerAddress;
 
char answer = 'Y';
do {
std::cout << "\n=== List of Current Customers ===" << std::endl;
if (aCursor.fetchRow(RWDBCursor::First).isValid()) {
do {
std::cout << customerName << "\t"
<< customerAddress << std::endl;
} while (aCursor.fetchRow().isValid());
}
std::cout << "\nAdd a customer (Y or N)? ";
std::cin >> answer;
if (answer == 'y' || answer == 'Y') {
std::cout << "Enter the new customer information: ";
RWCString firstName, lastName;
std::cin >> firstName >> lastName >> customerAddress;
customerName = lastName + "," + firstName;
aCursor.insertRow(customers.name());
}
} while (answer == 'y' || answer == 'Y');