DataStax C/C++ Driver for Apache Cassandra
Clone or download
mikefero Merge pull request #435 from zatsepin/master
Fixed libuv library searching
Latest commit 6eed698 Dec 3, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin CPP-449: Adding Visual Studio 2017 to automated build script Sep 21, 2017
cmake/modules Fixed libuv library searching Nov 7, 2018
examples Merge remote-tracking branch 'riptano/1.6.0' into 1.10.0 Jul 19, 2018
gtests CPP-688 - Abstract protocol handling (#433) Oct 18, 2018
include CPP-688 - Abstract protocol handling (#433) Oct 18, 2018
packaging CPP-655 - Add packaging support for Ubuntu 18.04 Sep 27, 2018
src CPP-688 - Abstract protocol handling (#433) Oct 18, 2018
test test: Adding help message for `--keep-cluster` and updating versions Oct 9, 2018
topics doc: Adding driver installation to installation section of README Oct 9, 2018
.build.sh CPP-690 - Add per-commit Jenkins CI (#431) Oct 9, 2018
.gitignore Merge remote-tracking branch 'riptano/master' into 2.10.0 Sep 26, 2018
.travis.sh CPP-682 - Fix unit test execution on TravisCI Oct 1, 2018
.travis.yml CPP-682 - Fix unit test execution on TravisCI Oct 1, 2018
CHANGELOG.md doc: Add missing changelog entry Oct 10, 2018
CMakeLists.txt Merge remote-tracking branch 'riptano/master' into 2.10.0 Sep 26, 2018
CONTRIBUTING.md Fixing typo in CONTRIBUTING.md Apr 17, 2015
Doxyfile.in Fixed header docs for new features Mar 14, 2016
LICENSE.txt initial version based on libCql Aug 21, 2013
README.md Add Ubuntu 18.04 to the landing page Oct 10, 2018
appveyor.ps1 ci: Correcting archive package names Oct 10, 2018
appveyor.yml ci: Ensuring tags are always built on AppVeyor Oct 10, 2018
build.yaml CPP-690 - Add per-commit Jenkins CI (#431) Oct 9, 2018
cassconfig.hpp.in Merge remote-tracking branch 'riptano/master' into 2.10.0 Sep 26, 2018
cmake_uninstall.cmake.in Improved and refactored CMake build system. Sep 3, 2013
docs.yaml DOC-2049: added new option to docs.yaml file. Oct 31, 2018
vc_build.bat Release preparations for v2.9.0 Apr 11, 2018

README.md

DataStax C/C++ Driver for Apache Cassandra

Build Status: Linux Build Status: Windows

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. Use the DSE C/C++ driver for better compatibility and support for DataStax Enterprise.

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. If using DataStax Enterprise use the DSE C/C++ driver instead.

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

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

If using DataStax Enterprise the DSE C/C++ driver provides more features and better compatibility. 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

Feedback Requested

Help us focus our efforts! Provide your input on the C/C++ Driver Platform and Runtime Survey (we kept it short).

Examples

The driver includes several examples in the examples directory.

A Simple Example

#include <cassandra.h>
#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

Copyright (c) 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.