-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlong_ps.cc
66 lines (53 loc) · 1.51 KB
/
long_ps.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
57
58
59
60
61
62
63
64
65
66
#include <mysql.h>
#include <string>
#include <iostream>
const char* user = "maxuser";
const char* password = "maxpwd";
const char* db = "test";
const char* host = "127.0.0.1";
int port = 4006;
std::string create_query(int bytes)
{
const std::string prefix = "SELECT '";
const std::string suffix = "'";
std::string query;
query.reserve(bytes);
query += prefix;
query.insert(query.end(), bytes - prefix.size() - suffix.size(), 'a');
query += suffix;
return query;
}
int main(int argc, char** argv)
{
MYSQL* c = mysql_init(nullptr);
int bytes = 0xffffff;
if (argc > 1)
{
bytes = strtol(argv[1], nullptr, 0);
}
bytes = std::max(bytes - 1, 0);
int timeout = 20;
mysql_optionsv(c, MYSQL_OPT_CONNECT_TIMEOUT, &timeout);
mysql_optionsv(c, MYSQL_OPT_READ_TIMEOUT, &timeout);
mysql_optionsv(c, MYSQL_OPT_WRITE_TIMEOUT, &timeout);
if (!mysql_real_connect(c, host, user, password, db, port, nullptr, 0))
{
std::cout << "Connect: " << mysql_error(c) << std::endl;
}
else
{
MYSQL_STMT* stmt = mysql_stmt_init(c);
std::string query = create_query(bytes);
if (mysql_stmt_prepare(stmt, query.c_str(), query.length()))
{
std::cout << "Prepare: " << mysql_error(c) << std::endl;
}
if (mysql_stmt_execute(stmt))
{
std::cout << "Execute: " << mysql_error(c) << std::endl;
}
mysql_stmt_close(stmt);
}
mysql_close(c);
return 0;
}