summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 419b318)
raw | patch | inline | side by side (parent: 419b318)
author | Sebastian Harl <sh@tokkee.org> | |
Fri, 24 Oct 2014 15:59:28 +0000 (17:59 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Fri, 24 Oct 2014 15:59:28 +0000 (17:59 +0200) |
src/core/store-private.h | patch | blob | history | |
src/core/store_expr.c | patch | blob | history | |
src/include/core/store.h | patch | blob | history |
index 7ce807bfa3d9807111453c7f958a5dd994fbb72b..1e2c3ec5b4ef398be8a10f9420b26f53adac93b3 100644 (file)
--- a/src/core/store-private.h
+++ b/src/core/store-private.h
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 ed0589bc28d1a37c32c6ea93400331410b01c532..d5b22c7e89b8c645c1da9f130e1435d90d023122 100644 (file)
--- a/src/core/store_expr.c
+++ b/src/core/store_expr.c
expr->type = type;
expr->left = left;
expr->right = right;
+
+ /* unknown for now */
+ expr->data_type = -1;
return 0;
} /* expr_init */
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 *
ATTR_VALUE, NULL, NULL, &value));
if (! expr)
free(value.data.string);
+ expr->data_type = -1;
return expr;
} /* sdb_store_expr_attrvalue */
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
index b82ae2e9134cb41ca1f4cdb4b77626c454ab0cff..97bb6e65cd56be1afff6a6da035a6ab0ae18803b 100644 (file)
--- a/src/include/core/store.h
+++ b/src/include/core/store.h
: ((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.