1 message in com.mysql.lists.plusplustransactions using c++
FromSent OnAttachments
Naveen David01 Dec 2001 02:15 
Subject:transactions using c++
From:Naveen David (znda@hotmail.com)
Date:12/01/2001 02:15:49 AM
List:com.mysql.lists.plusplus

HI,

I am quite new to sqlplus and am trying to do some transactions using C++. The tables in question are BerkleyDB tables which are transactional safe tables. I am hardcodeing begin-commit statements in mysql into c++. The program looks like this

Connection con(DATABASE,HOST,USER,PASSWORD); Query query = con.query(); try{ query<<"set autocommit = 0"; query.execute(); //query<<"begin"; //query.execute(); query<<"lock table animal write";//lock the table query.execute(); query<<"update animal set name = \"HELL\" where color = \"pink\""; query<<"Lock table ratio write"; query.execute(); query<<"insert into ratio set ID = 4"; //Trying to generate an error by entering a duplicate ID query.execute(); query<<"commit";//commiting if everything goes well query.execute(); query<<"unlock tables"; query.execute(); }catch(BadQuery er) { //Trying to rollback in case of some error query<<"rollback"; query.execute(); cout<<con.affected_rows(); cerr<<"ERROR:"<<er.error<<endl; }

I am trying to make the updation of the first table a success and the insertion into the second table a failure. And after that I want to rollback the first updation. Although the rollback query is executed there seems to be no rollback. I have used both BEGIN and SET AUTOCOMMIT = 0 methods. The only way to do a rollback seems to be to use two connections. But I do not want to use two connections. Any help will be appreciated.

Thanks, David.