Update Operation
Instances of RWDBCursor are also useful for updating rows in a table. This use of RWDBCursor is an encapsulation of the SQL statement:
 
UPDATE tableName SET <set-clause>
WHERE CURRENT OF cursorName
The following example allows a user to correct names in the customer table:
 
RWDBConnection conn = aDatabase.connection();
RWDBTable customers = aDatabase.table("Customer");
RWDBSelector aSelector = aDatabase.selector();
aSelector << customers["name"];
conn.beginTransaction();
RWDBCursor aCursor =
aSelector.cursor(conn, RWDBCursor::Sequential, RWDBCursor::Write);
RWCString customerName;
aCursor << &customerName;
 
while (aCursor.fetchRow().isValid()) {
std::cout << "Is " << customerName << "correct (Y or N)? ";
char answer;
std::cin >> answer;
if (answer == 'n' || answer == 'N') {
std::cout << "Enter the correction: ";
RWCString firstName, lastName;
std::cin >> firstName;
std::cin >> lastName;
customerName = lastName + "," + firstName;
aCursor.updateRow(table.name());
}
}
conn.commitTransaction();