SV* PLCB_op_set(PLCB_t *object, plcb_SINGLEOP *opinfo) { lcb_error_t err = LCB_SUCCESS; plcb_DOCVAL vspec = { 0 }; lcb_CMDSTORE scmd = { 0 }; key_from_so(opinfo, (lcb_CMDBASE *)&scmd); PLCB_args_set(object, opinfo, &scmd, &vspec); plcb_convert_storage(object, opinfo->docav, &vspec); if (vspec.encoded == NULL) { die("Invalid value!"); } LCB_CMD_SET_VALUE(&scmd, vspec.encoded, vspec.len); if (opinfo->cmdbase != PLCB_CMD_APPEND && opinfo->cmdbase != PLCB_CMD_PREPEND) { scmd.flags = vspec.flags; } scmd.operation = cmd_to_storop(opinfo->cmdbase); err = lcb_store3(object->instance, opinfo->cookie, &scmd); plcb_convert_storage_free(object, &vspec); return plcb_opctx_return(opinfo, err); }
static int handle_single_kv(pycbc_Bucket *self, struct pycbc_common_vars *cv, int optype, PyObject *curkey, PyObject *curvalue, PyObject *options, pycbc_Item *itm, void *arg) { int rv; const struct storecmd_vars *scv = (struct storecmd_vars *)arg; struct single_key_context skc = { NULL }; const void *key, *value; size_t nkey, nvalue; lcb_error_t err; lcb_CMDSTORE cmd = { 0 }; skc.ttl = scv->ttl; skc.flagsobj = scv->flagsobj; skc.value = curvalue; skc.cas = scv->single_cas; rv = pycbc_tc_encode_key(self, &curkey, (void**)&key, &nkey); if (rv < 0) { return -1; } if (!nkey) { PYCBC_EXCTHROW_EMPTYKEY(); rv = -1; goto GT_DONE; } if (itm) { rv = handle_item_kv(itm, options, scv, &skc); if (rv < 0) { return -1; } } rv = pycbc_tc_encode_value(self, &skc.value, skc.flagsobj, (void**)&value, &nvalue, &cmd.flags); if (rv < 0) { skc.value = NULL; rv = -1; goto GT_DONE; } if (scv->operation == LCB_APPEND || scv->operation == LCB_PREPEND) { /* The server ignores these flags and libcouchbase will throw an error * if the flags are present. We check elsewhere here to ensure that * only UTF8/BYTES are accepted for append/prepend anyway */ cmd.flags = 0; } LCB_CMD_SET_KEY(&cmd, key, nkey); LCB_CMD_SET_VALUE(&cmd, value, nvalue); cmd.cas = skc.cas; cmd.operation = scv->operation; cmd.exptime = skc.ttl; err = lcb_store3(self->instance, cv->mres, &cmd); if (err == LCB_SUCCESS) { rv = 0; } else { rv = -1; PYCBC_EXCTHROW_SCHED(err); } GT_DONE: Py_XDECREF(curkey); Py_XDECREF(skc.value); return rv; }