Git Product home page Git Product logo

cpp-driver's Introduction

DataStax C/C++ Driver for Apache Cassandra® and DataStax Products

A modern, feature-rich and highly tunable C/C++ client library for Apache Cassandra® 2.1+ using exclusively Cassandra's binary protocol and Cassandra Query Language v3. This driver can also be used with other DataStax products:

Getting the Driver

Binary versions of the driver, available for multiple operating systems and multiple architectures, can be obtained from our download server. The source code is made available via GitHub.

Packages for the driver's dependencies, libuv (1.x), OpenSSL, and zlib are also provided under the dependencies directory for each platform (if applicable). Note: CentOS and Ubuntu use the version of OpenSSL and zlib provided with the distribution:

Upgrading

Starting with DataStax C/C++ driver for Apache Cassandra® v2.15.0, DataStax Enterprise (DSE) support is now available; using the DSE driver exclusively is no longer required for DSE customers.

For DSE driver users

Linking changes will be required when migrating to this driver. Replace -ldse with -lcassandra.

For Cassandra driver users

No changes will be required when upgrading to this driver. There will be new driver dependencies when using any of the binary versions obtained from our download server as Kerberos is utilized in the DSE features of this driver. See the [installation] section for more information on obtaining the dependencies for a specific platform.

Features

Compatibility

This driver works exclusively with the Cassandra Query Language v3 (CQL3) and Cassandra's native protocol. The current version works with:

  • Apache Cassandra® versions 2.1, 2.2 and 3.0+
  • Architectures: 32-bit (x86) and 64-bit (x64)
  • Compilers: GCC 4.1.2+, Clang 3.4+, and MSVC 2010/2012/2013/2015/2017/2019

A complete compatibility matrix for both Apache Cassandra® and DataStax Enterprise can be found here.

Disclaimer: DataStax products do not support big-endian systems.

Documentation

Getting Help

Examples

The driver includes several examples in the examples directory.

A Simple Example

#include <cassandra.h>
/* Use "#include <dse.h>" when connecting to DataStax Enterpise */
#include <stdio.h>

int main(int argc, char* argv[]) {
  /* Setup and connect to cluster */
  CassFuture* connect_future = NULL;
  CassCluster* cluster = cass_cluster_new();
  CassSession* session = cass_session_new();
  char* hosts = "127.0.0.1";
  if (argc > 1) {
    hosts = argv[1];
  }

  /* Add contact points */
  cass_cluster_set_contact_points(cluster, hosts);

  /* Provide the cluster object as configuration to connect the session */
  connect_future = cass_session_connect(session, cluster);

  if (cass_future_error_code(connect_future) == CASS_OK) {
    CassFuture* close_future = NULL;

    /* Build statement and execute query */
    const char* query = "SELECT release_version FROM system.local";
    CassStatement* statement = cass_statement_new(query, 0);

    CassFuture* result_future = cass_session_execute(session, statement);

    if (cass_future_error_code(result_future) == CASS_OK) {
      /* Retrieve result set and get the first row */
      const CassResult* result = cass_future_get_result(result_future);
      const CassRow* row = cass_result_first_row(result);

      if (row) {
        const CassValue* value = cass_row_get_column_by_name(row, "release_version");

        const char* release_version;
        size_t release_version_length;
        cass_value_get_string(value, &release_version, &release_version_length);
        printf("release_version: '%.*s'\n", (int)release_version_length, release_version);
      }

      cass_result_free(result);
    } else {
      /* Handle error */
      const char* message;
      size_t message_length;
      cass_future_error_message(result_future, &message, &message_length);
      fprintf(stderr, "Unable to run query: '%.*s'\n", (int)message_length, message);
    }

    cass_statement_free(statement);
    cass_future_free(result_future);

    /* Close the session */
    close_future = cass_session_close(session);
    cass_future_wait(close_future);
    cass_future_free(close_future);
  } else {
    /* Handle error */
    const char* message;
    size_t message_length;
    cass_future_error_message(connect_future, &message, &message_length);
    fprintf(stderr, "Unable to connect: '%.*s'\n", (int)message_length, message);
  }

  cass_future_free(connect_future);
  cass_cluster_free(cluster);
  cass_session_free(session);

  return 0;
}

License

© DataStax, Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

cpp-driver's People

Contributors

absurdfarce avatar aholmberg avatar angelcaban avatar aruntejch avatar azreal42 avatar bbucher avatar castaglia avatar devnexen avatar dimbleby avatar gahr avatar jduo avatar jeremyschlatter avatar jstasiewicz avatar jul-stas avatar kcieslinski avatar kw217 avatar mikefero avatar mpenick avatar mstump avatar planetbeing avatar pmcfadin avatar remicollet avatar richardkchapman avatar sandvige avatar severinleonhardt avatar sonofsatoshi avatar stamhankar999 avatar vhavel avatar wash-amzn avatar zakalibit avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.