/* * test the SERVER_STATUS_IN_TRANS flag in MYSQL.server_status * * compile: gcc -o csc30924 csc30924.c `mysql_config --cflags --libs` */ #include #include #include #define NONZERO(F) \ if (!(F)) {\ printf("Error: 0 == %s\n", #F);\ exit(1);\ } else\ printf("OK: %s\n", #F); #define QUERY(F) \ if (mysql_query(mysql, F)) { \ printf("Query '%s' failed!\n", F); \ } else { \ printf("OK: %s\n", F); \ printf("connection is%s in transaction\n", \ mysql->server_status & SERVER_STATUS_IN_TRANS ? "" : " not"); \ } int main(void) { MYSQL *mysql; //connect to MySQL NONZERO(mysql= mysql_init(NULL)); NONZERO(mysql_real_connect(mysql, "localhost", NULL, NULL, "test", 0, NULL, 0)); QUERY("DROP TABLE IF EXISTS t1"); QUERY("CREATE TABLE t1 (c1 int)"); QUERY("BEGIN"); QUERY("INSERT INTO t1 (c1) VALUES (1)"); QUERY("COMMIT"); //cleanup & disconnect QUERY("DROP TABLE IF EXISTS t1"); mysql_close(mysql); printf("complete\n"); }