i'm writing c++ application uses mysql c api connect database. mysql server version 5.6.19-log.
i need run several sql update, insert , delete statements in 1 transaction make sure either changes or no changes applied.
i found in docs functions mysql_commit() , mysql_rollback() finish transaction (commit or roll back), can't find corresponding function starts transaction.
is there such function? missing obvious?
i run update, insert , delete statements using mysql_real_query() function.
i guess should able start transaction running start transaction sql statement using same mysql_real_query() function. should able commit transaction running commit sql statement using same mysql_real_query() function.
but then, point of having dedicated mysql_commit() , mysql_rollback() functions in api?
//connect mysql server: mysql *mysql = mysql_init(null); mysql = mysql_real_connect(mysql, ......) //turn off auto_commit mysql_autocommit(mysql , false); or
//start tranaction directly follows mysql_real_query(mysql,"begin"); //run commands: mysql_real_query(mysql,"update..."); //commit transaction mysql_real_query(mysql, "commit");
Comments
Post a Comment