-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend_to_blackhole.cc
56 lines (48 loc) · 1.4 KB
/
send_to_blackhole.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "common.hh"
int main(int argc, char** argv)
{
auto cnf = parse(argc, argv);
int NUM_QUERIES = 100000;
if (!cnf.args.empty())
{
NUM_QUERIES = std::stoi(cnf.args[0]);
}
MYSQL* c = mysql_init(nullptr);
if (!mysql_real_connect(c, cnf.host, cnf.user, cnf.password, cnf.db, cnf.port, nullptr, 0))
{
std::cout << "Failed to connect: " << mysql_error(c) << std::endl;
mysql_close(c);
}
else if (mysql_query(c, "CREATE OR REPLACE TABLE test.blackhole(id INT) ENGINE=BLACKHOLE"))
{
std::cout << "mysql_query: " << mysql_error(c) << std::endl;
}
else
{
std::string query = "INSERT INTO test.blackhole VALUES (1)";
for (int i = 0; i < NUM_QUERIES; i++)
{
if (mysql_send_query(c, query.c_str(), query.length()))
{
std::cout << "mysql_send_query: " << mysql_error(c) << std::endl;
}
else
{
std::cout << "Send: " << i << "\n";
}
}
for (int i = 0; i < NUM_QUERIES; i++)
{
if (mysql_read_query_result(c))
{
std::cout << "mysql_read_query_result: " << mysql_error(c) << std::endl;
}
else
{
std::cout << "Read: " << i << "\n";
}
}
}
mysql_close(c);
return 0;
}