Code

data: Let sdb_data_array_get support DATETIME, BINARY, REGEX values.
authorSebastian Harl <sh@tokkee.org>
Wed, 11 Mar 2015 19:00:27 +0000 (20:00 +0100)
committerSebastian Harl <sh@tokkee.org>
Wed, 11 Mar 2015 19:00:27 +0000 (20:00 +0100)
src/core/data.c

index 2b1cff2ae066316cb1628a7037fa3f250ef21496..44353057b5df70bcb8db19da6600166d4786500d 100644 (file)
@@ -781,9 +781,28 @@ sdb_data_array_get(const sdb_data_t *array, size_t i, sdb_data_t *value)
                char **v = array->data.array.values;
                tmp.data.string = v[i];
        }
+       else if (type == SDB_TYPE_DATETIME) {
+               sdb_time_t *v = array->data.array.values;
+               tmp.data.datetime = v[i];
+       }
+       else if (type == SDB_TYPE_BINARY) {
+               struct {
+                       size_t length;
+                       unsigned char *datum;
+               } *v = array->data.array.values;
+               assert(sizeof(tmp.data.binary) == sizeof(v[i]));
+               memcpy(&tmp.data.binary, &v[i], sizeof(v[i]));
+       }
+       else if (type == SDB_TYPE_REGEX) {
+               struct {
+                       char *raw;
+                       regex_t regex;
+               } *v = array->data.array.values;
+               assert(sizeof(tmp.data.re) == sizeof(v[i]));
+               memcpy(&tmp.data.re, &v[i], sizeof(v[i]));
+       }
        else {
-               /* TODO */
-               errno = ENOTSUP;
+               errno = EINVAL;
                return -1;
        }