Allow NULL for config for extension in DB schema

This commit is contained in:
Özgür Kesim 2022-01-21 12:48:22 +01:00
parent ba3be90ed4
commit eb58dc0c3c
Signed by: oec
GPG Key ID: 3D76A56D79EDD9D7
3 changed files with 33 additions and 8 deletions

View File

@ -297,14 +297,14 @@ COMMENT ON TABLE signkey_revocations
CREATE TABLE IF NOT EXISTS extensions
(extension_id BIGSERIAL UNIQUE
,name VARCHAR NOT NULL UNIQUE
,config BYTEA NOT NULL
,config BYTEA
);
COMMENT ON TABLE extensions
IS 'Configurations of the activated extensions';
COMMENT ON COLUMN extensions.name
IS 'Name of the extension';
COMMENT ON COLUMN extensions.config
IS 'Configuration of the extension as JSON-blob';
IS 'Configuration of the extension as JSON-blob, maybe NULL';
CREATE TABLE IF NOT EXISTS known_coins

View File

@ -11420,9 +11420,12 @@ postgres_set_extension_config (void *cls,
const char *config)
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_QueryParam pcfg = (NULL == config || 0 == *config) ?
GNUNET_PQ_query_param_null () :
GNUNET_PQ_query_param_string (config);
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_string (extension_name),
GNUNET_PQ_query_param_string (config),
pcfg,
GNUNET_PQ_query_param_end
};
@ -11451,15 +11454,24 @@ postgres_get_extension_config (void *cls,
GNUNET_PQ_query_param_string (extension_name),
GNUNET_PQ_query_param_end
};
bool is_null;
struct GNUNET_PQ_ResultSpec rs[] = {
GNUNET_PQ_result_spec_string ("config", config),
GNUNET_PQ_result_spec_allow_null (
GNUNET_PQ_result_spec_string ("config", config),
&is_null),
GNUNET_PQ_result_spec_end
};
enum GNUNET_DB_QueryStatus qs;
return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
"get_extension_config",
params,
rs);
qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
"get_extension_config",
params,
rs);
if (is_null)
{
*config = NULL;
}
return qs;
}

View File

@ -146,6 +146,19 @@ test_extension_config (void)
FAILIF (0 != strcmp ("buzz", config));
/* let's do this again, with NULL */
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->set_extension_config (plugin->cls,
"fnord",
NULL));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->get_extension_config (plugin->cls,
"fnord",
&config));
FAILIF (NULL != config);
return GNUNET_OK;
drop:
return GNUNET_SYSERR;