added a grammar test executable
This commit is contained in:
parent
ff0167cde6
commit
1ee767a31e
|
@ -26,6 +26,10 @@ execution: $(LIB_FILES) $(EXECUTION_MAIN)
|
||||||
$(CC) $(CFLAGS) $(LIB_FILES) $(EXECUTION_MAIN) -o $(EXECUTION_BIN)
|
$(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)
|
tests: $(LIB_FILES) $(TESTS_MAIN)
|
||||||
$(CC) $(CFLAGS) $(LIB_FILES) $(TESTS_MAIN) -o $(TESTS_BIN)
|
$(CC) $(CFLAGS) $(LIB_FILES) $(TESTS_MAIN) -o $(TESTS_BIN)
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,18 @@ make clean
|
||||||
# make tests
|
# make tests
|
||||||
# ./bin/tests
|
# ./bin/tests
|
||||||
|
|
||||||
make execution
|
# make execution
|
||||||
./bin/sql_execution "SELECT a FROM foo WHERE a > 12 OR b > 3 AND c = 3"
|
# ./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 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"
|
# ./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"
|
|
@ -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;
|
||||||
|
}
|
Loading…
Reference in New Issue