CassError insert_into_collections(CassSession* session, const char* key, const char* items[]) {
CassError rc = CASS_OK;
CassStatement* statement = NULL;
CassFuture* future = NULL;
CassCollection* collection = NULL;
const char** item = NULL;
const char* query = "INSERT INTO examples.collections (key, items) VALUES (?, ?);";
statement = cass_statement_new(query, 2);
cass_statement_bind_string(statement, 0, key);
collection = cass_collection_new(CASS_COLLECTION_TYPE_SET, 2);
for (item = items; *item; item++) {
cass_collection_append_string(collection, *item);
}
cass_statement_bind_collection(statement, 1, collection);
cass_collection_free(collection);
future = cass_session_execute(session, statement);
cass_future_wait(future);
rc = cass_future_error_code(future);
if (rc != CASS_OK) {
print_error(future);
}
cass_future_free(future);
cass_statement_free(statement);
return rc;
}
备忘!
标签:statement,bind,list,collection,char,item,future,cass From: https://blog.51cto.com/u_11908275/6382328