-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
101 lines (79 loc) · 2.39 KB
/
test.cpp
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include "tpw.hpp"
void
simple_test()
{
TPW::Connection conn("localhost", 3301);
TPW::Space space = conn.get_space("tester");
std::cout << "This example follows " <<
"http://tarantool.org/doc/getting_started.html" << std::endl;
std::cout << "'tester' space has internal number " << space.num() <<
" while TPW able to use symbolic names" << std::endl;
//
// Uncomment to start fresh
conn.write( conn.call("box.space.tester:truncate") ).read();
//
try
{
std::cout << "Insert records in slightly different ways" << std::endl;
conn.write( conn.insert(space) << 4U << "Painting" ).read();
conn.insert(space) << 5U << "Diameter" << 12U <<
TPW::ENDR;
conn.write( conn.insert(space) << (uint64_t)6 << "Weight"
<< (uint64_t)80 ).read();
}
catch(const TPW::Connection::Error& err)
{
std::cout << "we've got error " << err.what() <<
", but lets try to go further" << std::endl;
}
uint64_t metric_value;
std::string metric_name;
conn.select(space) << 5U << TPW::ENDR >>
TPW::SKIP >> metric_name >> metric_value;
std::cout << "We've got value " << metric_value << " for " <<
metric_name << std::endl;
std::cout << "All known tester tools are:" << std::endl;
std::cout << conn.write( conn.select(space) /* << 1U */).read().explain();
std::cout << "==" << std::endl;
for(;;)
{
TPW::ITStream&& its(conn.get_itstream());
if (!its.good())
{
std::cout << "all done" << std::endl;
break;
}
uint64_t id;
std::string tool_name;
its >> id >> tool_name;
std::cout << " > " << id << ':' << tool_name << std::endl;
}
std::cout << conn.write( conn.select(space)/* << 1U*/).read().explain();
std::cout << "==" << std::endl;
for(;;)
{
TPW::ITStream&& its(conn.get_itstream());
if (!its.good())
{
std::cout << "all done" << std::endl;
break;
}
#if 0
uint64_t id;
std::string tool_name;
its >> std::make_tuple(std::ref(id), std::ref(tool_name));
std::cout << " > " << id << ':' << tool_name << std::endl;
#else
std::tuple<uint64_t, std::string> tpl;
its >> tpl;
std::cout << " > " << std::get<0>(tpl) << ':' << std::get<0>(tpl) << std::endl;
#endif
}
conn.call_execute("string.format", "%s_%d_%s", "string one", 10, "string two");
std::cout << conn.read().explain();
}
int
main(int, char**)
{
simple_test();
}