Skip to content

How to get an specific value with lmdb++ #1

Open
@hiteboar

Description

@hiteboar

I have already tried to use lmdb++ but I failed.
What I want to do is simple, it is like the example.cc but I want to get an specific value of a key of the data base instead of go over all the values that have been saved on it with cursors.

For example:

int main() {
  auto env = lmdb::env::create();
  env.open("./example.mdb", 0, 0664);

  auto wtxn = lmdb::txn::begin(env);
  auto dbi = lmdb::dbi::open(wtxn, nullptr);
  dbi.put(wtxn, "username", "jhacker");
  dbi.put(wtxn, "email", "jhacker@example.org");
  dbi.put(wtxn, "fullname", "J. Random Hacker");
  wtxn.commit();

  auto rtxn = lmdb::txn::begin(env);

  std::string value;
  dbi.get(rtxn, "username", value);
  std::printf("value: '%s'\n",value.c_str());

  rtxn.abort();

  return EXIT_SUCCESS;
}

But it returns me:
Segmentation fault (core dumped)

How can I do this?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions