Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 3 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -442,22 +442,9 @@ elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
# Clang/Intel specific compiler options
# I disabled long-long warning because boost generates about 50 such warnings
set(WARNING_COMPILER_FLAGS "-Wall -pedantic -Wextra -Wno-long-long -Wno-unused-parameter -Wno-variadic-macros -Wno-zero-length-array")

# Detect if this is Apple's clang
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -v ERROR_VARIABLE CASS_CLANG_VERSION_INFO)
if (CASS_CLANG_VERSION_INFO MATCHES "^Apple LLVM")
set(CASS_IS_APPLE_CLANG 1)
else()
set(CASS_IS_APPLE_CLANG 0)
endif()

if(NOT CASS_IS_APPLE_CLANG AND
(${CMAKE_CXX_COMPILER_VERSION} VERSION_EQUAL "3.6" OR
${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER "3.6")
)
set(WARNING_COMPILER_FLAGS "${WARNING_COMPILER_FLAGS} -Wno-unused-local-typedef ")
endif()
set(WARNING_COMPILER_FLAGS "-Wall -pedantic -Wextra -Wno-long-long -Wno-unused-parameter")
set(WARNING_COMPILER_FLAGS "${WARNING_COMPILER_FLAGS} -Wno-variadic-macros -Wno-zero-length-array")
set(WARNING_COMPILER_FLAGS "${WARNING_COMPILER_FLAGS} -Wno-unused-local-typedef -Wno-unknown-warning-option")

# OpenSSL is deprecated on later versions of Mac OS X. The long-term solution
# is to provide a CommonCryto implementation.
Expand Down
117 changes: 63 additions & 54 deletions examples/schema_meta/schema_meta.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,38 @@
#include <stdio.h>
#include <cassandra.h>

void print_schema_meta(const CassSchemaMeta* meta, int indent);
void print_keyspace_meta(const CassKeyspaceMeta* meta, int indent);
void print_table_meta(const CassTableMeta* meta, int indent);

void print_keyspace(CassSession* session, const char* keyspace) {
const CassSchema* schema = cass_session_get_schema(session);
const CassSchemaMeta* keyspace_meta = cass_schema_get_keyspace(schema, keyspace);
const CassSchemaMeta* schema_meta = cass_session_get_schema_meta(session);
const CassKeyspaceMeta* keyspace_meta = cass_schema_meta_keyspace_by_name(schema_meta, keyspace);

if (keyspace_meta != NULL) {
print_schema_meta(keyspace_meta, 0);
print_keyspace_meta(keyspace_meta, 0);
} else {
fprintf(stderr, "Unable to find \"%s\" keyspace in the schema metadata\n", keyspace);
}

cass_schema_free(schema);
cass_schema_meta_free(schema_meta);
}

void print_table(CassSession* session, const char* keyspace, const char* table) {
const CassSchema* schema = cass_session_get_schema(session);
const CassSchemaMeta* keyspace_meta = cass_schema_get_keyspace(schema, keyspace);
const CassSchemaMeta* schema_meta = cass_session_get_schema_meta(session);
const CassKeyspaceMeta* keyspace_meta = cass_schema_meta_keyspace_by_name(schema_meta, keyspace);

if (keyspace_meta != NULL) {
const CassSchemaMeta* table_meta = cass_schema_meta_get_entry(keyspace_meta, table);
const CassTableMeta* table_meta = cass_keyspace_meta_table_by_name(keyspace_meta, table);
if (table_meta != NULL) {
print_schema_meta(table_meta, 0);
print_table_meta(table_meta, 0);
} else {
fprintf(stderr, "Unable to find \"%s\" table in the schema metadata\n", table);
}
} else {
fprintf(stderr, "Unable to find \"%s\" keyspace in the schema metadata\n", keyspace);
}

cass_schema_free(schema);
cass_schema_meta_free(schema_meta);
}

void print_error(CassFuture* future) {
Expand Down Expand Up @@ -129,9 +130,9 @@ int main() {
void print_schema_value(const CassValue* value);
void print_schema_list(const CassValue* value);
void print_schema_map(const CassValue* value);
void print_schema_meta_field(const CassSchemaMetaField* field, int indent);
void print_schema_meta_fields(const CassSchemaMeta* meta, int indent);
void print_schema_meta_entries(const CassSchemaMeta* meta, int indent);
void print_meta_field(const CassIterator* iterator, int indent);
void print_meta_fields(CassIterator* iterator, int indent);
void print_column_meta(const CassColumnMeta* meta, int indent);

void print_indent(int indent) {
int i;
Expand Down Expand Up @@ -227,69 +228,77 @@ void print_schema_map(const CassValue* value) {
cass_iterator_free(iterator);
}

void print_schema_meta_field(const CassSchemaMetaField* field, int indent) {
void print_meta_field(const CassIterator* iterator, int indent) {
const char* name;
size_t name_length;
const CassValue* value;

cass_schema_meta_field_name(field, &name, &name_length);
value = cass_schema_meta_field_value(field);
cass_iterator_get_meta_field_name(iterator, &name, &name_length);
value = cass_iterator_get_meta_field_value(iterator);

print_indent(indent);
printf("%.*s: ", (int)name_length, name);
print_schema_value(value);
printf("\n");
}

void print_schema_meta_fields(const CassSchemaMeta* meta, int indent) {
CassIterator* fields = cass_iterator_fields_from_schema_meta(meta);

while (cass_iterator_next(fields)) {
print_schema_meta_field(cass_iterator_get_schema_meta_field(fields), indent);
void print_meta_fields(CassIterator* iterator, int indent) {
while (cass_iterator_next(iterator)) {
print_meta_field(iterator, indent);
}
cass_iterator_free(fields);
cass_iterator_free(iterator);
}

void print_schema_meta_entries(const CassSchemaMeta* meta, int indent) {
CassIterator* entries = cass_iterator_from_schema_meta(meta);
void print_keyspace_meta(const CassKeyspaceMeta* meta, int indent) {
const char* name;
size_t name_length;
CassIterator* iterator;

print_indent(indent);
cass_keyspace_meta_name(meta, &name, &name_length);
printf("Keyspace \"%.*s\":\n", (int)name_length, name);

print_meta_fields(cass_iterator_fields_from_keyspace_meta(meta), indent + 1);
printf("\n");

while (cass_iterator_next(entries)) {
print_schema_meta(cass_iterator_get_schema_meta(entries), indent);
iterator = cass_iterator_tables_from_keyspace_meta(meta);
while (cass_iterator_next(iterator)) {
print_table_meta(cass_iterator_get_table_meta(iterator), indent + 1);
}
cass_iterator_free(entries);
printf("\n");

cass_iterator_free(iterator);
}

void print_schema_meta(const CassSchemaMeta* meta, int indent) {
const CassSchemaMetaField* field = NULL;
void print_table_meta(const CassTableMeta* meta, int indent) {
const char* name;
size_t name_length;
print_indent(indent);
CassIterator* iterator;

switch (cass_schema_meta_type(meta)) {
case CASS_SCHEMA_META_TYPE_KEYSPACE:
field = cass_schema_meta_get_field(meta, "keyspace_name");
cass_value_get_string(cass_schema_meta_field_value(field), &name, &name_length);
printf("Keyspace \"%.*s\":\n", (int)name_length, name);
print_schema_meta_fields(meta, indent + 1);
printf("\n");
print_schema_meta_entries(meta, indent + 1);
break;
print_indent(indent);
cass_table_meta_name(meta, &name, &name_length);
printf("Table \"%.*s\":\n", (int)name_length, name);

case CASS_SCHEMA_META_TYPE_TABLE:
field = cass_schema_meta_get_field(meta, "columnfamily_name");
cass_value_get_string(cass_schema_meta_field_value(field), &name, &name_length);
printf("Table \"%.*s\":\n", (int)name_length, name);
print_schema_meta_fields(meta, indent + 1);
printf("\n");
print_schema_meta_entries(meta, indent + 1);
break;
print_meta_fields(cass_iterator_fields_from_table_meta(meta), indent + 1);
printf("\n");

case CASS_SCHEMA_META_TYPE_COLUMN:
field = cass_schema_meta_get_field(meta, "column_name");
cass_value_get_string(cass_schema_meta_field_value(field), &name, &name_length);
printf("Column \"%.*s\":\n", (int)name_length, name);
print_schema_meta_fields(meta, indent + 1);
printf("\n");
break;
iterator = cass_iterator_columns_from_table_meta(meta);
while (cass_iterator_next(iterator)) {
print_column_meta(cass_iterator_get_column_meta(iterator), indent + 1);
}
printf("\n");

cass_iterator_free(iterator);
}

void print_column_meta(const CassColumnMeta* meta, int indent) {
const char* name;
size_t name_length;

print_indent(indent);
cass_column_meta_name(meta, &name, &name_length);
printf("Column \"%.*s\":\n", (int)name_length, name);
print_meta_fields(cass_iterator_fields_from_column_meta(meta), indent + 1);
printf("\n");
}

18 changes: 11 additions & 7 deletions examples/udt/udt.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include "cassandra.h"

CassUuidGen* uuid_gen;
const CassSchema* schema;
const CassSchemaMeta* schema_meta;

void print_error(CassFuture* future) {
const char* message;
Expand Down Expand Up @@ -88,6 +88,7 @@ CassError insert_into_udt(CassSession* session) {

CassUuid id;
char id_str[CASS_UUID_STRING_LENGTH];
const CassKeyspaceMeta* keyspace_meta = NULL;
const CassDataType* udt_address = NULL;
const CassDataType* udt_phone = NULL;

Expand All @@ -98,8 +99,11 @@ CassError insert_into_udt(CassSession* session) {
cass_uuid_gen_time(uuid_gen, &id);
cass_uuid_string(id, id_str);

udt_address = cass_schema_get_udt(schema, "examples", "address");
udt_phone = cass_schema_get_udt(schema, "examples", "phone_numbers");
keyspace_meta = cass_schema_meta_keyspace_by_name(schema_meta, "examples");
if (keyspace_meta != NULL) {
udt_address = cass_keyspace_meta_type_by_name(keyspace_meta, "address");
udt_phone = cass_keyspace_meta_type_by_name(keyspace_meta, "phone_numbers");
}

if (udt_address != NULL && udt_phone != NULL) {
int i;
Expand Down Expand Up @@ -168,7 +172,7 @@ CassError select_from_udt(CassSession* session) {
const CassRow* row = cass_iterator_get_row(rows);
const CassValue* id_value = cass_row_get_column_by_name(row, "id");
const CassValue* address_value = cass_row_get_column_by_name(row, "address");
CassIterator* fields = cass_iterator_from_user_type(address_value);
CassIterator* fields = cass_iterator_fields_from_user_type(address_value);

cass_value_get_uuid(id_value, &id);
cass_uuid_string(id, id_str);
Expand Down Expand Up @@ -197,7 +201,7 @@ CassError select_from_udt(CassSession* session) {
CassIterator* phone_numbers = cass_iterator_from_collection(field_value);
while (cass_iterator_next(phone_numbers)) {
const CassValue* phone_value = cass_iterator_get_value(phone_numbers);
CassIterator* phone_fields = cass_iterator_from_user_type(phone_value);
CassIterator* phone_fields = cass_iterator_fields_from_user_type(phone_value);
assert(cass_value_type(phone_value) == CASS_VALUE_TYPE_UDT);
while (cass_iterator_next(phone_fields)) {
const CassValue* phone_number_value = cass_iterator_get_user_type_field_value(phone_fields);
Expand Down Expand Up @@ -240,7 +244,7 @@ int main() {
return -1;
}

schema = cass_session_get_schema(session);
schema_meta = cass_session_get_schema_meta(session);

execute_query(session,
"CREATE KEYSPACE examples WITH replication = { \
Expand All @@ -266,7 +270,7 @@ int main() {
cass_session_free(session);

cass_uuid_gen_free(uuid_gen);
cass_schema_free(schema);
cass_schema_meta_free(schema_meta);

return 0;
}
Loading