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
104 lines (90 loc) · 3.73 KB
/
Copy pathHelloWorld.cpp
File metadata and controls
104 lines (90 loc) · 3.73 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
/* 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.
*/
#define __STDC_CONSTANT_MACROS
#define __STDC_LIMIT_MACROS
#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.
* SHA-256 can be used as of VoltDB5.2 by specifying voltdb::HASH_SHA256
*/
voltdb::ClientConfig config("myusername", "mypassword", voltdb::HASH_SHA1);
voltdb::Client client = voltdb::Client::create(config);
client.createConnection("localhost");
/*
* 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("English").addString("Hello").addString("World");
response = client.invoke(procedure);
if (response.failure()) { std::cout << response.toString() << std::endl; return -1; }
params->addString("French").addString("Bonjour").addString("Monde");
response = client.invoke(procedure);
if (response.failure()) { std::cout << response.toString(); return -1; }
params->addString("Spanish").addString("Hola").addString("Mundo");
response = client.invoke(procedure);
if (response.failure()) { std::cout << response.toString(); return -1; }
params->addString("Danish").addString("Hej").addString("Verden");
response = client.invoke(procedure);
if (response.failure()) { std::cout << response.toString(); return -1; }
params->addString("Italian").addString("Ciao").addString("Mondo");
response = client.invoke(procedure);
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("Spanish");
response = client.invoke(selectProc);
/*
* Print the response
*/
std::cout << response.toString();
if (response.statusCode() != voltdb::STATUS_CODE_SUCCESS) {
return -1;
} else {
return 0;
}
}