mdb_put function

int mdb_put(
  1. Pointer<MDB_txn> txn,
  2. int dbi,
  3. Pointer<MDB_val> key,
  4. Pointer<MDB_val> data,
  5. int flags,
)

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

Implementation

@ffi.FfiNative<
    ffi.Int Function(ffi.Pointer<MDB_txn>, MDB_dbi, ffi.Pointer<MDB_val>,
        ffi.Pointer<MDB_val>, ffi.UnsignedInt)>('mdb_put')
external int mdb_put(
  ffi.Pointer<MDB_txn> txn,
  int dbi,
  ffi.Pointer<MDB_val> key,
  ffi.Pointer<MDB_val> data,
  int flags,
);