1, Transaction commit mode modification: Modify the database submission mode for 0[ manual submission ]
memset (SQL, 0x00, sizeof (SQL));
memcpy (SQL, "set autocommit=0;", 17);
if (mysql_query (sock, SQL)) {
sprintf (g_actrcmsg, " shutdown autocommit mode failed [%d][%s]", Mysql_errno (sock), Mysql_error (sock)); TRCLOG1
return-1;
}
2. Start of transaction
memset (SQL, 0x00, sizeof (SQL));
memcpy (SQL, "Start transaction;", 18);
if (mysql_query (sock, SQL)) {
sprintf (g_actrcmsg, " failed to establish transaction [%d][%s]", Mysql_errno (sock), Mysql_error (sock)); TRCLOG1
return-1;
}
3. Transaction rollback
memset (SQL, 0x00, sizeof (SQL));
memcpy (SQL, "rollback;", 9);
if (mysql_query (sock, SQL)) {
sprintf (g_actrcmsg, " transaction rollback failed [%d][%s]", Mysql_errno (sock), Mysql_error (sock)); TRCLOG1
return-1;
}
4. Transaction Submission
memset (SQL, 0x00, sizeof (SQL));
memcpy (SQL, "commit;", 7);
if (mysql_query (sock, SQL)) {
sprintf (g_actrcmsg, " Commit transaction Failed [%d][%s]\n", Mysql_errno (sock), Mysql_error (sock)); TRCLOG1
return-1;
}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
C-language MySQL database transaction start, commit, rollback example