#include #include #include #include int main(int argc, char* const argv[]) { int errCnt=0; time_t begin = time(0); // create 2 connections MYSQL * pHandle = mysql_init(0); MYSQL * pHandle2 = mysql_init(0); if (!mysql_real_connect(pHandle, "127.0.0.1", "root", 0, 0, 0, 0, 0) || !mysql_real_connect(pHandle2, "127.0.0.1", "root", 0, 0, 0, 0, 0)) { printf("Connection Error\n"); return 1; } // drop create and use DB mysql_query(pHandle, "DROP DATABASE IF EXISTS TestCase"); mysql_query(pHandle, "CREATE DATABASE TestCase"); mysql_query(pHandle, "USE TestCase"); mysql_query(pHandle2, "USE TestCase"); // create table mysql_query(pHandle, "CREATE TABLE t1 (c1 int(10), PRIMARY KEY (c1))"); // loop until limit reached, recording errors as we go for (int i = 0; i < 100000; i++) { char insert[80]; char select[80]; sprintf(insert, "INSERT INTO t1 VALUES (%d)", i); sprintf(select, "SELECT * FROM t1 WHERE c1 = %d", i); // insert row mysql_query(pHandle, insert); // select using different connection // expecting result to contain 1 row // expecting result to contain 1 row mysql_query(pHandle2, select); MYSQL_RES * res = mysql_store_result(pHandle2); if (res->row_count != 1) { printf("Unexpected number of results: %d - Key %d\n", (int)res->row_count, i); errCnt++; } mysql_free_result(res); } printf("Test completed in %d seconds. Number of errors: %d\n", (int)(time(0) - begin), errCnt); return 0; }