From: Sebastian Harl Date: Tue, 19 May 2015 18:08:56 +0000 (+0200) Subject: store: Add sdb_store_query_prepare_matcher(). X-Git-Tag: sysdb-0.8.0~86 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=5ced2b9eb4d4def7d3ad5b1172004293e7a68e0e;p=sysdb.git store: Add sdb_store_query_prepare_matcher(). 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. --- diff --git a/src/core/store_query.c b/src/core/store_query.c index 9855063..17ee17f 100644 --- a/src/core/store_query.c +++ b/src/core/store_query.c @@ -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 : */ diff --git a/src/include/core/store.h b/src/include/core/store.h index fb59c7c..48866a7 100644 --- a/src/include/core/store.h +++ b/src/include/core/store.h @@ -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 diff --git a/t/unit/core/store_expr_test.c b/t/unit/core/store_expr_test.c index 48c128c..679fb54 100644 --- a/t/unit/core/store_expr_test.c +++ b/t/unit/core/store_expr_test.c @@ -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 @@ -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); } diff --git a/t/unit/core/store_lookup_test.c b/t/unit/core/store_lookup_test.c index 3555495..4466b15 100644 --- a/t/unit/core/store_lookup_test.c +++ b/t/unit/core/store_lookup_test.c @@ -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 @@ -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: " + "sdb_parser_parse_conditional(%s, -1) = NULL; expected: " "(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: (parser error: %s)", + "sdb_parser_parse_conditional(%s, -1) = NULL; " + "expected: (parser error: %s)", scan_data[_i].filter, sdb_strbuf_string(errbuf)); } diff --git a/t/unit/frontend/query_test.c b/t/unit/frontend/query_test.c index a90b00f..9cb613f 100644 --- a/t/unit/frontend/query_test.c +++ b/t/unit/frontend/query_test.c @@ -30,7 +30,6 @@ #endif #include "frontend/connection.h" -#include "frontend/parser.h" #include "frontend/connection-private.h" #include "testutils.h"