-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
60 lines (58 loc) · 1.56 KB
/
main.cpp
File metadata and controls
60 lines (58 loc) · 1.56 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
#ifndef TEST
#include "parser.hpp"
#include <string>
#include <iostream>
#include <fstream>
void RunStmt(const std::string& sql, Parser& p, Manager& manager) {
try {
auto X = p.parse(sql);
X->Run(manager);
} catch (const char* t) {
std::cout << t << std::endl;
}
}
int main(int argc, char** argv) {
Manager manager;
Parser parser;
if (argc == 2) {
std::ifstream input(argv[1]);
if (!input) {
std::cout << "File Not Found" << std::endl;
return 0;
}
std::vector<char> sql;
char c = '\0';
while (input) {
int x = input.get();
if (x == -1)
break;
if (c == '\0' && x == ';') {
RunStmt(std::string(sql.begin(), sql.end()), parser, manager);
sql.clear();
} else {
if (c == '\0' && x == '\'')
c = '\'';
else if (c == '\0' && x == '"')
c = '"';
else if (c == '\'' && x == '\'')
c = '\0';
else if (c == '"' && x == '"')
c = '\0';
sql.push_back(x);
}
}
} else {
while (true) {
std::string sql;
std::cout << ">> ";
std::getline(std::cin, sql);
if (!std::cin)
break;
if (sql.substr(0, 4) == "exit")
break;
if (!sql.empty())
RunStmt(sql, parser, manager);
}
}
}
#endif