new sqlite3::Statement(mConn, "INSERT OR REPLACE INTO data (key, value) VALUES (?,?)"));
mRemoveValuesStmt.reset(
new sqlite3::Statement(mConn, "DELETE FROM data WHERE key = ?1 OR key GLOB escapeStr(?1) ||'.*' "));
+ mGetKeysStmt.reset(
+ new sqlite3::Statement(mConn, "SELECT key FROM data"));
}
void KVStore::createFunctions()
return values;
}
+std::vector<std::string> KVStore::getKeys()
+{
+ Transaction transaction = getTransaction();
+ ScopedReset scopedReset(mGetKeysStmt);
+
+ std::vector<std::string> result;
+
+ for (;;) {
+ int ret = ::sqlite3_step(mGetKeysStmt->get());
+ if (ret == SQLITE_DONE) {
+ return result;
+ }
+ if (ret != SQLITE_ROW) {
+ throw ConfigException("Error during stepping: " + mConn.getErrorMessage());
+ }
+ const char* key = reinterpret_cast<const char*>(sqlite3_column_text(mGetKeysStmt->get(),
+ FIRST_COLUMN));
+ result.push_back(key);
+ }
+}
+
} // namespace config
return getInternal(key, static_cast<T*>(nullptr));
}
+ /**
+ * Returns all stored keys.
+ */
+ std::vector<std::string> getKeys();
+
KVStore::Transaction getTransaction();
private:
std::unique_ptr<sqlite3::Statement> mGetValueListStmt;
std::unique_ptr<sqlite3::Statement> mSetValueStmt;
std::unique_ptr<sqlite3::Statement> mRemoveValuesStmt;
+ std::unique_ptr<sqlite3::Statement> mGetKeysStmt;
void setupDb();
void prepareStatements();