diff options
author | Aaron Seigo <aseigo@kde.org> | 2014-12-06 00:57:23 +0100 |
---|---|---|
committer | Aaron Seigo <aseigo@kde.org> | 2014-12-06 00:57:23 +0100 |
commit | a9ae9ad67f6d030c1fc2ba9cd682fbec96ef8c44 (patch) | |
tree | 6a00a3c9765bb481f7df7e4a691e62bb59317c05 /common | |
parent | 66bcbab0990c965196991d66ca2a595cf9135074 (diff) | |
download | sink-a9ae9ad67f6d030c1fc2ba9cd682fbec96ef8c44.tar.gz sink-a9ae9ad67f6d030c1fc2ba9cd682fbec96ef8c44.zip |
implement scanning
Diffstat (limited to 'common')
-rw-r--r-- | common/storage_kyoto.cpp | 43 |
1 files changed, 35 insertions, 8 deletions
diff --git a/common/storage_kyoto.cpp b/common/storage_kyoto.cpp index 539ada1..d61c6c4 100644 --- a/common/storage_kyoto.cpp +++ b/common/storage_kyoto.cpp | |||
@@ -142,9 +142,20 @@ void Storage::read(const std::string &sKey, | |||
142 | } | 142 | } |
143 | 143 | ||
144 | std::string value; | 144 | std::string value; |
145 | if (d->db.get(sKey, &value)) { | 145 | if (sKey.empty()) { |
146 | resultHandler(value); | 146 | kyotocabinet::DB::Cursor *cursor = d->db.cursor(); |
147 | cursor->jump(); | ||
148 | |||
149 | std::string key, value; | ||
150 | while (cursor->get_value(&value, true) && resultHandler(value)) {} | ||
151 | |||
152 | delete cursor; | ||
147 | return; | 153 | return; |
154 | } else { | ||
155 | if (d->db.get(sKey, &value)) { | ||
156 | resultHandler(value); | ||
157 | return; | ||
158 | } | ||
148 | } | 159 | } |
149 | 160 | ||
150 | Error error(d->name.toStdString(), d->db.error().code(), d->db.error().message()); | 161 | Error error(d->name.toStdString(), d->db.error().code(), d->db.error().message()); |
@@ -162,14 +173,30 @@ void Storage::read(const std::string &sKey, | |||
162 | } | 173 | } |
163 | 174 | ||
164 | size_t valueSize; | 175 | size_t valueSize; |
165 | char *valueBuffer = d->db.get(sKey.data(), sKey.size(), &valueSize); | 176 | char *valueBuffer; |
166 | if (valueBuffer) { | 177 | if (sKey.empty()) { |
167 | resultHandler(valueBuffer, valueSize); | 178 | kyotocabinet::DB::Cursor *cursor = d->db.cursor(); |
179 | cursor->jump(); | ||
180 | |||
181 | while ((valueBuffer = cursor->get_value(&valueSize, true))) { | ||
182 | bool ok = resultHandler(valueBuffer, valueSize); | ||
183 | delete[] valueBuffer; | ||
184 | if (!ok) { | ||
185 | break; | ||
186 | } | ||
187 | } | ||
188 | |||
189 | delete cursor; | ||
168 | } else { | 190 | } else { |
169 | Error error(d->name.toStdString(), d->db.error().code(), d->db.error().message()); | 191 | valueBuffer = d->db.get(sKey.data(), sKey.size(), &valueSize); |
170 | errorHandler(error); | 192 | if (valueBuffer) { |
193 | resultHandler(valueBuffer, valueSize); | ||
194 | } else { | ||
195 | Error error(d->name.toStdString(), d->db.error().code(), d->db.error().message()); | ||
196 | errorHandler(error); | ||
197 | } | ||
198 | delete[] valueBuffer; | ||
171 | } | 199 | } |
172 | delete[] valueBuffer; | ||
173 | } | 200 | } |
174 | 201 | ||
175 | qint64 Storage::diskUsage() const | 202 | qint64 Storage::diskUsage() const |