2015-12-23 16:47:04 +01:00
|
|
|
|
2016-01-16 12:36:58 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string>
|
|
|
|
|
2015-12-23 17:00:41 +01:00
|
|
|
// include the sql parser
|
2015-12-23 16:47:04 +01:00
|
|
|
#include "SQLParser.h"
|
|
|
|
|
2016-01-16 12:36:58 +01:00
|
|
|
// contains printing utilities
|
2017-04-07 15:47:51 +02:00
|
|
|
#include "util/sqlhelper.h"
|
2016-01-16 12:36:58 +01:00
|
|
|
|
2017-05-27 00:18:52 +02:00
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
if (argc <= 1) {
|
|
|
|
fprintf(stderr, "Usage: ./example \"SELECT * FROM test;\"\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
std::string query = argv[1];
|
|
|
|
|
|
|
|
// parse a given query
|
|
|
|
hsql::SQLParserResult result;
|
2017-07-21 02:47:45 +02:00
|
|
|
hsql::SQLParser::parse(query, &result);
|
2017-05-27 00:18:52 +02:00
|
|
|
|
|
|
|
// check whether the parsing was successful
|
|
|
|
|
|
|
|
if (result.isValid()) {
|
|
|
|
printf("Parsed successfully!\n");
|
|
|
|
printf("Number of statements: %lu\n", result.size());
|
|
|
|
|
2017-06-14 22:46:43 +02:00
|
|
|
for (auto i = 0u; i < result.size(); ++i) {
|
2017-05-27 00:18:52 +02:00
|
|
|
// Print a statement summary.
|
|
|
|
hsql::printStatementInfo(result.getStatement(i));
|
2015-12-23 16:47:04 +01:00
|
|
|
}
|
2017-05-27 00:18:52 +02:00
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Given string is not a valid SQL query.\n");
|
|
|
|
fprintf(stderr, "%s (L%d:%d)\n",
|
|
|
|
result.errorMsg(),
|
|
|
|
result.errorLine(),
|
|
|
|
result.errorColumn());
|
|
|
|
return -1;
|
|
|
|
}
|
2017-02-08 13:51:50 +01:00
|
|
|
}
|