Comments (10)
It looks like you are assuming your values will be NUL-terminated:
printf("We got '%s'\nValue '%s'\n", k.data(), v.data());
But your put
s above aren't writing the NUL byte.
Don't use the C string routines since you won't be able to store NUL bytes in your keys/values. Instead do something like:
std::string myKey(k.data(), k.size());
std::string myValue(v.data(), v.size());
std::cout << "We got " << myKey << " and " << myValue << std::endl;
(untested)
Or, better yet, upgrade to C++17 and use my fork and get the string_view
hotness :)
from lmdbxx.
I know about string_view and about your fork, but I have constraint that prevent me from going above c++11. Since you're here, could you tell me how can I force my database to sorted by input order (instead of lexicographically). Also on first creation of database, it always crashes with "bus_error", but if I open the environment, then close it then open it again and execute my code, it works.
EDIT: How can I make sure my puts do add the null byte, in order to avoid this problem?
from lmdbxx.
-
Make it so your keys increase every time you insert, or use a secondary index
-
I don't know, I'd need code to reproduce it. Make sure you are creating a big enough MAPSIZE, and the same mapsize each time. Make sure you commit the transaction that creates the tables.
-
I suggest not storing the NUL byte. It's a waste of space since LMDB tracks size anyway. Furthermore, it indicates you are unable to store NUL bytes as part of your keys or values (as I described above)
from lmdbxx.
How can I use a secondary index?
from lmdbxx.
Every time you insert into your main table, you also insert into another table. In this secondary table, the key is an increasing integer, and the value is the key into your main table.
Then when you want to iterate over your items in insertion order, iterate through the secondary index. For each value, use it as a key to look up the item from the main table.
from lmdbxx.
I'm sorry for all these questions but I can't find where else to ask them, is it possible to get the position of an entry without iterating through my database with a cursor and then incrementing a counter?
from lmdbxx.
It's OK. What do you mean get the position? You can position the cursor directly to a know key with cursor ops like MDB_SET
, or go to somewhere nearby with MDB_SET_RANGE
.
If you mean get an item by its postion index (ie, get the 10th element in the DB) then afaik this is not possible. If you're always appending to the DB (and never removing or inserting in the middle) then you could maintain the position index in a secondary index.
from lmdbxx.
I meant, doing a dbi.get()
to search for the position index of a certain key, (e.g inputting "user_email" and receiving 10). Is this possible without holding duplicate databases with secondary indexes?
from lmdbxx.
AFAIK, no.
from lmdbxx.
I'll see which one would be more cost effective, iterating through the database and counting, or keeping a duplicate of each concerned database with indices.
from lmdbxx.
Related Issues (19)
- How to get an specific value with lmdb++ HOT 3
- Allow copying of lmdb::dbi instances HOT 2
- Feature Request: remove dependency on pthreads? HOT 4
- How can I save '0' ? HOT 2
- Symbol mdb_env_create() doesn't resolve HOT 1
- No updating value when key exists HOT 1
- Example uses the same dbi instance with a different transaction HOT 2
- Could you tag a new release? HOT 1
- Cursor double free on write tx HOT 1
- I forked this repo for C++17
- mdb_del : Invalid argument for simple deletion HOT 9
- Double-free when txn.commit() throws
- Merge into lmdb HOT 5
- Help needed cursor_put and MDB_MULTIPLE HOT 5
- problem in lmdb++.h line 1654 HOT 1
- Querying for different types in key/value pair HOT 1
- thread-local storage is not supported for clang7 HOT 1
- Enhance error messages in exceptions
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lmdbxx.