forked from VoltDB/voltdb-client-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelloWorld.cpp
More file actions
129 lines (119 loc) · 4.18 KB
/
Copy pathHelloWorld.cpp
File metadata and controls
129 lines (119 loc) · 4.18 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* This file is part of VoltDB.
* Copyright (C) 2008-2015 VoltDB Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
#endif
#ifndef __STDC_LIMIT_MACROS
#define __STDC_LIMIT_MACROS
#endif
#include <vector>
#include <boost/shared_ptr.hpp>
#include "Client.h"
#include "Table.h"
#include "TableIterator.h"
#include "Row.hpp"
#include "WireType.h"
#include "Parameter.hpp"
#include "ParameterSet.hpp"
#include "ClientConfig.h"
int main(int argc, char **argv) {
/*
* Instantiate a client and connect to the database.
*/
voltdb::errType err = voltdb::errOk;
voltdb::ClientConfig config("program", "password");
voltdb::Client client = voltdb::Client::create();
client.createConnection(err, "localhost");
if (!voltdb::isOk(err)) {
std::cout << "Error connecting to database: " << err << std::endl;
return -1;
}
/*
* Describe the stored procedure to be invoked
*/
std::vector<voltdb::Parameter> parameterTypes(3);
parameterTypes[0] = voltdb::Parameter(voltdb::WIRE_TYPE_STRING);
parameterTypes[1] = voltdb::Parameter(voltdb::WIRE_TYPE_STRING);
parameterTypes[2] = voltdb::Parameter(voltdb::WIRE_TYPE_STRING);
voltdb::Procedure procedure("Insert", parameterTypes);
voltdb::InvocationResponse response;
/*
* Load the database.
*/
voltdb::ParameterSet* params = procedure.params();
params->addString(err, "Hello").addString(err, "World").addString(err, "English");
if (!voltdb::isOk(err)) {
std::cout << "Failed to add parameter Hello, World, English" << std::endl;
return -1;
}
response = client.invoke(err, procedure);
if (!voltdb::isOk(err)) {
std::cout << "Failed to invoke procedure. Error: " << err << std::endl;
return -1;
}
if (response.failure()) {
std::cout << response.toString() << std::endl;
return -1;
}
params->addString(err, "Bonjour").addString(err, "Monde").addString(err, "French");
if (!voltdb::isOk(err)) {
std::cout << "Failed to add parameter Bonjour, Monde, French" << std::endl;
return -1;
}
response = client.invoke(err, procedure);
if (!voltdb::isOk(err)) {
std::cout << "Failed to invoke procedure. Error: " << err << std::endl;
return -1;
}
if (response.failure()) {
std::cout << response.toString();
return -1;
}
/*
* Describe procedure to retrieve message
*/
parameterTypes.resize( 1, voltdb::Parameter(voltdb::WIRE_TYPE_STRING));
voltdb::Procedure selectProc("Select", parameterTypes);
/*
* Retrieve the message
*/
selectProc.params()->addString(err, "French");
if (!voltdb::isOk(err)) {
std::cout << "Failed to add parameter French" << std::endl;
return -1;
}
response = client.invoke(err, selectProc);
if (!voltdb::isOk(err)) {
std::cout << "Failed to invoke procedure. Error: " << err << std::endl;
return -1;
}
if (response.failure()) {
std::cout << response.toString();
return -1;
}
/*
* Print the response
*/
std::cout << response.toString();
return 0;
}