aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/facade/DB.cpp
diff options
context:
space:
mode:
authormax-001 <maxsmits21@kpnmail.nl>2024-12-20 12:01:36 +0100
committermax-001 <maxsmits21@kpnmail.nl>2024-12-20 12:01:36 +0100
commit79d3a9f4311e6684b6df83a15ca7844f58c1959c (patch)
treeb2883e83f61cee9edf290a6a7228c7f0b1fbae8a /src/crepe/facade/DB.cpp
parent9140b73e4af7aa925b53e4fb4e6aa7f4ea2e3385 (diff)
parent03aea832aa0bc2edba2cc5ab4d9f8eba42d355be (diff)
Merge remote-tracking branch 'origin/master' into max/game
Diffstat (limited to 'src/crepe/facade/DB.cpp')
-rw-r--r--src/crepe/facade/DB.cpp14
1 files changed, 4 insertions, 10 deletions
diff --git a/src/crepe/facade/DB.cpp b/src/crepe/facade/DB.cpp
index 95cf606..7a3e473 100644
--- a/src/crepe/facade/DB.cpp
+++ b/src/crepe/facade/DB.cpp
@@ -1,6 +1,6 @@
#include <cstring>
-#include "util/Log.h"
+#include "util/dbg.h"
#include "DB.h"
@@ -21,12 +21,6 @@ DB::DB(const string & path) {
const char * file = path.empty() ? NULL : path.c_str();
ret = this->db->open(this->db.get(), NULL, file, NULL, libdb::DB_BTREE, DB_CREATE, 0);
if (ret != 0) throw runtime_error(format("db->open: {}", libdb::db_strerror(ret)));
-
- // create cursor
- libdb::DBC * cursor;
- ret = this->db->cursor(this->db.get(), NULL, &cursor, 0);
- if (ret != 0) throw runtime_error(format("db->cursor: {}", libdb::db_strerror(ret)));
- this->cursor = {cursor, [](libdb::DBC * cursor) { cursor->close(cursor); }};
}
libdb::DBT DB::to_thing(const string & thing) const noexcept {
@@ -42,10 +36,10 @@ string DB::get(const string & key) {
libdb::DBT db_val;
memset(&db_val, 0, sizeof(libdb::DBT));
- int ret = this->cursor->get(this->cursor.get(), &db_key, &db_val, DB_FIRST);
+ int ret = this->db->get(this->db.get(), NULL, &db_key, &db_val, 0);
if (ret == 0) return {static_cast<char *>(db_val.data), db_val.size};
- string err = format("cursor->get: {}", libdb::db_strerror(ret));
+ string err = format("db->get: {}", libdb::db_strerror(ret));
if (ret == DB_NOTFOUND) throw out_of_range(err);
else throw runtime_error(err);
}
@@ -54,7 +48,7 @@ void DB::set(const string & key, const string & value) {
libdb::DBT db_key = this->to_thing(key);
libdb::DBT db_val = this->to_thing(value);
int ret = this->db->put(this->db.get(), NULL, &db_key, &db_val, 0);
- if (ret != 0) throw runtime_error(format("cursor->get: {}", libdb::db_strerror(ret)));
+ if (ret != 0) throw runtime_error(format("db->get: {}", libdb::db_strerror(ret)));
}
bool DB::has(const std::string & key) {