lmdb_master_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

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).

§Arguments

  • txn (direction in) - A transaction handle returned by #mdb_txn_begin()
  • dbi (direction in) - A database handle returned by #mdb_dbi_open()
  • key (direction in) - The key to store in the database
  • data (direction in, out) - The data to store
  • flags (direction in) - 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 **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.
# Returns

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.