Code

store: Added support for querying the BACKEND field.
authorSebastian Harl <sh@tokkee.org>
Mon, 20 Oct 2014 17:17:53 +0000 (19:17 +0200)
committerSebastian Harl <sh@tokkee.org>
Mon, 20 Oct 2014 17:17:53 +0000 (19:17 +0200)
… returning an array of strings.

src/core/store.c
t/unit/core/store_test.c

index 81aedfb7600a9243accbe4e49cceffcf87f8c54b..d9ca4c0eb113a7a2824249d92d83fa45f4d4e56c 100644 (file)
@@ -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;
        }
index c1071fb584e0f18b333eb18607c1193f374a4fc1..826d938fc4444a5d02a0bde60812dcb83ebc0933 100644 (file)
@@ -781,6 +781,19 @@ START_TEST(test_get_field)
                        "sdb_store_get_field(<host>, SDB_FIELD_INTERVAL, <value>) "
                        "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(<host>, SDB_FIELD_BACKEND, <value>) = "
+                       "%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(<host>, SDB_FIELD_BACKEND, <value>) "
+                       "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