Typedefs | |
| typedef struct MDBX_cursor | MDBX_cursor |
| Opaque structure for navigating through a table. | |
Enumerations | |
| enum | MDBX_cursor_op { MDBX_FIRST , MDBX_FIRST_DUP , MDBX_GET_BOTH , MDBX_GET_BOTH_RANGE , MDBX_GET_CURRENT , MDBX_GET_MULTIPLE , MDBX_LAST , MDBX_LAST_DUP , MDBX_NEXT , MDBX_NEXT_DUP , MDBX_NEXT_MULTIPLE , MDBX_NEXT_NODUP , MDBX_PREV , MDBX_PREV_DUP , MDBX_PREV_NODUP , MDBX_SET , MDBX_SET_KEY , MDBX_SET_RANGE , MDBX_PREV_MULTIPLE , MDBX_SET_LOWERBOUND , MDBX_SET_UPPERBOUND , MDBX_TO_KEY_LESSER_THAN , MDBX_TO_KEY_LESSER_OR_EQUAL , MDBX_TO_KEY_EQUAL , MDBX_TO_KEY_GREATER_OR_EQUAL , MDBX_TO_KEY_GREATER_THAN , MDBX_TO_EXACT_KEY_VALUE_LESSER_THAN , MDBX_TO_EXACT_KEY_VALUE_LESSER_OR_EQUAL , MDBX_TO_EXACT_KEY_VALUE_EQUAL , MDBX_TO_EXACT_KEY_VALUE_GREATER_OR_EQUAL , MDBX_TO_EXACT_KEY_VALUE_GREATER_THAN , MDBX_TO_PAIR_LESSER_THAN , MDBX_TO_PAIR_LESSER_OR_EQUAL , MDBX_TO_PAIR_EQUAL , MDBX_TO_PAIR_GREATER_OR_EQUAL , MDBX_TO_PAIR_GREATER_THAN , MDBX_SEEK_AND_GET_MULTIPLE } |
| Cursor operationsThis is the set of all operations for retrieving data using a cursor. More... | |
Functions | |
| LIBMDBX_API MDBX_cursor * | mdbx_cursor_create (void *context) |
| Create a cursor handle but not bind it to transaction nor DBI-handle. | |
| LIBMDBX_API int | mdbx_cursor_set_userctx (MDBX_cursor *cursor, void *ctx) |
| Set application information associated with the cursor. | |
| LIBMDBX_API void * | mdbx_cursor_get_userctx (const MDBX_cursor *cursor) |
| Get the application information associated with the MDBX_cursor. | |
| LIBMDBX_API int | mdbx_cursor_bind (MDBX_txn *txn, MDBX_cursor *cursor, MDBX_dbi dbi) |
| Bind cursor to specified transaction and DBI-handle. | |
| LIBMDBX_API int | mdbx_cursor_unbind (MDBX_cursor *cursor) |
| Unbind cursor from a transaction. | |
| LIBMDBX_API int | mdbx_cursor_reset (MDBX_cursor *cursor) |
| Resets the cursor state. | |
| LIBMDBX_API int | mdbx_cursor_open (MDBX_txn *txn, MDBX_dbi dbi, MDBX_cursor **cursor) |
| Create a cursor handle for the specified transaction and DBI handle. | |
| LIBMDBX_API void | mdbx_cursor_close (MDBX_cursor *cursor) |
| Closes a cursor handle without returning error code. | |
| LIBMDBX_API int | mdbx_cursor_close2 (MDBX_cursor *cursor) |
| Closes a cursor handle with returning error code. | |
| LIBMDBX_API int | mdbx_txn_release_all_cursors_ex (const MDBX_txn *txn, bool unbind, size_t *count) |
| Unbind or closes all cursors of a given transaction and of all its parent transactions if ones are. | |
| int | mdbx_txn_release_all_cursors (const MDBX_txn *txn, bool unbind) |
| Unbind or closes all cursors of a given transaction and of all its parent transactions if ones are. | |
| LIBMDBX_API int | mdbx_cursor_renew (MDBX_txn *txn, MDBX_cursor *cursor) |
| Renew a cursor handle for use within the given transaction. | |
| LIBMDBX_API MDBX_txn * | mdbx_cursor_txn (const MDBX_cursor *cursor) |
| Return the cursor's transaction handle. | |
| LIBMDBX_API MDBX_dbi | mdbx_cursor_dbi (const MDBX_cursor *cursor) |
| Return the cursor's table handle. | |
| LIBMDBX_API int | mdbx_cursor_copy (const MDBX_cursor *src, MDBX_cursor *dest) |
| Copy cursor position and state. | |
| LIBMDBX_API int | mdbx_cursor_compare (const MDBX_cursor *left, const MDBX_cursor *right, bool ignore_multival) |
| Compares the position of the cursors. | |
| LIBMDBX_API int | mdbx_cursor_eof (const MDBX_cursor *cursor) |
| Determines whether the cursor is pointed to a key-value pair or not, i.e. was not positioned or points to the end of data. | |
| LIBMDBX_API int | mdbx_cursor_on_first (const MDBX_cursor *cursor) |
| Determines whether the cursor is pointed to the first key-value pair or not. | |
| LIBMDBX_API int | mdbx_cursor_on_first_dup (const MDBX_cursor *cursor) |
| Determines whether the cursor is on the first or single multi-value corresponding to the key. | |
| LIBMDBX_API int | mdbx_cursor_on_last (const MDBX_cursor *cursor) |
| Determines whether the cursor is pointed to the last key-value pair or not. | |
| LIBMDBX_API int | mdbx_cursor_on_last_dup (const MDBX_cursor *cursor) |
| Determines whether the cursor is on the last or single multi-value corresponding to the key. | |
| typedef struct MDBX_cursor MDBX_cursor |
Opaque structure for navigating through a table.
| enum MDBX_cursor_op |
Cursor operationsThis is the set of all operations for retrieving data using a cursor.
| Enumerator | |
|---|---|
| MDBX_FIRST | Position at first key/data item |
| MDBX_FIRST_DUP | MDBX_DUPSORT -only: Position at first data item of current key. |
| MDBX_GET_BOTH | MDBX_DUPSORT -only: Position at key/data pair. |
| MDBX_GET_BOTH_RANGE | MDBX_DUPSORT -only: Position at given key and at first data greater than or equal to specified data. |
| MDBX_GET_CURRENT | Return key/data at current cursor position |
| MDBX_GET_MULTIPLE | MDBX_DUPFIXED -only: Return up to a page of duplicate data items from current cursor position. Move cursor to prepare for MDBX_NEXT_MULTIPLE.
|
| MDBX_LAST | Position at last key/data item |
| MDBX_LAST_DUP | MDBX_DUPSORT -only: Position at last data item of current key. |
| MDBX_NEXT | Position at next data item |
| MDBX_NEXT_DUP | MDBX_DUPSORT -only: Position at next data item of current key. |
| MDBX_NEXT_MULTIPLE | MDBX_DUPFIXED -only: Return up to a page of duplicate data items from next cursor position. Move cursor to prepare for MDBX_NEXT_MULTIPLE. |
| MDBX_NEXT_NODUP | Position at first data item of next key |
| MDBX_PREV | Position at previous data item |
| MDBX_PREV_DUP | MDBX_DUPSORT -only: Position at previous data item of current key. |
| MDBX_PREV_NODUP | Position at last data item of previous key |
| MDBX_SET | Position at specified key |
| MDBX_SET_KEY | Position at specified key, return both key and data |
| MDBX_SET_RANGE | Position at first key greater than or equal to specified key. |
| MDBX_PREV_MULTIPLE | MDBX_DUPFIXED -only: Position at previous page and return up to a page of duplicate data items. |
| MDBX_SET_LOWERBOUND | Positions cursor at first key-value pair greater than or equal to specified, return both key and data, and the return code depends on whether a exact match. For non DUPSORT-ed collections this work the same to MDBX_SET_RANGE, but returns MDBX_SUCCESS if key found exactly or MDBX_RESULT_TRUE if greater key was found. For DUPSORT-ed a data value is taken into account for duplicates, i.e. for a pairs/tuples of a key and an each data value of duplicates. Returns MDBX_SUCCESS if key-value pair found exactly or MDBX_RESULT_TRUE if the next pair was returned. |
| MDBX_SET_UPPERBOUND | Positions cursor at first key-value pair greater than specified, return both key and data, and the return code depends on whether a upper-bound was found. For non DUPSORT-ed collections this work like MDBX_SET_RANGE, but returns MDBX_SUCCESS if the greater key was found or MDBX_NOTFOUND otherwise. For DUPSORT-ed a data value is taken into account for duplicates, i.e. for a pairs/tuples of a key and an each data value of duplicates. Returns MDBX_SUCCESS if the greater pair was returned or MDBX_NOTFOUND otherwise. |
| MDBX_TO_KEY_LESSER_THAN | Doubtless cursor positioning at a specified key. |
| MDBX_TO_KEY_LESSER_OR_EQUAL | Doubtless cursor positioning at a specified key. |
| MDBX_TO_KEY_EQUAL | Doubtless cursor positioning at a specified key. |
| MDBX_TO_KEY_GREATER_OR_EQUAL | Doubtless cursor positioning at a specified key. |
| MDBX_TO_KEY_GREATER_THAN | Doubtless cursor positioning at a specified key. |
| MDBX_TO_EXACT_KEY_VALUE_LESSER_THAN | Doubtless cursor positioning at a specified key-value pair for dupsort/multi-value hives. |
| MDBX_TO_EXACT_KEY_VALUE_LESSER_OR_EQUAL | Doubtless cursor positioning at a specified key-value pair for dupsort/multi-value hives. |
| MDBX_TO_EXACT_KEY_VALUE_EQUAL | Doubtless cursor positioning at a specified key-value pair for dupsort/multi-value hives. |
| MDBX_TO_EXACT_KEY_VALUE_GREATER_OR_EQUAL | Doubtless cursor positioning at a specified key-value pair for dupsort/multi-value hives. |
| MDBX_TO_EXACT_KEY_VALUE_GREATER_THAN | Doubtless cursor positioning at a specified key-value pair for dupsort/multi-value hives. |
| MDBX_TO_PAIR_LESSER_THAN | Doubtless cursor positioning at a specified key-value pair for dupsort/multi-value hives. |
| MDBX_TO_PAIR_LESSER_OR_EQUAL | Doubtless cursor positioning at a specified key-value pair for dupsort/multi-value hives. |
| MDBX_TO_PAIR_EQUAL | Doubtless cursor positioning at a specified key-value pair for dupsort/multi-value hives. |
| MDBX_TO_PAIR_GREATER_OR_EQUAL | Doubtless cursor positioning at a specified key-value pair for dupsort/multi-value hives. |
| MDBX_TO_PAIR_GREATER_THAN | Doubtless cursor positioning at a specified key-value pair for dupsort/multi-value hives. |
| MDBX_SEEK_AND_GET_MULTIPLE | MDBX_DUPFIXED -only: Seek to given key and return up to a page of duplicate data items from current cursor position. Move cursor to prepare for MDBX_NEXT_MULTIPLE.
|
| LIBMDBX_API int mdbx_cursor_bind | ( | MDBX_txn * | txn, |
| MDBX_cursor * | cursor, | ||
| MDBX_dbi | dbi ) |
Bind cursor to specified transaction and DBI-handle.
Using of the mdbx_cursor_bind() is equivalent to calling mdbx_cursor_renew() but with specifying an arbitrary DBI-handle.
A cursor may be associated with a new transaction, and referencing a new or the same table handle as it was created with. This may be done whether the previous transaction is live or dead.
If the transaction is nested, then the cursor should not be used in its parent transaction. Otherwise it is no way to restore state if this nested transaction will be aborted, nor impossible to define the expected behavior.
| [in] | txn | A transaction handle returned by mdbx_txn_begin(). |
| [in] | dbi | A table handle returned by mdbx_dbi_open(). |
| [in] | cursor | A cursor handle returned by mdbx_cursor_create(). |
| MDBX_THREAD_MISMATCH | Given transaction is not owned by current thread. |
| MDBX_EINVAL | An invalid parameter was specified. |
| LIBMDBX_API void mdbx_cursor_close | ( | MDBX_cursor * | cursor | ) |
Closes a cursor handle without returning error code.
The cursor handle will be freed and must not be used again after this call, but its transaction may still be live.
This function returns void but panic in case of error. Use mdbx_cursor_close2() if you need to receive an error code instead of an app crash.
| [in] | cursor | A cursor handle returned by mdbx_cursor_open() or mdbx_cursor_create(). |
| LIBMDBX_API int mdbx_cursor_close2 | ( | MDBX_cursor * | cursor | ) |
Closes a cursor handle with returning error code.
The cursor handle will be freed and must not be used again after this call, but its transaction may still be live.
| [in] | cursor | A cursor handle returned by mdbx_cursor_open() or mdbx_cursor_create(). |
| MDBX_THREAD_MISMATCH | Given transaction is not owned by current thread. |
| MDBX_EINVAL | An invalid parameter was specified. |
| LIBMDBX_API int mdbx_cursor_compare | ( | const MDBX_cursor * | left, |
| const MDBX_cursor * | right, | ||
| bool | ignore_multival ) |
Compares the position of the cursors.
This function is intended to compare the positions of two cursors associated with the same transaction and the same table (DBI descriptor). If the cursors are associated with different transactions, or with different tables, or one of them is not initialized, then the result of the comparison is undefined (the behavior may be changed in subsequent versions).
| [in] | left | A left cursor for comparing positions. |
| [in] | right | A right cursor for comparing positions. |
| [in] | ignore_multival | A boolean option that affects the result only when comparing cursors for tables with multi-values, i.e. with the MDBX_DUPSORT flag. In the case of true, cursor positions are compared only by keys, without taking into account positioning among multi-values. Otherwise, in the case of false, if the key positions match, the multi-value positions are also compared. |
| A | signed value in the semantics of the operator <=> (less than zero, zero, or greater than zero) as a result of comparing cursor positions. |
| LIBMDBX_API int mdbx_cursor_copy | ( | const MDBX_cursor * | src, |
| MDBX_cursor * | dest ) |
Copy cursor position and state.
| [in] | src | A source cursor handle returned by mdbx_cursor_create() or mdbx_cursor_open(). |
| [in,out] | dest | A destination cursor handle returned by mdbx_cursor_create() or mdbx_cursor_open(). |
| LIBMDBX_API MDBX_cursor * mdbx_cursor_create | ( | void * | context | ) |
Create a cursor handle but not bind it to transaction nor DBI-handle.
A cursor cannot be used when its table handle is closed. Nor when its transaction has ended, except with mdbx_cursor_bind() and mdbx_cursor_renew(). Also it can be discarded with mdbx_cursor_close().
A cursor must be closed explicitly always, before or after its transaction ends. It can be reused with mdbx_cursor_bind() or mdbx_cursor_renew() before finally closing it.
| [in] | context | A pointer to application context to be associated with created cursor and could be retrieved by mdbx_cursor_get_userctx() until cursor closed. |
| LIBMDBX_API MDBX_dbi mdbx_cursor_dbi | ( | const MDBX_cursor * | cursor | ) |
Return the cursor's table handle.
| [in] | cursor | A cursor handle returned by mdbx_cursor_open(). |
| LIBMDBX_API int mdbx_cursor_eof | ( | const MDBX_cursor * | cursor | ) |
Determines whether the cursor is pointed to a key-value pair or not, i.e. was not positioned or points to the end of data.
| [in] | cursor | A cursor handle returned by mdbx_cursor_open(). |
| MDBX_RESULT_TRUE | No more data available or cursor not positioned |
| MDBX_RESULT_FALSE | A data is available |
| OTHERWISE | the error code |
| LIBMDBX_API void * mdbx_cursor_get_userctx | ( | const MDBX_cursor * | cursor | ) |
Get the application information associated with the MDBX_cursor.
| [in] | cursor | An cursor handle returned by mdbx_cursor_create() or mdbx_cursor_open(). |
| LIBMDBX_API int mdbx_cursor_on_first | ( | const MDBX_cursor * | cursor | ) |
Determines whether the cursor is pointed to the first key-value pair or not.
| [in] | cursor | A cursor handle returned by mdbx_cursor_open(). |
| MDBX_RESULT_TRUE | Cursor positioned to the first key-value pair |
| MDBX_RESULT_FALSE | Cursor NOT positioned to the first key-value pair |
| OTHERWISE | the error code |
| LIBMDBX_API int mdbx_cursor_on_first_dup | ( | const MDBX_cursor * | cursor | ) |
Determines whether the cursor is on the first or single multi-value corresponding to the key.
| [in] | cursor | A cursor handle returned by mdbx_cursor_open(). |
| MDBX_RESULT_TRUE | The cursor is positioned to the first or single multi-value corresponding to the key. |
| MDBX_RESULT_FALSE | The cursor is NOT positioned to the first or single multi-value corresponding to the key. |
| OTHERWISE | the error code |
| LIBMDBX_API int mdbx_cursor_on_last | ( | const MDBX_cursor * | cursor | ) |
Determines whether the cursor is pointed to the last key-value pair or not.
| [in] | cursor | A cursor handle returned by mdbx_cursor_open(). |
| MDBX_RESULT_TRUE | Cursor positioned to the last key-value pair |
| MDBX_RESULT_FALSE | Cursor NOT positioned to the last key-value pair |
| OTHERWISE | the error code |
| LIBMDBX_API int mdbx_cursor_on_last_dup | ( | const MDBX_cursor * | cursor | ) |
Determines whether the cursor is on the last or single multi-value corresponding to the key.
| [in] | cursor | A cursor handle returned by mdbx_cursor_open(). |
| MDBX_RESULT_TRUE | The cursor is positioned to the last or single multi-value corresponding to the key. |
| MDBX_RESULT_FALSE | The cursor is NOT positioned to the last or single multi-value corresponding to the key. |
| OTHERWISE | the error code |
| LIBMDBX_API int mdbx_cursor_open | ( | MDBX_txn * | txn, |
| MDBX_dbi | dbi, | ||
| MDBX_cursor ** | cursor ) |
Create a cursor handle for the specified transaction and DBI handle.
Using of the mdbx_cursor_open() is equivalent to calling mdbx_cursor_create() and then mdbx_cursor_bind() functions.
A cursor cannot be used when its table handle is closed. Nor when its transaction has ended, except with mdbx_cursor_bind() and mdbx_cursor_renew(). Also it can be discarded with mdbx_cursor_close().
A cursor must be closed explicitly always, before or after its transaction ends. It can be reused with mdbx_cursor_bind() or mdbx_cursor_renew() before finally closing it.
| [in] | txn | A transaction handle returned by mdbx_txn_begin(). |
| [in] | dbi | A table handle returned by mdbx_dbi_open(). |
| [out] | cursor | Address where the new MDBX_cursor handle will be stored. |
| MDBX_THREAD_MISMATCH | Given transaction is not owned by current thread. |
| MDBX_EINVAL | An invalid parameter was specified. |
| LIBMDBX_API int mdbx_cursor_renew | ( | MDBX_txn * | txn, |
| MDBX_cursor * | cursor ) |
Renew a cursor handle for use within the given transaction.
A cursor may be associated with a new transaction whether the previous transaction is running or finished.
Using of the mdbx_cursor_renew() is equivalent to calling mdbx_cursor_bind() with the DBI-handle that previously the cursor was used with.
| [in] | txn | A transaction handle returned by mdbx_txn_begin(). |
| [in] | cursor | A cursor handle returned by mdbx_cursor_open(). |
| MDBX_THREAD_MISMATCH | Given transaction is not owned by current thread. |
| MDBX_EINVAL | An invalid parameter was specified. |
| MDBX_BAD_DBI | The cursor was not bound to a DBI-handle or such a handle became invalid. |
| LIBMDBX_API int mdbx_cursor_reset | ( | MDBX_cursor * | cursor | ) |
Resets the cursor state.
As a result of the reset, the cursor becomes unpositioned and does not allow relative positioning operations, getting or changing data until cursor is set to a position independent of the current one. This allows to stop further operations without first positioning the cursor.
| [in] | cursor | A cursor handle returned by mdbx_cursor_open(). |
| LIBMDBX_API int mdbx_cursor_set_userctx | ( | MDBX_cursor * | cursor, |
| void * | ctx ) |
Set application information associated with the cursor.
| [in] | cursor | An cursor handle returned by mdbx_cursor_create() or mdbx_cursor_open(). |
| [in] | ctx | An arbitrary pointer for whatever the application needs. |
| LIBMDBX_API MDBX_txn * mdbx_cursor_txn | ( | const MDBX_cursor * | cursor | ) |
Return the cursor's transaction handle.
| [in] | cursor | A cursor handle returned by mdbx_cursor_open(). |
| LIBMDBX_API int mdbx_cursor_unbind | ( | MDBX_cursor * | cursor | ) |
Unbind cursor from a transaction.
Unbinded cursor is disassociated with any transactions but still holds the original DBI-handle internally. Thus it could be renewed with any running transaction or closed.
If the transaction is nested, then the cursor should not be used in its parent transaction. Otherwise it is no way to restore state if this nested transaction will be aborted, nor impossible to define the expected behavior.
| [in] | cursor | A cursor handle returned by mdbx_cursor_open(). |
|
inline |
Unbind or closes all cursors of a given transaction and of all its parent transactions if ones are.
Unbinds either closes all cursors associated (opened, renewed or binded) with the given transaction in a bulk with minimal overhead.
| [in] | txn | A transaction handle returned by mdbx_txn_begin(). |
| [in] | unbind | If non-zero, unbinds cursors and leaves ones reusable. Otherwise close and dispose cursors. |
| MDBX_THREAD_MISMATCH | Given transaction is not owned by current thread. |
| MDBX_BAD_TXN | Given transaction is invalid or has a child/nested transaction transaction. |
| LIBMDBX_API int mdbx_txn_release_all_cursors_ex | ( | const MDBX_txn * | txn, |
| bool | unbind, | ||
| size_t * | count ) |
Unbind or closes all cursors of a given transaction and of all its parent transactions if ones are.
Unbinds either closes all cursors associated (opened, renewed or binded) with the given transaction in a bulk with minimal overhead.
| [in] | txn | A transaction handle returned by mdbx_txn_begin(). |
| [in] | unbind | If non-zero, unbinds cursors and leaves ones reusable. Otherwise close and dispose cursors. |
| [in,out] | count | An optional pointer to return the number of cursors processed by the requested operation. |
| MDBX_THREAD_MISMATCH | Given transaction is not owned by current thread. |
| MDBX_BAD_TXN | Given transaction is invalid or has a child/nested transaction transaction. |