index c8c7482e796f4438aeafdb8eebe4588223636e7b..997cf9f0a320c616af5074c86f749a03b1dca8b1 100644 (file)
--- a/src/include/core/data.h
+++ b/src/include/core/data.h
SDB_TYPE_DATETIME,
SDB_TYPE_BINARY,
SDB_TYPE_REGEX, /* extended, case-insensitive POSIX regex */
+
+ /* flags: */
+ SDB_TYPE_ARRAY = 1 << 8,
};
#define SDB_TYPE_TO_STRING(t) \
: ((t) == SDB_TYPE_STRING) ? "STRING" \
: ((t) == SDB_TYPE_DATETIME) ? "DATETIME" \
: ((t) == SDB_TYPE_BINARY) ? "BINARY" \
- : ((t) == SDB_TYPE_REGEX) ? "REGEX" : "UNKNOWN")
+ : ((t) == SDB_TYPE_REGEX) ? "REGEX" \
+ : ((t) == (SDB_TYPE_ARRAY | SDB_TYPE_INTEGER)) ? "[]INTEGER" \
+ : ((t) == (SDB_TYPE_ARRAY | SDB_TYPE_DECIMAL)) ? "[]DECIMAL" \
+ : ((t) == (SDB_TYPE_ARRAY | SDB_TYPE_STRING)) ? "[]STRING" \
+ : ((t) == (SDB_TYPE_ARRAY | SDB_TYPE_DATETIME)) ? "[]DATETIME" \
+ : ((t) == (SDB_TYPE_ARRAY | SDB_TYPE_BINARY)) ? "[]BINARY" \
+ : ((t) == (SDB_TYPE_ARRAY | SDB_TYPE_REGEX)) ? "[]REGEX" \
+ : "UNKNOWN")
+
+union sdb_datum;
+typedef union sdb_datum sdb_datum_t;
+
+union sdb_datum {
+ int64_t integer; /* SDB_TYPE_INTEGER */
+ double decimal; /* SDB_TYPE_DECIMAL */
+ char *string; /* SDB_TYPE_STRING */
+ sdb_time_t datetime; /* SDB_TYPE_DATETIME */
+ struct {
+ size_t length;
+ unsigned char *datum;
+ } binary; /* SDB_TYPE_BINARY */
+ struct {
+ char *raw;
+ regex_t regex;
+ } re; /* SDB_TYPE_REGEX */
+
+ struct {
+ size_t length;
+ void *values;
+ } array;
+};
/*
* sdb_data_t:
- * A datum retrieved from an arbitrary data source.
+ * An arbitrary value of a specified type.
*/
typedef struct {
- int type;
- union {
- int64_t integer; /* SDB_TYPE_INTEGER */
- double decimal; /* SDB_TYPE_DECIMAL */
- char *string; /* SDB_TYPE_STRING */
- sdb_time_t datetime; /* SDB_TYPE_DATETIME */
- struct {
- size_t length;
- unsigned char *datum;
- } binary; /* SDB_TYPE_BINARY */
- struct {
- char *raw;
- regex_t regex;
- } re; /* SDB_TYPE_REGEX */
- } data;
+ int type; /* type of the datum */
+ sdb_datum_t data;
} sdb_data_t;
#define SDB_DATA_INIT { SDB_TYPE_NULL, { .integer = 0 } }
_Bool
sdb_data_isnull(const sdb_data_t *datum);
+/*
+ * sdb_data_inarray:
+ * Determine whether a datum is included in an array based on the usual
+ * comparison function of the value's type. The element type of the array has
+ * to match the type of the value. The value may be another array. In that
+ * case, the element types have to match and the function returns true if all
+ * elements of the first array are included in the second where order does not
+ * matter.
+ */
+_Bool
+sdb_data_inarray(const sdb_data_t *value, const sdb_data_t *array);
+
+/*
+ * sdb_data_array_get:
+ * Get the i-th value stored in the specified array and store an alias in
+ * 'value'. Storing an alias means that the value points to the actual array
+ * element. Do *not* free the value after using it (i.e., don't use
+ * sdb_data_free_datum).
+ *
+ * Returns:
+ * - 0 on success
+ * - a negative value else
+ */
+int
+sdb_data_array_get(const sdb_data_t *array, size_t i, sdb_data_t *value);
+
/*
* Operators supported by sdb_data_eval_expr.
*/
sdb_data_expr_eval(int op, const sdb_data_t *d1, const sdb_data_t *d2,
sdb_data_t *res);
+/*
+ * sdb_data_expr_type:
+ * Determine the type of the expression when applying the specified operator
+ * to the specified types. Note that if an actual value is a typed NULL value
+ * (e.g. a NULL string value), the return value of this function does not
+ * match the return type of sdb_data_expr_eval.
+ *
+ * See the documentation of sdb_data_expr_eval() for a description of which
+ * operations are supported.
+ *
+ * Returns:
+ * - the type id on success
+ * - a negative value else
+ */
+int
+sdb_data_expr_type(int op, int type1, int type2);
+
/*
* sdb_data_strlen:
* Returns a (worst-case) estimate for the number of bytes required to format