Listing 1

void DisableAccount( const std::string & sUniqueAccountName ) 
{ 
  CAccountKey           Key( sUniqueAccountName ); 
  CAccountDB::Transaction_t     Transaction; 
  CAccountDBCursor_t    Cursor( & Transaction ); 
  // This will throw if Key does not exist in the database, 
  // or if the retrieved database record is not a valid 
  // CAccountRecord (it's constructor calls a Validate() method)
  CAccountRecord        AccountRecord
                        ( 
                        Cursor.MoveToKeyAndGetRecord 
                                (
                                Key, 
                                CAccountDBCursor_t::eReadModifyWrite 
                                ) 
                        ); 
  // Here do arbitrary manipulations on AccountRecord (and perhaps other 
  // tables, such as indexes, via more cursors in the same transaction).
  // Any type of exception may be thrown here. 

  // For this example, open a child record and modify it.
  CBillingInfoRecord    BillingInfo( & AccountRecord );
  BillingInfo.SetState( CBillingInfoRecord::eDisabled );
  // Here the operation was successful - write AccountRecord back to DB.
  // This also may throw (e.g. if modified AccountRecord does not pass
  // it's own Validate() method, or if transaction selected for deadlock
  // resolution).
  Cursor.SerializeAndOverwriteCurrentRecord( AccountRecord ); 

  Cursor.Close(); 
  Transaction.Commit(); 

  // End of scope... 
  // Cursor object is destroyed here. If not already explicitly closed
  // then destructor will close it. 
  // Transaction object is destroyed here. If not explicitly commited or
  // aborted then its destructor will call abort(). 
}