summaryrefslogtreecommitdiffstats
path: root/store/database.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2014-12-03 20:36:37 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2014-12-03 20:36:37 +0100
commit44757d932abac6c8346366dfa3c0fb94e5ee0d06 (patch)
treec9120c3b4faf1b8e33dc04fee7347bc91c956977 /store/database.cpp
parent21138cfb7a4537626e11bdf084fcf9d672361059 (diff)
downloadsink-44757d932abac6c8346366dfa3c0fb94e5ee0d06.tar.gz
sink-44757d932abac6c8346366dfa3c0fb94e5ee0d06.zip
dummyresource that doesn't work yet
Diffstat (limited to 'store/database.cpp')
-rw-r--r--store/database.cpp27
1 files changed, 20 insertions, 7 deletions
diff --git a/store/database.cpp b/store/database.cpp
index c16a077..7e2019e 100644
--- a/store/database.cpp
+++ b/store/database.cpp
@@ -63,7 +63,7 @@ void Database::write(const std::string &sKey, const std::string &sValue, MDB_txn
63 } 63 }
64} 64}
65 65
66void Database::read(const std::string &sKey) 66void Database::read(const std::string &sKey, const std::function<void(const std::string)> &resultHandler)
67{ 67{
68 int rc; 68 int rc;
69 MDB_txn *txn; 69 MDB_txn *txn;
@@ -76,13 +76,26 @@ void Database::read(const std::string &sKey)
76 76
77 rc = mdb_txn_begin(env, NULL, MDB_RDONLY, &txn); 77 rc = mdb_txn_begin(env, NULL, MDB_RDONLY, &txn);
78 rc = mdb_cursor_open(txn, dbi, &cursor); 78 rc = mdb_cursor_open(txn, dbi, &cursor);
79 // while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { 79 if (sKey.empty()) {
80 if ((rc = mdb_cursor_get(cursor, &key, &data, MDB_SET)) == 0) { 80 std::cout << "Iterating over all values of store!" << std::endl;
81 const std::string resultKey(static_cast<char*>(key.mv_data), key.mv_size); 81 while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
82 const std::string resultValue(static_cast<char*>(data.mv_data), data.mv_size); 82 const std::string resultKey(static_cast<char*>(key.mv_data), key.mv_size);
83 // std::cout << "key: " << resultKey << " data: " << resultValue << std::endl; 83 const std::string resultValue(static_cast<char*>(data.mv_data), data.mv_size);
84 // std::cout << "key: " << resultKey << " data: " << resultValue << std::endl;
85 resultHandler(resultValue);
86 }
84 } else { 87 } else {
85 std::cout << "couldn't find value " << sKey << std::endl; 88 if ((rc = mdb_cursor_get(cursor, &key, &data, MDB_SET)) == 0) {
89 const std::string resultKey(static_cast<char*>(key.mv_data), key.mv_size);
90 const std::string resultValue(static_cast<char*>(data.mv_data), data.mv_size);
91 // std::cout << "key: " << resultKey << " data: " << resultValue << std::endl;
92 resultHandler(resultValue);
93 } else {
94 std::cout << "couldn't find value " << sKey << std::endl;
95 }
96 }
97 if (rc) {
98 std::cerr << "mdb_cursor_get: " << rc << mdb_strerror(rc) << std::endl;
86 } 99 }
87 mdb_cursor_close(cursor); 100 mdb_cursor_close(cursor);
88 mdb_txn_abort(txn); 101 mdb_txn_abort(txn);