mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-30 22:47:16 +08:00
mdbx: add mdbx_cursor_copy()
.
Change-Id: I476f1230beec6a550897bef236745530154c1079
This commit is contained in:
parent
2489e0ba6e
commit
b6f0070f85
12
mdbx.h
12
mdbx.h
@ -3861,6 +3861,18 @@ mdbx_cursor_txn(const MDBX_cursor *cursor);
|
|||||||
* \param [in] cursor A cursor handle returned by \ref mdbx_cursor_open(). */
|
* \param [in] cursor A cursor handle returned by \ref mdbx_cursor_open(). */
|
||||||
LIBMDBX_API MDBX_dbi mdbx_cursor_dbi(const MDBX_cursor *cursor);
|
LIBMDBX_API MDBX_dbi mdbx_cursor_dbi(const MDBX_cursor *cursor);
|
||||||
|
|
||||||
|
/** \brief Copy cursor position and state.
|
||||||
|
* \ingroup c_cursors
|
||||||
|
*
|
||||||
|
* \param [in] src A source cursor handle returned
|
||||||
|
* by \ref mdbx_cursor_create() or \ref mdbx_cursor_open().
|
||||||
|
*
|
||||||
|
* \param [in,out] dest A destination cursor handle returned
|
||||||
|
* by \ref mdbx_cursor_create() or \ref mdbx_cursor_open().
|
||||||
|
*
|
||||||
|
* \returns A non-zero error value on failure and 0 on success. */
|
||||||
|
LIBMDBX_API int mdbx_cursor_copy(const MDBX_cursor *src, MDBX_cursor *dest);
|
||||||
|
|
||||||
/** \brief Retrieve by cursor.
|
/** \brief Retrieve by cursor.
|
||||||
* \ingroup c_crud
|
* \ingroup c_crud
|
||||||
*
|
*
|
||||||
|
28
src/core.c
28
src/core.c
@ -14140,6 +14140,34 @@ int mdbx_cursor_renew(MDBX_txn *txn, MDBX_cursor *mc) {
|
|||||||
return likely(mc) ? mdbx_cursor_bind(txn, mc, mc->mc_dbi) : MDBX_EINVAL;
|
return likely(mc) ? mdbx_cursor_bind(txn, mc, mc->mc_dbi) : MDBX_EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int mdbx_cursor_copy(const MDBX_cursor *src, MDBX_cursor *dest) {
|
||||||
|
if (unlikely(!src))
|
||||||
|
return MDBX_EINVAL;
|
||||||
|
if (unlikely(src->mc_signature != MDBX_MC_LIVE))
|
||||||
|
return MDBX_EBADSIGN;
|
||||||
|
|
||||||
|
int rc = mdbx_cursor_bind(src->mc_txn, dest, src->mc_dbi);
|
||||||
|
if (unlikely(rc != MDBX_SUCCESS))
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
again:
|
||||||
|
dest->mc_flags ^= (dest->mc_flags ^ src->mc_flags) & ~C_UNTRACK;
|
||||||
|
dest->mc_top = src->mc_top;
|
||||||
|
dest->mc_snum = src->mc_snum;
|
||||||
|
for (unsigned i = 0; i < src->mc_snum; ++i) {
|
||||||
|
dest->mc_ki[i] = src->mc_ki[i];
|
||||||
|
dest->mc_pg[i] = src->mc_pg[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (src->mc_xcursor) {
|
||||||
|
src = &src->mc_xcursor->mx_cursor;
|
||||||
|
dest = &dest->mc_xcursor->mx_cursor;
|
||||||
|
goto again;
|
||||||
|
}
|
||||||
|
|
||||||
|
return MDBX_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
/* Return the count of duplicate data items for the current key */
|
/* Return the count of duplicate data items for the current key */
|
||||||
int mdbx_cursor_count(const MDBX_cursor *mc, size_t *countp) {
|
int mdbx_cursor_count(const MDBX_cursor *mc, size_t *countp) {
|
||||||
if (unlikely(mc == NULL))
|
if (unlikely(mc == NULL))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user