| /* |
| This is free and unencumbered software released into the public domain. |
| |
| Anyone is free to copy, modify, publish, use, compile, sell, or |
| distribute this software, either in source code form or as a compiled |
| binary, for any purpose, commercial or non-commercial, and by any |
| means. |
| |
| In jurisdictions that recognize copyright laws, the author or authors |
| of this software dedicate any and all copyright interest in the |
| software to the public domain. We make this dedication for the benefit |
| of the public at large and to the detriment of our heirs and |
| successors. We intend this dedication to be an overt act of |
| relinquishment in perpetuity of all present and future rights to this |
| software under copyright law. |
| |
| 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. |
| |
| For more information, please refer to <http://unlicense.org/> |
| */ |
| |
| #include <cassandra.h> |
| #include <stdio.h> |
| |
| int main(int argc, char* argv[]) { |
| /* Setup and connect to cluster */ |
| CassFuture* connect_future = NULL; |
| CassCluster* cluster; |
| CassSession* session; |
| |
| const char* secure_connect_bundle; |
| const char* username; |
| const char* password; |
| |
| if (argc < 4) { |
| fprintf(stderr, "Usage: %s <secure connect bundle zip> <username> <password>\n", argv[0]); |
| return 1; |
| } |
| |
| secure_connect_bundle = argv[1]; |
| username = argv[2]; |
| password = argv[3]; |
| |
| cluster = cass_cluster_new(); |
| session = cass_session_new(); |
| |
| /* Setup driver to connect to the cloud using the secure connection bundle */ |
| if (cass_cluster_set_cloud_secure_connection_bundle(cluster, secure_connect_bundle) != CASS_OK) { |
| fprintf(stderr, "Unable to configure cloud using the secure connection bundle: %s\n", |
| secure_connect_bundle); |
| } |
| |
| cass_cluster_set_credentials(cluster, username, password); |
| |
| /* 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) { |
| /* 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); |
| } 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; |
| } |