/* test case */ #include #include #include #include #include int main(int argc, char** argv) { const char *multiSQL= "DROP TABLE IF EXISTS test_table;" "CREATE TABLE test_table(id INT);" "INSERT INTO test_table VALUES(10);" "UPDATE test_table SET id=20 WHERE id=10;" "SELECT * FROM test_table;" "INSER INTO non_existent_table VALUES(11);" ; MYSQL conn; int res; printf("start...\n"); mysql_init(&conn); if (! mysql_real_connect(&conn,"localhost","root", "", "test",3306, NULL, CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS)) { printf("FAIL when trying to connect\n"); exit(1); } else { printf("SUCCESS when trying to connect\n"); } if(0==mysql_real_query(&conn,multiSQL,(unsigned long)strlen(multiSQL))) { MYSQL_RES *result=NULL; if(mysql_field_count(&conn)>0) {//Clear result in case there is a result. result=mysql_use_result(&conn); if (NULL!=result) mysql_free_result(result); } while(1) { res=mysql_next_result(&conn); if(mysql_field_count(&conn)>0) {//Clear result in case there's a result. result=mysql_use_result(&conn); if(NULL!=result) mysql_free_result(result); } if(res>0) { printf("FAIL\n"); break; } else { printf("OK\n"); if(res==-1)//last one. Gets in here on ERROR too, why? { printf("\nLast one :-)."); break; } } printf("\n"); }//while(1) } else { printf("FAIL query\n"); } mysql_close(&conn); }