lmdb_sys

Function mdb_put

Source
pub unsafe extern "C" fn mdb_put(
    txn: *mut MDB_txn,
    dbi: MDB_dbi,
    key: *mut MDB_val,
    data: *mut MDB_val,
    flags: c_uint,
) -> c_int
Expand description

@brief Store items into a database.

This function stores key/data pairs in the database. The default behavior is to enter the new key/data pair, replacing any previously existing key if duplicates are disallowed, or adding a duplicate data item if duplicates are allowed (#MDB_DUPSORT). @param[in] txn A transaction handle returned by #mdb_txn_begin() @param[in] dbi A database handle returned by #mdb_dbi_open() @param[in] key The key to store in the database @param[in,out] data The data to store @param[in] flags Special options for this operation. This parameter must be set to 0 or by bitwise OR’ing together one or more of the values described here.

  • #MDB_NODUPDATA - enter the new key/data pair only if it does not already appear in the database. This flag may only be specified if the database was opened with #MDB_DUPSORT. The function will return #MDB_KEYEXIST if the key/data pair already appears in the database.
  • #MDB_NOOVERWRITE - enter the new key/data pair only if the key does not already appear in the database. The function will return #MDB_KEYEXIST if the key already appears in the database, even if the database supports duplicates (#MDB_DUPSORT). The \b data parameter will be set to point to the existing item.
  • #MDB_RESERVE - reserve space for data of the given size, but don't copy the given data. Instead, return a pointer to the reserved space, which the caller can fill in later - before the next update operation or the transaction ends. This saves an extra memcpy if the data is being generated later. LMDB does nothing else with this memory, the caller is expected to modify all of the space requested. This flag must not be specified if the database was opened with #MDB_DUPSORT.
  • #MDB_APPEND - append the given key/data pair to the end of the database. This option allows fast bulk loading when keys are already known to be in the correct order. Loading unsorted keys with this flag will cause a #MDB_KEYEXIST error.
  • #MDB_APPENDDUP - as above, but for sorted dup data.
@return A non-zero error value on failure and 0 on success. Some possible errors are:
  • #MDB_MAP_FULL - the database is full, see #mdb_env_set_mapsize().
  • #MDB_TXN_FULL - the transaction has too many dirty pages.
  • EACCES - an attempt was made to write in a read-only transaction.
  • EINVAL - an invalid parameter was specified.