added a grammar test executable

This commit is contained in:
Pedro 2014-11-03 23:26:44 +01:00
parent ff0167cde6
commit 1ee767a31e
3 changed files with 56 additions and 4 deletions

View File

@ -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)

View File

@ -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"

37
src/sql_grammar_test.cpp Normal file
View File

@ -0,0 +1,37 @@
#include <stdio.h>
#include <string>
#include <chrono>
#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<std::chrono::system_clock> start, end;
start = std::chrono::system_clock::now();
// Parsing
Statement* stmt = SQLParser::parseSQLString(sql);
end = std::chrono::system_clock::now();
std::chrono::duration<double> 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;
}