HyriseSQLParser/example/example.cpp

36 lines
865 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 "sqlhelper.h"
int main(int argc, char *argv[]) {
if (argc <= 1) {
fprintf(stderr, "Usage: ./example \"SELECT * FROM test;\"\n");
return -1;
}
std::string query = argv[1];
2015-12-23 17:00:41 +01:00
// parse a given query
2016-02-27 16:40:24 +01:00
hsql::SQLParserResult* result = hsql::SQLParser::parseSQLString(query);
2015-12-23 17:00:41 +01:00
// check whether the parsing was successful
2016-01-16 12:36:58 +01:00
if (result->isValid) {
printf("Parsed successfully!\n");
2016-02-27 16:40:24 +01:00
printf("Number of statements: %lu\n", result->size());
2016-01-16 12:36:58 +01:00
for (hsql::SQLStatement* stmt : result->statements) {
// process the statements...
hsql::printStatementInfo(stmt);
}
2016-02-27 16:40:24 +01:00
return 0;
} else {
printf("Invalid SQL!\n");
2016-02-27 16:40:24 +01:00
return -1;
}
}