mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-01 23:54:12 +08:00
mdbx-tools: use MDBX_ACCEDE to open DBI with custom comparators.
This commit is contained in:
parent
cefbe02130
commit
5e2067decd
13
src/core.c
13
src/core.c
@ -16284,8 +16284,9 @@ static int mdbx_dbi_bind(MDBX_txn *txn, const MDBX_dbi dbi, unsigned user_flags,
|
||||
*/
|
||||
if ((user_flags ^ txn->mt_dbs[dbi].md_flags) & PERSISTENT_FLAGS) {
|
||||
/* flags ara differs, check other conditions */
|
||||
if (!user_flags && (!keycmp || keycmp == txn->mt_dbxs[dbi].md_cmp) &&
|
||||
(!datacmp || datacmp == txn->mt_dbxs[dbi].md_dcmp)) {
|
||||
if ((!user_flags && (!keycmp || keycmp == txn->mt_dbxs[dbi].md_cmp) &&
|
||||
(!datacmp || datacmp == txn->mt_dbxs[dbi].md_dcmp)) ||
|
||||
user_flags == MDBX_ACCEDE) {
|
||||
/* no comparators were provided and flags are zero,
|
||||
* seems that is case #1 above */
|
||||
user_flags = txn->mt_dbs[dbi].md_flags;
|
||||
@ -16338,8 +16339,12 @@ int mdbx_dbi_open_ex(MDBX_txn *txn, const char *table_name, unsigned user_flags,
|
||||
if (unlikely(rc != MDBX_SUCCESS))
|
||||
goto early_bailout;
|
||||
|
||||
switch (user_flags &
|
||||
(MDBX_INTEGERDUP | MDBX_DUPFIXED | MDBX_DUPSORT | MDBX_REVERSEDUP)) {
|
||||
switch (user_flags & (MDBX_INTEGERDUP | MDBX_DUPFIXED | MDBX_DUPSORT |
|
||||
MDBX_REVERSEDUP | MDBX_ACCEDE)) {
|
||||
case MDBX_ACCEDE:
|
||||
if ((user_flags & MDBX_CREATE) == 0)
|
||||
break;
|
||||
__fallthrough /* fall through */;
|
||||
default:
|
||||
rc = MDBX_EINVAL;
|
||||
goto early_bailout;
|
||||
|
@ -1285,7 +1285,7 @@ typedef struct MDBX_node {
|
||||
/* mdbx_dbi_open() flags */
|
||||
#define VALID_FLAGS \
|
||||
(MDBX_REVERSEKEY | MDBX_DUPSORT | MDBX_INTEGERKEY | MDBX_DUPFIXED | \
|
||||
MDBX_INTEGERDUP | MDBX_REVERSEDUP | MDBX_CREATE)
|
||||
MDBX_INTEGERDUP | MDBX_REVERSEDUP | MDBX_CREATE | MDBX_ACCEDE)
|
||||
|
||||
/* max number of pages to commit in one writev() call */
|
||||
#define MDBX_COMMIT_PAGES 64
|
||||
|
@ -574,7 +574,7 @@ static int process_db(MDBX_dbi dbi_handle, char *dbi_name, visitor *handler,
|
||||
|
||||
if (dbi_handle == ~0u) {
|
||||
rc = mdbx_dbi_open_ex(
|
||||
txn, dbi_name, 0, &dbi_handle,
|
||||
txn, dbi_name, MDBX_ACCEDE, &dbi_handle,
|
||||
(dbi_name && ignore_wrong_order) ? equal_or_greater : nullptr,
|
||||
(dbi_name && ignore_wrong_order) ? equal_or_greater : nullptr);
|
||||
if (rc) {
|
||||
|
@ -356,7 +356,7 @@ int main(int argc, char *argv[]) {
|
||||
goto env_close;
|
||||
}
|
||||
|
||||
rc = mdbx_dbi_open(txn, subname, 0, &dbi);
|
||||
rc = mdbx_dbi_open(txn, subname, MDBX_ACCEDE, &dbi);
|
||||
if (unlikely(rc != MDBX_SUCCESS)) {
|
||||
error("mdbx_dbi_open", rc);
|
||||
goto txn_abort;
|
||||
@ -394,7 +394,7 @@ int main(int argc, char *argv[]) {
|
||||
subname[key.iov_len] = '\0';
|
||||
|
||||
MDBX_dbi sub_dbi;
|
||||
rc = mdbx_dbi_open_ex(txn, subname, 0, &sub_dbi,
|
||||
rc = mdbx_dbi_open_ex(txn, subname, MDBX_ACCEDE, &sub_dbi,
|
||||
rescue ? equal_or_greater : nullptr,
|
||||
rescue ? equal_or_greater : nullptr);
|
||||
if (unlikely(rc != MDBX_SUCCESS)) {
|
||||
|
@ -396,7 +396,7 @@ int main(int argc, char *argv[]) {
|
||||
printf(" GC: %" PRIaPGNO " pages\n", pages);
|
||||
}
|
||||
|
||||
rc = mdbx_dbi_open(txn, subname, 0, &dbi);
|
||||
rc = mdbx_dbi_open(txn, subname, MDBX_ACCEDE, &dbi);
|
||||
if (unlikely(rc != MDBX_SUCCESS)) {
|
||||
error("mdbx_dbi_open", rc);
|
||||
goto txn_abort;
|
||||
@ -426,7 +426,7 @@ int main(int argc, char *argv[]) {
|
||||
subname = mdbx_malloc(key.iov_len + 1);
|
||||
memcpy(subname, key.iov_base, key.iov_len);
|
||||
subname[key.iov_len] = '\0';
|
||||
rc = mdbx_dbi_open(txn, subname, 0, &subdbi);
|
||||
rc = mdbx_dbi_open(txn, subname, MDBX_ACCEDE, &subdbi);
|
||||
if (rc == MDBX_SUCCESS)
|
||||
printf("Status of %s\n", subname);
|
||||
mdbx_free(subname);
|
||||
|
Loading…
x
Reference in New Issue
Block a user