You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-07-13 01:00:23 +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:
@ -53,6 +53,10 @@
|
|||||||
<p>Add <id>storageHelperFree()</id> to storage helper.</p>
|
<p>Add <id>storageHelperFree()</id> to storage helper.</p>
|
||||||
</release-item>
|
</release-item>
|
||||||
|
|
||||||
|
<release-item>
|
||||||
|
<p>Add <code>kvKeyExists()</code> to <code>KeyValue</code> object.</p>
|
||||||
|
</release-item>
|
||||||
|
|
||||||
<release-item>
|
<release-item>
|
||||||
<release-item-contributor-list>
|
<release-item-contributor-list>
|
||||||
<release-item-contributor id="stephen.frost"/>
|
<release-item-contributor id="stephen.frost"/>
|
||||||
|
@ -123,6 +123,20 @@ kvGetIdx(const KeyValue *this, const Variant *key)
|
|||||||
FUNCTION_TEST_RETURN(result);
|
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
|
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 *kvPut(KeyValue *this, const Variant *key, const Variant *value);
|
||||||
KeyValue *kvPutKv(KeyValue *this, const Variant *key);
|
KeyValue *kvPutKv(KeyValue *this, const Variant *key);
|
||||||
const Variant *kvGet(const 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);
|
VariantList *kvGetList(const KeyValue *this, const Variant *key);
|
||||||
void kvFree(KeyValue *this);
|
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;
|
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(78)), NULL, "get int/null");
|
||||||
TEST_RESULT_PTR(kvGet(store, varNewInt(777)), NULL, "get missing key");
|
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
|
// 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");
|
TEST_RESULT_PTR(kvPut(store, varNewInt(78), varNewInt(66)), store, "update int/null to int/int");
|
||||||
|
Reference in New Issue
Block a user