mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-04 17:54:13 +08:00
mdbx: add mdbx_get2() for testing.
Change-Id: Icd0961e464936fa2d24fd3ed87b61de038e955c2
This commit is contained in:
parent
940138fbda
commit
68fd9c9908
2
mdbx.h
2
mdbx.h
@ -1246,6 +1246,8 @@ LIBMDBX_API int mdbx_drop(MDBX_txn *txn, MDBX_dbi dbi, int del);
|
|||||||
* - MDBX_EINVAL - an invalid parameter was specified. */
|
* - MDBX_EINVAL - an invalid parameter was specified. */
|
||||||
LIBMDBX_API int mdbx_get(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key,
|
LIBMDBX_API int mdbx_get(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key,
|
||||||
MDBX_val *data);
|
MDBX_val *data);
|
||||||
|
LIBMDBX_API int mdbx_get2(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key,
|
||||||
|
MDBX_val *data);
|
||||||
|
|
||||||
/* Store items into a database.
|
/* Store items into a database.
|
||||||
*
|
*
|
||||||
|
35
src/mdbx.c
35
src/mdbx.c
@ -7153,6 +7153,41 @@ int mdbx_get(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data) {
|
|||||||
return mdbx_cursor_set(&cx.outer, key, data, MDBX_SET, &exact);
|
return mdbx_cursor_set(&cx.outer, key, data, MDBX_SET, &exact);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int mdbx_get2(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data) {
|
||||||
|
int exact = 0;
|
||||||
|
DKBUF;
|
||||||
|
|
||||||
|
mdbx_debug("===> get db %u key [%s]", dbi, DKEY(key));
|
||||||
|
|
||||||
|
if (unlikely(!key || !data || !txn))
|
||||||
|
return MDBX_EINVAL;
|
||||||
|
|
||||||
|
if (unlikely(txn->mt_signature != MDBX_MT_SIGNATURE))
|
||||||
|
return MDBX_EBADSIGN;
|
||||||
|
|
||||||
|
if (unlikely(txn->mt_owner != mdbx_thread_self()))
|
||||||
|
return MDBX_THREAD_MISMATCH;
|
||||||
|
|
||||||
|
if (unlikely(!TXN_DBI_EXIST(txn, dbi, DB_USRVALID)))
|
||||||
|
return MDBX_EINVAL;
|
||||||
|
|
||||||
|
if (unlikely(txn->mt_flags & MDBX_TXN_BLOCKED))
|
||||||
|
return MDBX_BAD_TXN;
|
||||||
|
|
||||||
|
MDBX_cursor_couple cx;
|
||||||
|
int rc = mdbx_cursor_init(&cx.outer, txn, dbi);
|
||||||
|
if (unlikely(rc != MDBX_SUCCESS))
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
const int op =
|
||||||
|
(txn->mt_dbs[dbi].md_flags & MDBX_DUPSORT) ? MDBX_GET_BOTH : MDBX_SET_KEY;
|
||||||
|
rc = mdbx_cursor_set(&cx.outer, key, data, op, &exact);
|
||||||
|
if (unlikely(rc != MDBX_SUCCESS))
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
return exact ? MDBX_SUCCESS : MDBX_RESULT_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
/* Find a sibling for a page.
|
/* Find a sibling for a page.
|
||||||
* Replaces the page at the top of the cursor's stack with the specified
|
* Replaces the page at the top of the cursor's stack with the specified
|
||||||
* sibling, if one exists.
|
* sibling, if one exists.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user