-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbasic.cpp
More file actions
44 lines (33 loc) · 941 Bytes
/
basic.cpp
File metadata and controls
44 lines (33 loc) · 941 Bytes
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
#include <cstdlib>
#include <iostream>
#include <mgclient.hpp>
int main(int argc, char *argv[]) {
if (argc != 4) {
std::cerr << "Usage: " << argv[0] << " [host] [port] [query]\n";
exit(1);
}
mg::Client::Init();
std::cout << "mgclient version: " << mg::Client::Version() << std::endl;
mg::Client::Params params;
params.host = argv[1];
params.port = static_cast<uint16_t>(atoi(argv[2]));
params.use_ssl = false;
auto client = mg::Client::Connect(params);
if (!client) {
std::cerr << "Failed to connect!\n";
return 1;
}
if (!client->Execute(argv[3])) {
std::cerr << "Failed to execute query!";
return 1;
}
int rows = 0;
while (const auto maybeResult = client->FetchOne()) {
++rows;
}
std::cout << "Fetched " << rows << " row(s)\n";
// Deallocate the client because mg_finalize has to be called globally.
client.reset(nullptr);
mg::Client::Finalize();
return 0;
}