HyriseSQLParser/example/example.cpp

42 lines
992 B
C++
Raw Normal View History

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
#include "SQLParser.h"
2016-01-16 12:36:58 +01:00
// contains printing utilities
#include "util/sqlhelper.h"
2016-01-16 12:36:58 +01: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;
hsql::SQLParser::parseSQLString(query, &result);
// check whether the parsing was successful
if (result.isValid()) {
printf("Parsed successfully!\n");
printf("Number of statements: %lu\n", result.size());
for (uint i = 0; i < result.size(); ++i) {
// Print a statement summary.
hsql::printStatementInfo(result.getStatement(i));
}
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
}