-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathexample.cpp
More file actions
42 lines (34 loc) · 1.09 KB
/
example.cpp
File metadata and controls
42 lines (34 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdlib.h>
#include <string>
// include the sql parser
#include "SQLParser.h"
// 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];
// parse a given query
hsql::SQLParserResult* result = hsql::SQLParser::parseSQLString(query);
// 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));
}
delete result;
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());
delete result;
return -1;
}
}