#include #include #include #include #include #include static char * c_host = "orion"; static char * c_user = "mysuser"; static char * c_auth = "fourjs"; static int c_port = 3308; static char * c_sock = NULL; static char * c_dbnm = "test1"; static int executing_query; static unsigned long thread_id; static void kill_query(void) { char cmd[50]; MYSQL *h; h = mysql_init(NULL); if (!mysql_real_connect(h, c_host, c_user, c_auth, c_dbnm, c_port, c_sock, CLIENT_FOUND_ROWS)) { fprintf(stderr, "kill_query: Could not connect (err=%d)\n", mysql_errno(h)); return; } sprintf(cmd, "KILL QUERY %ld", thread_id); if (mysql_query(h, cmd) != 0) { fprintf(stderr, "Could not execute %s.", cmd); } mysql_close(h); } static void handle_ctrlc_signal(int sig) { fprintf(stdout, "SIGINT caught! executing_query = %d\n", executing_query); if (executing_query) { executing_query = 0; kill_query(); } return; } int main(int argc, char ** argv) { MYSQL * conn; int i, s; const char * sqlstmt = "select benchmark(1000000000, md5('when will it end?'))"; MYSQL_RES * res; unsigned int c; signal(SIGINT, handle_ctrlc_signal); conn = mysql_init(NULL); if (!mysql_real_connect(conn, c_host, c_user, c_auth, c_dbnm, c_port, c_sock, CLIENT_FOUND_ROWS)) { fprintf(stderr, "Could not connect (err=%d)\n", mysql_errno(conn)); return -1; } thread_id = mysql_thread_id(conn); fprintf(stdout, "MySQL thread ID: %ld\n", thread_id); for (i=0; i<3; i++) { fprintf(stdout, "\nRound %d:\n", i+1); fprintf(stdout, "Executing statement ...\n"); executing_query = 1; s = mysql_query(conn, sqlstmt); if (s!=0) { if (mysql_errno(conn) == 1317) { fprintf(stdout, "Statement interrupted by user...\n"); } else { fprintf(stderr, "Could not execute the query (err=%d)\n", mysql_errno(conn)); return -1; } } fprintf(stdout, "Get field count:"); c = mysql_field_count(conn); fprintf(stdout, " %d\n", c); fprintf(stdout, "Calling mysql_store_result()..."); res = mysql_store_result(conn); if (res==NULL) { fprintf(stderr, "Could not get result handle (err=%d)\n", mysql_errno(conn)); return -1; } fprintf(stdout, "Calling mysql_free_result()..."); mysql_free_result(res); fprintf(stdout, "Round done.\n"); } return 0; }