4
#include "hstcpcli.hpp"
5
#include "string_util.hpp"
10
hstcpcli_main(int argc, char **argv)
13
parse_args(argc, argv, conf);
16
hstcpcli_ptr cli = hstcpcli_i::create(sockargs);
17
const std::string dbname = conf.get_str("dbname", "hstest");
18
const std::string table = conf.get_str("table", "hstest_table1");
19
const std::string index = conf.get_str("index", "PRIMARY");
20
const std::string fields = conf.get_str("fields", "k,v");
21
const int limit = conf.get_int("limit", 0);
22
const int skip = conf.get_int("skip", 0);
23
std::vector<std::string> keys;
24
std::vector<string_ref> keyrefs;
27
const std::string conf_key = std::string("k") + to_stdstring(num_keys);
28
const std::string k = conf.get_str(conf_key, "");
29
const std::string kx = conf.get_str(conf_key, "x");
30
if (k.empty() && kx == "x") {
36
for (size_t i = 0; i < keys.size(); ++i) {
37
const string_ref ref(keys[i].data(), keys[i].size());
38
keyrefs.push_back(ref);
40
const std::string op = conf.get_str("op", "=");
41
const string_ref op_ref(op.data(), op.size());
42
cli->request_buf_open_index(0, dbname.c_str(), table.c_str(),
43
index.c_str(), fields.c_str());
44
cli->request_buf_exec_generic(0, op_ref, num_keys == 0 ? 0 : &keyrefs[0],
45
num_keys, limit, skip, string_ref(), 0, 0);
49
if (cli->request_send() != 0) {
50
fprintf(stderr, "request_send: %s\n", cli->get_error().c_str());
53
if ((code = cli->response_recv(numflds)) != 0) {
54
fprintf(stderr, "response_recv: %s\n", cli->get_error().c_str());
58
cli->response_buf_remove();
60
if ((code = cli->response_recv(numflds)) != 0) {
61
fprintf(stderr, "response_recv: %s\n", cli->get_error().c_str());
65
const string_ref *const row = cli->get_next_row();
70
for (size_t i = 0; i < numflds; ++i) {
71
const std::string val(row[i].begin(), row[i].size());
72
printf(" %s", val.c_str());
77
cli->response_buf_remove();
84
main(int argc, char **argv)
86
return dena::hstcpcli_main(argc, argv);