Code

store: Add sdb_store_query_prepare_matcher().
authorSebastian Harl <sh@tokkee.org>
Tue, 19 May 2015 18:08:56 +0000 (20:08 +0200)
committerSebastian Harl <sh@tokkee.org>
Tue, 19 May 2015 18:08:56 +0000 (20:08 +0200)
This prepares a logical expression described by an AST for execution as a
store matcher. This is useful for anything that uses the lower level store
lookup functions.

src/core/store_query.c
src/include/core/store.h
t/unit/core/store_expr_test.c
t/unit/core/store_lookup_test.c
t/unit/frontend/query_test.c

index 9855063..17ee17f 100644 (file)
@@ -339,4 +339,10 @@ sdb_store_query_prepare(sdb_ast_node_t *ast)
        return QUERY(sdb_object_create(SDB_AST_TYPE_TO_STRING(ast), query_type, ast));
 } /* sdb_store_query_prepare */
 
+sdb_store_matcher_t *
+sdb_store_query_prepare_matcher(sdb_ast_node_t *ast)
+{
+       return node_to_matcher(ast);
+} /* sdb_store_query_prepare_matcher */
+
 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */
index fb59c7c..48866a7 100644 (file)
@@ -391,6 +391,18 @@ typedef struct sdb_store_query sdb_store_query_t;
 sdb_store_query_t *
 sdb_store_query_prepare(sdb_ast_node_t *ast);
 
+/*
+ * sdb_store_query_prepare_matcher:
+ * Prepare the logical expression described by 'ast' for execution as a store
+ * matcher.
+ *
+ * Returns:
+ *  - a matcher on success
+ *  - NULL else
+ */
+sdb_store_matcher_t *
+sdb_store_query_prepare_matcher(sdb_ast_node_t *ast);
+
 /*
  * sdb_store_query_execute:
  * Execute a previously prepared query. The query result will be written to
index 48c128c..679fb54 100644 (file)
@@ -31,7 +31,7 @@
 
 #include "core/store.h"
 #include "core/store-private.h"
-#include "frontend/parser.h"
+#include "parser/parser.h"
 #include "testutils.h"
 
 #include <check.h>
@@ -567,7 +567,10 @@ START_TEST(test_expr_iter)
        }
 
        if (expr_iter_data[_i].filter) {
-               filter = sdb_fe_parse_matcher(expr_iter_data[_i].filter, -1, NULL);
+               sdb_ast_node_t *ast;
+               ast = sdb_parser_parse_conditional(expr_iter_data[_i].filter, -1, NULL);
+               filter = sdb_store_query_prepare_matcher(ast);
+               sdb_object_deref(SDB_OBJ(ast));
                ck_assert(filter != NULL);
        }
 
index 3555495..4466b15 100644 (file)
@@ -31,7 +31,7 @@
 
 #include "core/store.h"
 #include "core/store-private.h"
-#include "frontend/parser.h"
+#include "parser/parser.h"
 #include "testutils.h"
 
 #include <assert.h>
@@ -610,6 +610,7 @@ START_TEST(test_scan)
 {
        sdb_strbuf_t *errbuf = sdb_strbuf_create(64);
        sdb_store_matcher_t *m, *filter = NULL;
+       sdb_ast_node_t *ast;
        int check, n;
 
        n = 0;
@@ -620,17 +621,21 @@ START_TEST(test_scan)
        fail_unless(n == 3,
                        "sdb_store_scan called callback %d times; expected: 3", (int)n);
 
-       m = sdb_fe_parse_matcher(scan_data[_i].query, -1, errbuf);
+       ast = sdb_parser_parse_conditional(scan_data[_i].query, -1, errbuf);
+       m = sdb_store_query_prepare_matcher(ast);
+       sdb_object_deref(SDB_OBJ(ast));
        fail_unless(m != NULL,
-                       "sdb_fe_parse_matcher(%s, -1) = NULL; expected: <matcher> "
+                       "sdb_parser_parse_conditional(%s, -1) = NULL; expected: <ast> "
                        "(parser error: %s)", scan_data[_i].query,
                        sdb_strbuf_string(errbuf));
 
        if (scan_data[_i].filter) {
-               filter = sdb_fe_parse_matcher(scan_data[_i].filter, -1, errbuf);
+               ast = sdb_parser_parse_conditional(scan_data[_i].filter, -1, errbuf);
+               filter = sdb_store_query_prepare_matcher(ast);
+               sdb_object_deref(SDB_OBJ(ast));
                fail_unless(filter != NULL,
-                               "sdb_fe_parse_matcher(%s, -1) = NULL; "
-                               "expected: <matcher> (parser error: %s)",
+                               "sdb_parser_parse_conditional(%s, -1) = NULL; "
+                               "expected: <ast> (parser error: %s)",
                                scan_data[_i].filter, sdb_strbuf_string(errbuf));
        }
 
index a90b00f..9cb613f 100644 (file)
@@ -30,7 +30,6 @@
 #endif
 
 #include "frontend/connection.h"
-#include "frontend/parser.h"
 #include "frontend/connection-private.h"
 #include "testutils.h"