Esempio n. 1
0
CassError insert_into_maps(CassSession* session, const char* key, const Pair items[]) {
  CassError rc = CASS_OK;
  CassStatement* statement = NULL;
  CassFuture* future = NULL;
  CassCollection* collection = NULL;
  const Pair* item = NULL;
  const char* query = "INSERT INTO examples.maps (key, items) VALUES (?, ?);";

  statement = cass_statement_new(query, 2);

  cass_statement_bind_string(statement, 0, key);

  collection = cass_collection_new(CASS_COLLECTION_TYPE_MAP, 5);
  for (item = items; item->key; item++) {
    cass_collection_append_string(collection, item->key);
    cass_collection_append_int32(collection, item->value);
  }
  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;
}
Esempio n. 2
0
 static CassError append(CassCollection* collection, cass_int32_t value) {
   return cass_collection_append_int32(collection, value);
 }