-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.cc
More file actions
63 lines (59 loc) · 2.18 KB
/
Copy pathtest.cc
File metadata and controls
63 lines (59 loc) · 2.18 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "sql_parser.h"
#include <fstream>
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cstdlib>
int main(int argc, char *argv[])
{
if (argc < 2) {
std::cerr << "usage: " << argv[0] << " file [num] [print]" << std::endl;
return -1;
}
int run_num = 1;
if (argc >= 3) {
run_num = atoi(argv[2]);
}
int print = 1;
if (argc >= 4) {
print = atoi(argv[3]);
}
std::ifstream ifs(argv[1], std::ios::in);
std::vector<std::string> sqls;
while (!ifs.eof()) {
char sql_buf[255];
ifs.getline(sql_buf, sizeof(sql_buf));
size_t sql_len = strlen(sql_buf);
if (sql_len <= 0) continue;
sqls.push_back(sql_buf);
}
SQLParser<std::string::const_iterator> sql_parser;
for (int i = 0; i < run_num; ++i) {
for (std::vector<std::string>::iterator iter = sqls.begin(); iter != sqls.end(); ++iter) {
std::string::const_iterator begin = iter->begin();
std::string::const_iterator end = iter->end();
SelectSQL select_sql;
bool ret = boost::spirit::qi::phrase_parse(begin, end, sql_parser,
boost::spirit::ascii::space,
select_sql);
if (ret && begin == end) {
if (print) {
std::cout << "phrase_parse succ. sql=" << *iter << std::endl;
for (std::vector<std::string>::iterator iter = select_sql.fields.begin(); iter != select_sql.fields.end(); ++iter) {
std::cout << "[field]=" << *iter << std::endl;
}
std::cout << "[table]=" << select_sql.table << std::endl;
if (select_sql.has_condition) {
std::cout << "[condition]=" << select_sql.condition << std::endl;
}
std::cout << "=============" << std::endl;
}
} else {
std::cerr << "[FAIL]phrase_parse fail. sql=" << *iter << std::endl;
std::cerr << "=============" << std::endl;
}
}
}
return 0;
}