From: Sebastian Harl Date: Mon, 20 Oct 2014 17:17:53 +0000 (+0200) Subject: store: Added support for querying the BACKEND field. X-Git-Tag: sysdb-0.6.0~90 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=d669467798e5d49acaed756d878fc25fb95875e5;p=sysdb.git store: Added support for querying the BACKEND field. … returning an array of strings. --- 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