From d669467798e5d49acaed756d878fc25fb95875e5 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Mon, 20 Oct 2014 19:17:53 +0200 Subject: [PATCH] store: Added support for querying the BACKEND field. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit … returning an array of strings. --- src/core/store.c | 9 +++++++-- t/unit/core/store_test.c | 13 +++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/core/store.c b/src/core/store.c index 81aedfb..d9ca4c0 100644 --- a/src/core/store.c +++ b/src/core/store.c @@ -919,8 +919,13 @@ sdb_store_get_field(sdb_store_obj_t *obj, int field, sdb_data_t *res) tmp.data.datetime = obj->interval; break; case SDB_FIELD_BACKEND: - /* TODO: add support for storing array values in a data object - * for now, fall thru to the error case */ + { + tmp.type = SDB_TYPE_ARRAY | SDB_TYPE_STRING; + tmp.data.array.length = obj->backends_num; + tmp.data.array.values = obj->backends; + return sdb_data_copy(res, &tmp); + break; + } default: return -1; } diff --git a/t/unit/core/store_test.c b/t/unit/core/store_test.c index c1071fb..826d938 100644 --- a/t/unit/core/store_test.c +++ b/t/unit/core/store_test.c @@ -781,6 +781,19 @@ START_TEST(test_get_field) "sdb_store_get_field(, SDB_FIELD_INTERVAL, ) " "returned value {%d, %lu}; expected {%d, 10}", value.type, value.data.datetime, SDB_TYPE_DATETIME); + + check = sdb_store_get_field(host, SDB_FIELD_BACKEND, &value); + fail_unless(check == 0, + "sdb_store_get_field(, SDB_FIELD_BACKEND, ) = " + "%d; expected: 0"); + /* there are no backends in this test */ + fail_unless((value.type == (SDB_TYPE_ARRAY | SDB_TYPE_STRING)) + && (value.data.array.length == 0) + && (value.data.array.values == NULL), + "sdb_store_get_field(, SDB_FIELD_BACKEND, ) " + "returned value {%d, %lu, %p}; expected {%d, 0, NULL}", + value.type, value.data.array.length, value.data.array.values, + SDB_TYPE_ARRAY | SDB_TYPE_STRING); } END_TEST -- 2.30.2