#include <iostream>
#include <thread>

#include <mysql/mysql.h>

void
qc_stress()
{
	MYSQL *conn = mysql_init(NULL);
	MYSQL_RES *res;
	MYSQL_ROW row;

	try {
		if (!mysql_real_connect(conn, "localhost", "root", "", "test",
					3306, NULL, 0))
			throw "can not connect";

		for (int i = 0; i < 1000000; i++) {
			std::string q = "SELECT * from qc_benchmark WHERE a < "
					+ std::to_string(i);
			if (mysql_query(conn, q.c_str()))
				throw "query error";
			mysql_free_result(mysql_use_result(conn));
		}
	}
	catch (const char *s) {
		std::cout << "Exception: " << s << std::endl;
	}
}

int
main(int argc, char *argv[])
{
	std::thread thr[16];

	for (auto &t : thr)
		t = std::thread(qc_stress);

	for (auto &t : thr)
		t.join();
	std::cout << "finish" << std::endl;
}
