From 1ee767a31ed1a245cf7d789e5e3022c7a2c86415 Mon Sep 17 00:00:00 2001 From: Pedro Date: Mon, 3 Nov 2014 23:26:44 +0100 Subject: [PATCH] added a grammar test executable --- src/Makefile | 4 ++++ src/build_and_run_tests.sh | 19 +++++++++++++++---- src/sql_grammar_test.cpp | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 src/sql_grammar_test.cpp diff --git a/src/Makefile b/src/Makefile index 8ee7922..2f9b925 100644 --- a/src/Makefile +++ b/src/Makefile @@ -26,6 +26,10 @@ execution: $(LIB_FILES) $(EXECUTION_MAIN) $(CC) $(CFLAGS) $(LIB_FILES) $(EXECUTION_MAIN) -o $(EXECUTION_BIN) +grammar_test: $(LIB_FILES) sql_grammar_test.cpp + $(CC) $(CFLAGS) $(LIB_FILES) sql_grammar_test.cpp -o bin/grammar_test + + tests: $(LIB_FILES) $(TESTS_MAIN) $(CC) $(CFLAGS) $(LIB_FILES) $(TESTS_MAIN) -o $(TESTS_BIN) diff --git a/src/build_and_run_tests.sh b/src/build_and_run_tests.sh index e688a43..244ea1c 100644 --- a/src/build_and_run_tests.sh +++ b/src/build_and_run_tests.sh @@ -4,7 +4,18 @@ make clean # make tests # ./bin/tests -make execution -./bin/sql_execution "SELECT a FROM foo WHERE a > 12 OR b > 3 AND c = 3" -./bin/sql_execution "SELECT col1, col2, 'test' FROM table, foo WHERE age > 12 AND zipcode = 12345 GROUP BY col1;" -./bin/sql_execution "SELECT * from table WHERE (b OR NOT a) AND a = 12.5" +# make execution +# ./bin/sql_execution "SELECT a FROM foo WHERE a > 12 OR b > 3 AND c = 3" +# ./bin/sql_execution "SELECT col1, col2, 'test' FROM table, foo WHERE age > 12 AND zipcode = 12345 GROUP BY col1;" +# ./bin/sql_execution "SELECT * from table WHERE (b OR NOT a) AND a = 12.5 JOIN table2 ON a = b" + +make grammar_test + +echo "\n\n" + +./bin/grammar_test "SELECT a FROM foo WHERE a > 12 OR b > 3 AND c = 3 LIMIT 10" +./bin/grammar_test "(SELECT col1, col2, 'test' FROM table, foo WHERE age > 12 AND zipcode = 12345 GROUP BY col1);" +./bin/grammar_test "SELECT age FROM table, (SELECT * FROM table2) ORDER BY age DESC" +./bin/grammar_test "(SELECT * from table WHERE (b OR NOT a) AND a = 12.5) JOIN table2 ON a = b" + +echo "\n\n" \ No newline at end of file diff --git a/src/sql_grammar_test.cpp b/src/sql_grammar_test.cpp new file mode 100644 index 0000000..611dc54 --- /dev/null +++ b/src/sql_grammar_test.cpp @@ -0,0 +1,37 @@ + +#include +#include +#include +#include "SQLParser.h" + +using namespace hsql; + +int main(int argc, char *argv[]) { + if (argc <= 1) { + fprintf(stderr, "No SQL-Statement given!\n"); + return -1; + } + + for (int n = 1; n < argc; ++n) { + char* sql = argv[n]; + + // Measuring the parsing time + std::chrono::time_point start, end; + start = std::chrono::system_clock::now(); + + // Parsing + Statement* stmt = SQLParser::parseSQLString(sql); + + end = std::chrono::system_clock::now(); + std::chrono::duration elapsed_seconds = end-start; + + if (stmt == NULL) { + fprintf(stderr, "-> Failed (%.3fms)! \"%s\"\n", elapsed_seconds.count()*1000, sql); + continue; + } else { + fprintf(stderr, "Success (%.3fms)! \"%s\"\n", elapsed_seconds.count()*1000, sql); + } + } + + return 0; +} \ No newline at end of file