c语言mysql数据库事务开始、提交、回滚范例

时间:2015-07-31 16:24:24   收藏:0   阅读:480

1、 事务提交模式修改:修改数据库提交模式为0[手动提交]

memset ( sql, 0x00, sizeof( sql ) );

memcpy ( sql, "set autocommit=0;", 17 );

if( mysql_query( sock, sql ) ){

sprintf( g_acTrcMsg, "关闭自动提交模式失败[%d][%s]", mysql_errno( sock ), mysql_error( sock ) );TRCLOG1

return -1;

}

 

2、 事务开始

memset ( sql, 0x00, sizeof( sql ) );

memcpy ( sql, "start transaction;", 18 );

if( mysql_query( sock, sql ) ){

sprintf( g_acTrcMsg, "建立事务失败[%d][%s]", mysql_errno( sock ), mysql_error( sock ) );TRCLOG1

return -1;

}

 

3、 事务回滚

memset ( sql, 0x00, sizeof( sql ) );

memcpy ( sql, "rollback;", 9 );

if( mysql_query( sock, sql ) ){

sprintf( g_acTrcMsg, "事务回滚失败[%d][%s]", mysql_errno( sock ), mysql_error( sock ) );TRCLOG1

return -1;

}

 

 

4、 事务提交

memset ( sql, 0x00, sizeof( sql ) );

memcpy ( sql, "commit;", 7 );

if( mysql_query( sock, sql ) ){

sprintf( g_acTrcMsg, "提交事务失败[%d][%s]\n", mysql_errno( sock ), mysql_error( sock ) );TRCLOG1

return -1;

}

 

版权声明:本文为博主原创文章,未经博主允许不得转载。

原文:http://blog.csdn.net/hnlyyk/article/details/47169921

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!