cassandra cpp driver中bind list——用cass_statement_bind_collection函数

 

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;
}

备忘!

posted @ 2017-03-14 15:50  bonelee  阅读(546)  评论(0编辑  收藏  举报