forked from dansontong/simpleDB
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
41 lines (33 loc) · 984 Bytes
/
main.cpp
File metadata and controls
41 lines (33 loc) · 984 Bytes
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
#include <stdlib.h>
#include <string>
// include the sql parser
#include "SQLParser.h"
// contains printing utilities
#include "util/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::parse(query, &result);
// check whether the parsing was successful
if (result.isValid()) {
printf("Parsed successfully!\n");
printf("Number of statements: %lu\n", result.size());
for (auto i = 0u; 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;
}
}