diff options
Diffstat (limited to 'common/storage_lmdb.cpp')
-rw-r--r-- | common/storage_lmdb.cpp | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/common/storage_lmdb.cpp b/common/storage_lmdb.cpp index eeb0045..42e3d33 100644 --- a/common/storage_lmdb.cpp +++ b/common/storage_lmdb.cpp | |||
@@ -194,17 +194,17 @@ void Storage::abortTransaction() | |||
194 | d->transaction = 0; | 194 | d->transaction = 0; |
195 | } | 195 | } |
196 | 196 | ||
197 | bool Storage::write(const char *key, size_t keySize, const char *value, size_t valueSize) | 197 | bool Storage::write(void const *keyPtr, size_t keySize, void const *valuePtr, size_t valueSize) |
198 | { | ||
199 | return write(std::string(key, keySize), std::string(value, valueSize)); | ||
200 | } | ||
201 | |||
202 | bool Storage::write(const std::string &sKey, const std::string &sValue) | ||
203 | { | 198 | { |
204 | if (!d->env) { | 199 | if (!d->env) { |
205 | return false; | 200 | return false; |
206 | } | 201 | } |
207 | 202 | ||
203 | if (d->mode == ReadOnly) { | ||
204 | std::cerr << "tried to write in read-only mode." << std::endl; | ||
205 | return false; | ||
206 | } | ||
207 | |||
208 | const bool implicitTransaction = !d->transaction || d->readTransaction; | 208 | const bool implicitTransaction = !d->transaction || d->readTransaction; |
209 | if (implicitTransaction) { | 209 | if (implicitTransaction) { |
210 | // TODO: if this fails, still try the write below? | 210 | // TODO: if this fails, still try the write below? |
@@ -215,10 +215,10 @@ bool Storage::write(const std::string &sKey, const std::string &sValue) | |||
215 | 215 | ||
216 | int rc; | 216 | int rc; |
217 | MDB_val key, data; | 217 | MDB_val key, data; |
218 | key.mv_size = sKey.size(); | 218 | key.mv_size = keySize; |
219 | key.mv_data = (void*)sKey.data(); | 219 | key.mv_data = const_cast<void*>(keyPtr); |
220 | data.mv_size = sValue.size(); | 220 | data.mv_size = valueSize; |
221 | data.mv_data = (void*)sValue.data(); | 221 | data.mv_data = const_cast<void*>(valuePtr); |
222 | rc = mdb_put(d->transaction, d->dbi, &key, &data, 0); | 222 | rc = mdb_put(d->transaction, d->dbi, &key, &data, 0); |
223 | 223 | ||
224 | if (rc) { | 224 | if (rc) { |
@@ -236,6 +236,11 @@ bool Storage::write(const std::string &sKey, const std::string &sValue) | |||
236 | return !rc; | 236 | return !rc; |
237 | } | 237 | } |
238 | 238 | ||
239 | bool Storage::write(const std::string &sKey, const std::string &sValue) | ||
240 | { | ||
241 | return write(const_cast<char*>(sKey.data()), sKey.size(), const_cast<char*>(sValue.data()), sValue.size()); | ||
242 | } | ||
243 | |||
239 | void Storage::read(const std::string &sKey, | 244 | void Storage::read(const std::string &sKey, |
240 | const std::function<bool(const std::string &value)> &resultHandler, | 245 | const std::function<bool(const std::string &value)> &resultHandler, |
241 | const std::function<void(const Storage::Error &error)> &errorHandler) | 246 | const std::function<void(const Storage::Error &error)> &errorHandler) |