Shows how to work with XATTRs using subdocument API.
#include <unistd.h>
#include <stdlib.h>
#include <libcouchbase/n1ql.h>
#include <assert.h>
#include <string.h>
{
return;
}
switch (type) {
size_t iter = 0;
size_t index = 0;
return;
}
if (index == 1) {
printf(
" * %.*s: %.*s%%\n", (
int)resp->nkey, resp->key, (
int)ent.
nvalue, ent.
value);
}
index++;
}
break;
}
case LCB_CALLBACK_SDMUTATE: {
size_t iter = 0;
size_t oix = 0;
size_t index = oix++;
if (type == LCB_CALLBACK_SDMUTATE) {
}
}
break;
}
}
}
{
printf(
"Failure: 0x%x, %s\n", resp->rc,
lcb_strerror(instance, resp->rc));
{
for (; hdr && *hdr; hdr++) {
printf("%s", *hdr);
if (hdr + 1) {
printf(" = %s", *(++hdr));
}
printf("\n");
}
}
printf(
"%.*s\n", (
int)resp->
nrow, resp->
row);
return;
}
char *start = "{\"docID\":\"";
char *stop = "\"";
char *key = strstr(resp->
row, start);
if (key == NULL || key != resp->
row) {
return;
}
key += strlen(start);
char *z = strstr(key, stop);
if (z == NULL) {
return;
}
*z = '\0';
{
lcb_CMDSUBDOC cmd = {};
char *path = "discounts.jsmith123";
cmd.specs = specs;
cmd.nspecs = 2;
}
}
#define DEFAULT_CONNSTR "couchbase://localhost/travel-sample"
static lcb_t connect_as(
char *username,
char *password)
{
return instance;
}
int main()
{
instance = connect_as("Administrator", "password");
{
lcb_CMDSUBDOC cmd = {};
char *key = "hotel_10138";
{
char *path = "discounts.jsmith123";
char *val = "20";
}
{
char *path = "discounts.pjones356";
char *val = "30";
}
{
char *path = "discounts.jbrown789";
char *val = "25";
}
{
char *path = "discounts.jbrown789";
}
cmd.specs = specs;
cmd.nspecs = 4;
}
{
lcb_CMDSUBDOC cmd = {};
char *key = "hotel_10142";
{
char *path = "discounts.jsmith123";
char *val = "15";
}
{
char *path = "discounts.pjones356";
char *val = "10";
}
cmd.specs = specs;
cmd.nspecs = 2;
}
{
char *path = "/settings/rbac/users/local/jsmith123";
char *payload = "password=jsmith123pwd&name=John+Smith"
"&roles=data_reader[travel-sample],query_select[travel-sample],data_writer[travel-sample]";
cmd.
method = LCB_HTTP_METHOD_PUT;
cmd.
nbody = strlen(payload);
}
instance = connect_as("jsmith123", "jsmith123pwd");
{
char *query = "SELECT id, meta(`travel-sample`).id AS docID FROM `travel-sample`";
printf("User \"jsmith123\" has discounts in the hotels below:\n");
}
}