| 9 | #include "util/sqlhelper.h" |
| 10 | |
| 11 | int main(int argc, char* argv[]) { |
| 12 | if (argc <= 1) { |
| 13 | fprintf(stderr, "Usage: ./example \"SELECT * FROM test;\"\n"); |
| 14 | return -1; |
| 15 | } |
| 16 | std::string query = argv[1]; |
| 17 | |
| 18 | // parse a given query |
| 19 | hsql::SQLParserResult result; |
| 20 | hsql::SQLParser::parse(query, &result); |
| 21 | |
| 22 | // check whether the parsing was successful |
| 23 | |
| 24 | if (result.isValid()) { |
| 25 | printf("Parsed successfully!\n"); |
| 26 | printf("Number of statements: %lu\n", result.size()); |
| 27 | |
| 28 | for (auto i = 0u; i < result.size(); ++i) { |
| 29 | // Print a statement summary. |
| 30 | hsql::printStatementInfo(result.getStatement(i)); |
| 31 | } |
| 32 | return 0; |
| 33 | } else { |
| 34 | fprintf(stderr, "Given string is not a valid SQL query.\n"); |
| 35 | fprintf(stderr, "%s (L%d:%d)\n", |
| 36 | result.errorMsg(), |
| 37 | result.errorLine(), |
| 38 | result.errorColumn()); |
| 39 | return -1; |
| 40 | } |
| 41 | } |
no test coverage detected