summaryrefslogtreecommitdiffstats
path: root/common/storage_kyoto.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'common/storage_kyoto.cpp')
-rw-r--r--common/storage_kyoto.cpp16
1 files changed, 11 insertions, 5 deletions
diff --git a/common/storage_kyoto.cpp b/common/storage_kyoto.cpp
index 05942c2..40bd3e6 100644
--- a/common/storage_kyoto.cpp
+++ b/common/storage_kyoto.cpp
@@ -118,28 +118,34 @@ bool Storage::write(const std::string &sKey, const std::string &sValue)
118 return success; 118 return success;
119} 119}
120 120
121void Storage::read(const std::string &sKey, const std::function<void(const std::string &value)> &resultHandler) 121bool Storage::read(const std::string &sKey, const std::function<void(const std::string &value)> &resultHandler)
122{ 122{
123 if (!d->dbOpen) { 123 if (!d->dbOpen) {
124 return; 124 return false;
125 } 125 }
126 126
127 std::string value; 127 std::string value;
128 if (d->db.get(sKey, &value)) { 128 if (d->db.get(sKey, &value)) {
129 resultHandler(value); 129 resultHandler(value);
130 return true;
130 } 131 }
132
133 return false;
131} 134}
132 135
133void Storage::read(const std::string &sKey, const std::function<void(void *ptr, int size)> &resultHandler) 136bool Storage::read(const std::string &sKey, const std::function<void(void *ptr, int size)> &resultHandler)
134{ 137{
135 if (!d->dbOpen) { 138 if (!d->dbOpen) {
136 return; 139 return false;
137 } 140 }
138 141
139 size_t valueSize; 142 size_t valueSize;
140 char *valueBuffer = d->db.get(sKey.data(), sKey.size(), &valueSize); 143 char *valueBuffer = d->db.get(sKey.data(), sKey.size(), &valueSize);
141 resultHandler(valueBuffer, valueSize); 144 if (valueBuffer) {
145 resultHandler(valueBuffer, valueSize);
146 }
142 delete[] valueBuffer; 147 delete[] valueBuffer;
148 return valueBuffer != nullptr;
143} 149}
144 150
145qint64 Storage::diskUsage() const 151qint64 Storage::diskUsage() const