Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Readme with example for CPP compilation

  • Loading branch information...
commit fc428bf8eab6a20344ba9c338b2727650c8ad7f7 1 parent a21c7f9
Ryan Betts rbetts authored
Showing with 84 additions and 0 deletions.
  1. +84 −0 README
84 README
View
@@ -0,0 +1,84 @@
+= VoltDB CPP Client Library
+
+The VoltDB client library implements the native VoltDB wire
+protocol. You can use the library to connect to a VoltDB cluster,
+invoke stored procedures and read responses.
+
+The Using VoltDB Guide explains how to use the CPP library in the
+chapter 12.1.2: Writing VoltDB Client Applications in C++.
+
+
+== Linking against libvoltdb.a
+
+The following command will compile and link an example client
+(clientvoter.cpp) libvoltdb.a.
+
+Directory structure for this example:
+
+./clientvoter.cpp # Example client
+./voltdb/include/ # Directory containing client library headers
+./voltdb/lib # Directory containing client library archive
+
+g++ -lrt -I./voltdb/usr/include/ \
+-D__STDC_LIMIT_MACROS \
+-DBOOST_SP_DISABLE_THREADS \
+clientvoter.cpp \
+./voltdb/lib/libvoltcpp.a \
+-o clientvoter
+
+==== Example clientvoter.cpp
+
+/*
+ This very simple example demonstrates a few basic concepts.
+ This example executes against the 'voter' example included
+ in the voltdb distribution.
+
+ The "Using VoltDB Guide" includes more complete information.
+*/
+
+#include "Client.h"
+#include "Parameter.hpp"
+#include "ParameterSet.hpp"
+#include "Row.hpp"
+#include "Table.h"
+#include "TableIterator.h"
+#include "WireType.h"
+
+#include <vector>
+
+using namespace std;
+
+int main(int argc, char** argv) {
+
+ // instantiate a voltdb::Client instance
+ voltdb::Client client = voltdb::Client::create();
+ client.createConnection("localhost");
+
+ // create a procedure instance for the Initialize procedure
+ vector<voltdb::Parameter> initParamTypes(2);
+ initParamTypes[0] = voltdb::Parameter(voltdb::WIRE_TYPE_INTEGER);
+ initParamTypes[1] = voltdb::Parameter(voltdb::WIRE_TYPE_STRING, true);
+ voltdb::Procedure initialize("Initialize", initParamTypes);
+ voltdb::ParameterSet *initParams = initialize.params();
+
+ // invoke the Initialize procedure
+ int64_t maxContestant = 4;
+ vector<string> contestantNames;
+ contestantNames.push_back("Edwina Burnam");
+ contestantNames.push_back("Tabatha Gehling");
+ contestantNames.push_back("Kelly Clauss");
+ contestantNames.push_back("Jessie Alloway");
+ initParams->addInt32(maxContestant);
+ initParams->addString(contestantNames);
+ voltdb::InvocationResponse initResponse = client.invoke(initialize);
+
+ if (initResponse.failure()) {
+ cout << "Initialization failed. " << initResponse.toString() << endl;
+ return -1;
+ }
+
+ cout << "Successfully connected and initialized the database." << endl;
+ return 0;
+}
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.