-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstate_tracker.cc
55 lines (48 loc) · 1.49 KB
/
state_tracker.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
#include "common.hh"
void print_status_changes(MYSQL* c)
{
const char* ptr = nullptr;
size_t len = 0;
if (mysql_session_track_get_first(c, SESSION_TRACK_SYSTEM_VARIABLES, &ptr, &len) == 0)
{
std::cout << std::string_view(ptr, len) << std::endl;
while (mysql_session_track_get_next(c, SESSION_TRACK_SYSTEM_VARIABLES, &ptr, &len) == 0)
{
std::cout << std::string_view(ptr, len) << std::endl;
}
}
}
int main(int argc, char** argv)
{
Config cnf = parse(argc, argv);
MYSQL* c = mysql_init(nullptr);
if (!mysql_real_connect(c, cnf.host, cnf.user, cnf.password, cnf.db, cnf.port, nullptr, CLIENT_MULTI_STATEMENTS|CLIENT_MULTI_RESULTS))
{
std::cout << "Connect: " << mysql_error(c) << std::endl;
}
else
{
auto queries = {
"SELECT 1",
"SET autocommit=0",
"SET autocommit=1,tx_isolation='REPEATABLE-READ'",
"CREATE OR REPLACE TABLE test.t1(id INT)",
"INSERT INTO test.t1 VALUES (1)",
"SET @myvar=1,autocommit=0,sql_notes=0",
"SELECT 1",
"COMMIT",
};
for (auto query : queries)
{
std::cout << query << std::endl;
mysql_query(c, query);
auto res = mysql_store_result(c);
print_status_changes(c);
mysql_free_result(res);
std::cout << std::endl;
sleep(1);
}
}
mysql_close(c);
return 0;
}