Code

store: Add sdb_store_query_prepare_matcher().
[sysdb.git] / src / frontend / analyzer.c
index cf077de41174df7e913ae46b835fd429218b535c..01e1ad357adec6502fc7efc74768bee7cdf03969 100644 (file)
@@ -95,19 +95,30 @@ analyze_expr(int context, sdb_store_expr_t *e, sdb_strbuf_t *errbuf)
                        if (context == (int)e->data.data.integer)
                                return 0;
                        if ((e->data.data.integer == SDB_HOST) &&
-                                       ((context == SDB_SERVICE) || (context == SDB_METRIC)))
+                                       ((context == SDB_SERVICE) || (context == SDB_METRIC)
+                                               || (context < 0)))
                                return 0;
                        sdb_strbuf_sprintf(errbuf, "Invalid expression %s.%s "
                                        "in %s context",
                                        SDB_STORE_TYPE_TO_NAME(e->data.data.integer),
-                                       EXPR_TO_STRING(e->left), SDB_STORE_TYPE_TO_NAME(context));
+                                       EXPR_TO_STRING(e->left),
+                                       context == -1 ? "generic" : SDB_STORE_TYPE_TO_NAME(context));
                        return -1;
 
                case ATTR_VALUE:
-               case FIELD_VALUE:
                case 0:
                        break;
 
+               case FIELD_VALUE:
+                       if ((e->data.data.integer == SDB_FIELD_VALUE)
+                                       && (context != SDB_ATTRIBUTE)) {
+                               sdb_strbuf_sprintf(errbuf, "Invalid expression %s.value "
+                                               "(only attributes have a value)",
+                                               SDB_STORE_TYPE_TO_NAME(context));
+                               return -1;
+                       }
+                       break;
+
                default:
                        if (analyze_expr(context, e->left, errbuf))
                                return -1;
@@ -161,7 +172,7 @@ analyze_matcher(int context, int parent_type,
 
                        if ((ITER_M(m)->iter->type == TYPED_EXPR)
                                        || (ITER_M(m)->iter->type == FIELD_VALUE))
-                               type = ITER_M(m)->iter->data.data.integer;
+                               type = (int)ITER_M(m)->iter->data.data.integer;
 
                        if (context == -1) { /* inside a filter */
                                /* attributes are always iterable */