From e28d223d42ff5e52866f24fbb95d47fea3665070 Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Wed, 13 May 2020 00:10:58 +0300 Subject: [PATCH] mdbx: fix MDBX_NODUPDATA handling for key-value data. More for https://github.com/erthink/libmdbx/issues/99 in continue to 9428efd2ae9f7fe984422b5eb1fc47f732236b51 Change-Id: I56050ddf5e56807a11d8613780c3ba76cc16d324 --- src/core.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/core.c b/src/core.c index c11f8b04..d7e4aaf1 100644 --- a/src/core.c +++ b/src/core.c @@ -12023,10 +12023,12 @@ int mdbx_cursor_put(MDBX_cursor *mc, const MDBX_val *key, MDBX_val *data, if (exact) { if (mc->mc_flags & C_SUB) { mdbx_assert(env, data->iov_len == 0 && olddata.iov_len == 0); - return rc; + return (flags & MDBX_NODUPDATA) ? MDBX_KEYEXIST : MDBX_SUCCESS; } - if (!(flags & MDBX_RESERVE) && mc->mc_dbx->md_dcmp(data, &olddata) == 0) - return rc; + if (!(flags & MDBX_RESERVE) && + unlikely(mc->mc_dbx->md_dcmp(data, &olddata) == 0)) + return ((flags & MDBX_NODUPDATA) && mc->mc_xcursor) ? MDBX_KEYEXIST + : MDBX_SUCCESS; } } else if (unlikely(rc != MDBX_NOTFOUND)) return rc;