2014-11-03 23:26:44 +01:00
|
|
|
|
|
|
|
#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;
|
|
|
|
}
|
|
|
|
|
2014-11-03 23:57:42 +01:00
|
|
|
bool expectFalse = (std::string("-f").compare(std::string(argv[1])) == 0);
|
|
|
|
|
|
|
|
int n = (expectFalse) ? 2 : 1;
|
|
|
|
for (; n < argc; ++n) {
|
2014-11-03 23:26:44 +01:00
|
|
|
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;
|
|
|
|
|
2014-11-04 00:02:40 +01:00
|
|
|
if (expectFalse != (stmt->type == kStmtError)) {
|
2014-11-07 01:09:06 +01:00
|
|
|
fprintf(stderr, "-> Failed (%.3fms)! %s: \"%s\"\n", elapsed_seconds.count()*1000, stmt->parser_msg, sql);
|
2014-11-03 23:26:44 +01:00
|
|
|
continue;
|
|
|
|
} else {
|
2014-11-04 00:02:40 +01:00
|
|
|
if (expectFalse) {
|
|
|
|
printf("Success (%.3fms)! %s: \"%s\"\n", elapsed_seconds.count()*1000, stmt->parser_msg, sql);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
printf("Success (%.3fms)! \"%s\"\n", elapsed_seconds.count()*1000, sql);
|
|
|
|
}
|
2014-11-03 23:26:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|