-
-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cursor.get returns key and value concatenated into key variable #25
Comments
It looks like you are assuming your values will be NUL-terminated:
But your 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:
(untested) Or, better yet, upgrade to C++17 and use my fork and get the |
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? |
|
How can I use a secondary index? |
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. |
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? |
It's OK. What do you mean get the position? You can position the cursor directly to a know key with cursor ops like 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. |
I meant, doing a |
AFAIK, no. |
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. |
Weird output from cursor get: I would get both key and value inside the key variable, then the value inside the value variable :
Expected Output:
Output :
The text was updated successfully, but these errors were encountered: