From de5bd0955ac50fe17aaf0a02055cc70836b7e4ae Mon Sep 17 00:00:00 2001 From: Minijackson Date: Wed, 22 Aug 2018 13:45:49 +0200 Subject: Fix "contains" function + write tests for contains and exists --- common/storage_common.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'common/storage_common.cpp') diff --git a/common/storage_common.cpp b/common/storage_common.cpp index 09b7707..7c794c3 100644 --- a/common/storage_common.cpp +++ b/common/storage_common.cpp @@ -233,6 +233,18 @@ void DataStore::getUids(const QByteArray &type, const Transaction &transaction, }); } +bool DataStore::hasUid(const QByteArray &type, const Transaction &transaction, const QByteArray &uid) +{ + bool hasTheUid = false; + transaction.openDatabase(type + "uids").scan(uid, [&](const QByteArray &key, const QByteArray &) { + Q_ASSERT(uid == key); + hasTheUid = true; + return false; + }); + + return hasTheUid; +} + bool DataStore::isInternalKey(const char *key) { return key && strncmp(key, s_internalPrefix, s_internalPrefixSize) == 0; -- cgit v1.2.3