index 18a0235536e3f154128ff576cbc624c9dfa49a5f..c840b0e0a56636ec5b2712d49d22fff155f546b2 100644 (file)
--- a/src/core/store_lookup.c
+++ b/src/core/store_lookup.c
} /* match_logical */
static int
-match_unary(sdb_store_matcher_t *m, sdb_store_obj_t *obj,
+match_uop(sdb_store_matcher_t *m, sdb_store_obj_t *obj,
sdb_store_matcher_t *filter)
{
assert(m->type == MATCHER_NOT);
assert(UOP_M(m)->op);
return !sdb_store_matcher_matches(UOP_M(m)->op, obj, filter);
-} /* match_unary */
+} /* match_uop */
/* iterate: ANY/ALL <iter> <cmp> <value> */
static int
} /* match_regex */
static int
-match_isnull(sdb_store_matcher_t *m, sdb_store_obj_t *obj,
+match_unary(sdb_store_matcher_t *m, sdb_store_obj_t *obj,
sdb_store_matcher_t *filter)
{
sdb_data_t v = SDB_DATA_INIT;
int status;
- assert((m->type == MATCHER_ISNULL) || (m->type == MATCHER_ISNNULL));
+ assert((m->type == MATCHER_ISNULL)
+ || (m->type == MATCHER_ISTRUE)
+ || (m->type == MATCHER_ISFALSE));
- if (ISNULL_M(m)->expr->type) {
+ if (UNARY_M(m)->expr->type) {
/* TODO: this might hide real errors;
* improve error reporting and propagation */
- if (sdb_store_expr_eval(ISNULL_M(m)->expr, obj, &v, filter))
+ if (sdb_store_expr_eval(UNARY_M(m)->expr, obj, &v, filter))
return 1;
}
else
- v = ISNULL_M(m)->expr->data;
-
- if (sdb_data_isnull(&v))
- status = 1;
- else
- status = 0;
+ v = UNARY_M(m)->expr->data;
+
+ if (m->type == MATCHER_ISNULL)
+ status = sdb_data_isnull(&v) ? 1 : 0;
+ else { /* ISTRUE or ISFALSE */
+ if ((v.type == SDB_TYPE_BOOLEAN)
+ && (v.data.boolean == (m->type == MATCHER_ISTRUE)))
+ status = 1;
+ else
+ status = 0;
+ }
- if (ISNULL_M(m)->expr->type)
+ if (UNARY_M(m)->expr->type)
sdb_data_free_datum(&v);
- if (m->type == MATCHER_ISNNULL)
- return !status;
return status;
-} /* match_isnull */
+} /* match_unary */
typedef int (*matcher_cb)(sdb_store_matcher_t *, sdb_store_obj_t *,
sdb_store_matcher_t *);
matchers[] = {
match_logical,
match_logical,
- match_unary,
+ match_uop,
match_iter,
match_iter,
match_in,
match_in,
/* unary operators */
- match_isnull,
- match_isnull,
+ match_unary,
+ match_unary,
+ match_unary,
/* ary operators */
match_cmp,
match_cmp,
match_regex,
match_regex,
+
+ NULL, /* QUERY */
};
/*
} /* uop_matcher_destroy */
static int
-isnull_matcher_init(sdb_object_t *obj, va_list ap)
+unary_matcher_init(sdb_object_t *obj, va_list ap)
{
M(obj)->type = va_arg(ap, int);
- if ((M(obj)->type != MATCHER_ISNULL) && (M(obj)->type != MATCHER_ISNNULL))
+ if ((M(obj)->type != MATCHER_ISNULL)
+ && (M(obj)->type != MATCHER_ISTRUE)
+ && (M(obj)->type != MATCHER_ISFALSE))
return -1;
- ISNULL_M(obj)->expr = va_arg(ap, sdb_store_expr_t *);
- sdb_object_ref(SDB_OBJ(ISNULL_M(obj)->expr));
+ UNARY_M(obj)->expr = va_arg(ap, sdb_store_expr_t *);
+ sdb_object_ref(SDB_OBJ(UNARY_M(obj)->expr));
return 0;
-} /* isnull_matcher_init */
+} /* unary_matcher_init */
static void
-isnull_matcher_destroy(sdb_object_t *obj)
+unary_matcher_destroy(sdb_object_t *obj)
{
- sdb_object_deref(SDB_OBJ(ISNULL_M(obj)->expr));
- ISNULL_M(obj)->expr = NULL;
-} /* isnull_matcher_destroy */
+ sdb_object_deref(SDB_OBJ(UNARY_M(obj)->expr));
+ UNARY_M(obj)->expr = NULL;
+} /* unary_matcher_destroy */
static sdb_type_t op_type = {
/* size = */ sizeof(op_matcher_t),
/* destroy = */ cmp_matcher_destroy,
};
-static sdb_type_t isnull_type = {
- /* size = */ sizeof(isnull_matcher_t),
- /* init = */ isnull_matcher_init,
- /* destroy = */ isnull_matcher_destroy,
+static sdb_type_t unary_type = {
+ /* size = */ sizeof(unary_matcher_t),
+ /* init = */ unary_matcher_init,
+ /* destroy = */ unary_matcher_destroy,
};
/*
sdb_store_matcher_t *
sdb_store_isnull_matcher(sdb_store_expr_t *expr)
{
- return M(sdb_object_create("isnull-matcher", isnull_type,
+ return M(sdb_object_create("isnull-matcher", unary_type,
MATCHER_ISNULL, expr));
} /* sdb_store_isnull_matcher */
sdb_store_matcher_t *
-sdb_store_isnnull_matcher(sdb_store_expr_t *expr)
+sdb_store_istrue_matcher(sdb_store_expr_t *expr)
{
- return M(sdb_object_create("isnull-matcher", isnull_type,
- MATCHER_ISNNULL, expr));
-} /* sdb_store_isnnull_matcher */
+ return M(sdb_object_create("istrue-matcher", unary_type,
+ MATCHER_ISTRUE, expr));
+} /* sdb_store_istrue_matcher */
+
+sdb_store_matcher_t *
+sdb_store_isfalse_matcher(sdb_store_expr_t *expr)
+{
+ return M(sdb_object_create("isfalse-matcher", unary_type,
+ MATCHER_ISFALSE, expr));
+} /* sdb_store_isfalse_matcher */
sdb_store_matcher_op_cb
sdb_store_parse_matcher_op(const char *op)
if ((m->type < 0) || ((size_t)m->type >= SDB_STATIC_ARRAY_LEN(matchers)))
return 0;
+ if (! matchers[m->type])
+ return 0;
return matchers[m->type](m, obj, filter);
} /* sdb_store_matcher_matches */