#ifdef WIN32 #include #endif #include #include #include void print_server_status(MYSQL *sock) { printf("Server Status: "); if(sock->server_status & 1) printf("[InTransaction]"); if(sock->server_status & 2) printf("[AutoCommitMode]"); if(sock->server_status & 4) printf("[MoreResults]"); if(sock->server_status & 8) printf("[AnotherQuery]"); if(sock->server_status & 16) printf("[BadIndex]"); if(sock->server_status & 32) printf("[NoIndex]"); if(sock->server_status & 64) printf("[CursorExists]"); if(sock->server_status & 128) printf("[LastRowSent]"); printf("\n"); } int do_query(MYSQL *sock, const char *q) { MYSQL_RES *res; MYSQL_ROW row; int num= 0; printf("Query: %s\n", q); if(mysql_query(sock, q)) { fprintf(stderr,"Query failed (%s)\n",mysql_error(sock)); return -1; } if (!(res= mysql_store_result(sock))) { if(num= mysql_field_count(sock)) { fprintf(stderr,"Couldn't get result from %s\n", mysql_error(sock)); return -1; } } else { printf("Fetching data:\n"); while(row= mysql_fetch_row(res)) { printf("%s\n", row[0]); } printf("Data fetched!\n"); } mysql_free_result(res); return 0; } int main(int argc, char **argv) { MYSQL mysql,*sock; if (argc < 3) { fprintf(stderr,"usage : bug36326 \n\n"); exit(1); } mysql_init(&mysql); if (!(sock = mysql_real_connect(&mysql,NULL,argv[2],argv[3],argv[1],0,NULL,0))) { fprintf(stderr,"Couldn't connect to engine!\n%s\n\n",mysql_error(&mysql)); perror(""); exit(1); } if(do_query(sock, "DROP TABLE IF EXISTS in_transaction")) exit(1); if(do_query(sock, "CREATE TABLE in_transaction(id int)")) exit(1); if(do_query(sock, "INSERT INTO in_transaction (id) VALUES (1),(2),(3),(4)")) exit(1); if(do_query(sock, "SET GLOBAL query_cache_type = 1")) exit(1); if(do_query(sock, "SET GLOBAL query_cache_size = 1000000")) exit(1); print_server_status(sock); /* begin transaction */ if(do_query(sock, "BEGIN")) exit(1); if(do_query(sock, "SELECT * FROM in_transaction")) exit(1); print_server_status(sock); /* rollback transaction */ if(do_query(sock, "ROLLBACK")) exit(1); print_server_status(sock); if(do_query(sock, "select * FROM in_transaction")) exit(1); print_server_status(sock); if(do_query(sock, "SELECT * FROM in_transaction")) exit(1); print_server_status(sock); if(sock->server_status & 1) printf("ERROR! [InTransaction] status detected!\n"); else printf("SUCCESS!\n"); mysql_close(sock); exit(0); return 0; /* Keep some compilers happy */ }