-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql_parser.cpp
More file actions
128 lines (100 loc) · 2.6 KB
/
sql_parser.cpp
File metadata and controls
128 lines (100 loc) · 2.6 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include <iostream>
#include <string>
#include <regex>
using namespace std;
// 本文件将使用正则表达式的方法进行SQL语句解析
const int inf = 0x3f3f3f3f;
// 表
struct Tables {
string name;
string pathName;
vector<string>colName;
vector<string>type;
vector<int>size;
FILE* fp;
};
string defaultPath; // 默认保存路径
// 验证sql语句是否正确
bool validate(string sql){
// 定义标准sql语句
string sqlupdate = "update\.+set\.+(where\.+)?END";
string sqldelete = "delete\.+from\.+where\.+END";
string sqlinsert="insert\.+into\.+(\(\.+/)\.*)?values\(.+\)END";
string sqlcreate="create table\.+\\(\.+\\)END";
string sqlselect="select\.+from\.+(where\.+)?((group by)?|(order by)?|(having)?)END";
string sqldrop ="drop table\.+END";
if(sql.substr(0, 5) == "create") {
}
if(sql.substr(0, 5) == "insert") {
}
if(sql.substr(0, 5) == "delete") {
}
if(sql.substr(0, 5) == "select") {
}
if(sql.substr(0, 5) == "update") {
}
if(sql.substr(0, 4) == "alter") {
}
}
// 创建
void create(string sql){
}
// 插入
void insert(string sql){
}
// 删除
void sql_delete(string sql){
}
// 查询
void select(string sql){
}
// 修改数据
void update(string sql){
}
// 修改表
void alter(string sql){
}
int sql_processer(){
string sql_command;
while (cin >> sql_command){
// 转为小写
for (int i = 0; i < sql_command.size(); i++)
{
sql_command[i] = tolower(sql_command[i]);
}
if(sql_command == "exit") break;
if(!validate(sql_command)) {
cout << "SQL语法错误, 请重新输入! ";
continue;
}
if(sql_command.substr(0, 5) == "create") create(sql_command);
if(sql_command.substr(0, 5) == "insert") insert(sql_command);
if(sql_command.substr(0, 5) == "delete") sql_delete(sql_command);
if(sql_command.substr(0, 5) == "select") select(sql_command);
if(sql_command.substr(0, 5) == "update") update(sql_command);
if(sql_command.substr(0, 4) == "alter") alter(sql_command);
}
}
void info()
{
cout << "input what you want to do:" << endl;
}
void help()
{
cout << "list [database]/[table]" << endl;
cout << "use [database]" << endl;
cout << "delete [database]" << endl;
cout << "" << endl;
cout << "input what you want to do:" << endl;
cout << "input what you want to do:" << endl;
cout << "input what you want to do:" << endl;
}
int main(){
string command;
info();
while (cin >> command)
{
/* code */
}
return 0;
}