mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2024-12-14 10:13:05 +02:00
Add kvKeyExists() to KeyValue object.
Check if a key exists even if the value is NULL, which is the same result for a missing key.
This commit is contained in:
parent
80df1114bd
commit
1fd89f05af
@ -53,6 +53,10 @@
|
||||
<p>Add <id>storageHelperFree()</id> to storage helper.</p>
|
||||
</release-item>
|
||||
|
||||
<release-item>
|
||||
<p>Add <code>kvKeyExists()</code> to <code>KeyValue</code> object.</p>
|
||||
</release-item>
|
||||
|
||||
<release-item>
|
||||
<release-item-contributor-list>
|
||||
<release-item-contributor id="stephen.frost"/>
|
||||
|
@ -123,6 +123,20 @@ kvGetIdx(const KeyValue *this, const Variant *key)
|
||||
FUNCTION_TEST_RETURN(result);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Does the key exist (even if the value is NULL)
|
||||
***********************************************************************************************************************************/
|
||||
bool
|
||||
kvKeyExists(const KeyValue *this, const Variant *key)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(KEY_VALUE, this);
|
||||
FUNCTION_TEST_PARAM(VARIANT, key);
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
FUNCTION_TEST_RETURN(kvGetIdx(this, key) != KEY_NOT_FOUND);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Get list of keys
|
||||
***********************************************************************************************************************************/
|
||||
|
@ -22,6 +22,7 @@ KeyValue *kvMove(KeyValue *this, MemContext *parentNew);
|
||||
KeyValue *kvPut(KeyValue *this, const Variant *key, const Variant *value);
|
||||
KeyValue *kvPutKv(KeyValue *this, const Variant *key);
|
||||
const Variant *kvGet(const KeyValue *this, const Variant *key);
|
||||
bool kvKeyExists(const KeyValue *this, const Variant *key);
|
||||
VariantList *kvGetList(const KeyValue *this, const Variant *key);
|
||||
void kvFree(KeyValue *this);
|
||||
|
||||
|
@ -25,7 +25,7 @@ testRun(void)
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------------------
|
||||
if (testBegin("kvPut(), kvAdd(), kvKeyList(), kvGet(), kvGetList(), and kvDup()"))
|
||||
if (testBegin("kvPut(), kvAdd(), kvKeyExists(), kvKeyList(), kvGet(), kvGetList(), and kvDup()"))
|
||||
{
|
||||
KeyValue *store = NULL;
|
||||
|
||||
@ -53,6 +53,11 @@ testRun(void)
|
||||
TEST_RESULT_PTR(kvGet(store, varNewInt(78)), NULL, "get int/null");
|
||||
TEST_RESULT_PTR(kvGet(store, varNewInt(777)), NULL, "get missing key");
|
||||
|
||||
// Check key exists
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_RESULT_BOOL(kvKeyExists(store, varNewStr(strNew("str-key"))), true, "key exists");
|
||||
TEST_RESULT_BOOL(kvKeyExists(store, varNewStr(strNew(BOGUS_STR))), false, "key does not exist");
|
||||
|
||||
// Check that a null value can be changed to non-null
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_RESULT_PTR(kvPut(store, varNewInt(78), varNewInt(66)), store, "update int/null to int/int");
|
||||
|
Loading…
Reference in New Issue
Block a user