Main  /  Edit  /  History  /   /  Users Area


This is simple class that allows executing exception safe transactions.

class transaction{
  transaction(session &sql);
  void commit();
  void rollback();

When the object is created, transaction begins. It is equivalent to:


If commit() called, "COMMIT" sql statement is executed and nothing is done on destruction. rollback() does the same, but the statement is "ROLLBACK".

If the object is destructed and commit() or rollback() hadn't called before, then rallback() is automatically called.

For example:

void move_money(string from,string to, int amount)
  dbixx::transaction tr(sql);
  int id1=get_id(from); 
  sql<<"UPDATE users SET account=account+? "
       "WHERE id=?", amount, id1,exec();
  int id2=get_id(to);
  sql<<"UPDATE users SET account=account-? "
       "WHERE id=?", amount, id2,exec();

If get_id(to) throws, then transaction is automatically rolled back.


CppCMS is a web development framework for performance demanding applications.

Support This Project Logo

Поддержать проект

CppCMS needs You


Main Page

Valid CSS | Valid XHTML 1.0