1. transaction commit mode modification: modify the database commit mode to 0 [manual commit] memset (SQL, 0x00, sizeof (SQL); memcpy (SQL, 1. modify the transaction commit mode: change the database commit mode to 0 [manual commit]
Memset (SQL, 0x00, sizeof (SQL ));
Memcpy (SQL, "set autocommit = 0;", 17 );
If (mysql_query (sock, SQL )){
Sprintf (g_acTrcMsg, "failed to disable automatic submission mode [% d] [% s]", mysql_errno (sock), mysql_error (sock); TRCLOG1
Return-1;
}
2. start transaction
Memset (SQL, 0x00, sizeof (SQL ));
Memcpy (SQL, "start transaction;", 18 );
If (mysql_query (sock, SQL )){
Sprintf (g_acTrcMsg, "failed to establish a 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, "failed to submit the transaction [% d] [% s] \ n", mysql_errno (sock), mysql_error (sock); TRCLOG1
Return-1;
}