From: Sebastian Harl Date: Fri, 24 Oct 2014 15:59:28 +0000 (+0200) Subject: store: Record the data-type of an expression. X-Git-Tag: sysdb-0.6.0~64 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=9d15e8a6bb4b1d5219f65b859a0744e9d91c8384;p=sysdb.git store: Record the data-type of an expression. --- diff --git a/src/core/store-private.h b/src/core/store-private.h index 7ce807b..1e2c3ec 100644 --- a/src/core/store-private.h +++ b/src/core/store-private.h @@ -117,6 +117,7 @@ struct sdb_store_expr { sdb_object_t super; int type; /* see above */ + int data_type; sdb_store_expr_t *left; sdb_store_expr_t *right; diff --git a/src/core/store_expr.c b/src/core/store_expr.c index ed0589b..d5b22c7 100644 --- a/src/core/store_expr.c +++ b/src/core/store_expr.c @@ -75,6 +75,9 @@ expr_init(sdb_object_t *obj, va_list ap) expr->type = type; expr->left = left; expr->right = right; + + /* unknown for now */ + expr->data_type = -1; return 0; } /* expr_init */ @@ -103,29 +106,39 @@ sdb_store_expr_t * sdb_store_expr_create(int op, sdb_store_expr_t *left, sdb_store_expr_t *right) { sdb_data_t value = SDB_DATA_INIT; + sdb_store_expr_t *e; if ((op < 0) || (SDB_DATA_CONCAT < op) || (! left) || (! right)) return NULL; - if (left->type || right->type) - return SDB_STORE_EXPR(sdb_object_create("store-expr", expr_type, + if (left->type || right->type) { + e = SDB_STORE_EXPR(sdb_object_create("store-expr", expr_type, op, left, right, NULL)); + e->data_type = sdb_data_expr_type(op, left->type, right->type); + return e; + } /* else: both expressions are constant values; evaluate now */ if (sdb_data_expr_eval(op, &left->data, &right->data, &value)) return NULL; - return SDB_STORE_EXPR(sdb_object_create("store-constvalue", expr_type, + e = SDB_STORE_EXPR(sdb_object_create("store-constvalue", expr_type, 0, NULL, NULL, &value)); + e->data_type = value.type; + return e; } /* sdb_store_expr_create */ sdb_store_expr_t * sdb_store_expr_fieldvalue(int field) { sdb_data_t value = { SDB_TYPE_INTEGER, { .integer = field } }; + sdb_store_expr_t *e; + if ((field < 0) || (SDB_FIELD_BACKEND < field)) return NULL; - return SDB_STORE_EXPR(sdb_object_create("store-fieldvalue", expr_type, + e = SDB_STORE_EXPR(sdb_object_create("store-fieldvalue", expr_type, FIELD_VALUE, NULL, NULL, &value)); + e->data_type = SDB_FIELD_TYPE(field); + return e; } /* sdb_store_expr_fieldvalue */ sdb_store_expr_t * @@ -142,6 +155,7 @@ sdb_store_expr_attrvalue(const char *name) ATTR_VALUE, NULL, NULL, &value)); if (! expr) free(value.data.string); + expr->data_type = -1; return expr; } /* sdb_store_expr_attrvalue */ @@ -149,10 +163,14 @@ sdb_store_expr_t * sdb_store_expr_constvalue(const sdb_data_t *value) { sdb_data_t data = SDB_DATA_INIT; + sdb_store_expr_t *e; + if (sdb_data_copy(&data, value)) return NULL; - return SDB_STORE_EXPR(sdb_object_create("store-constvalue", expr_type, + e = SDB_STORE_EXPR(sdb_object_create("store-constvalue", expr_type, 0, NULL, NULL, &data)); + e->data_type = data.type; + return e; } /* sdb_store_expr_constvalue */ int diff --git a/src/include/core/store.h b/src/include/core/store.h index b82ae2e..97bb6e6 100644 --- a/src/include/core/store.h +++ b/src/include/core/store.h @@ -106,6 +106,14 @@ enum { : ((f) == SDB_FIELD_INTERVAL) ? "interval" \ : ((f) == SDB_FIELD_BACKEND) ? "backend" : "unknown") +#define SDB_FIELD_TYPE(f) \ + (((f) == SDB_FIELD_NAME) ? SDB_TYPE_STRING \ + : ((f) == SDB_FIELD_LAST_UPDATE) ? SDB_TYPE_DATETIME \ + : ((f) == SDB_FIELD_AGE) ? SDB_TYPE_DATETIME \ + : ((f) == SDB_FIELD_INTERVAL) ? SDB_TYPE_DATETIME \ + : ((f) == SDB_FIELD_BACKEND) ? (SDB_TYPE_ARRAY | SDB_TYPE_STRING) \ + : -1) + /* * sdb_store_clear: * Clear the entire store and remove all stored objects.