-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommand.h
179 lines (164 loc) · 2.93 KB
/
command.h
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#pragma once
#include "structure.h"
#define MAX_ID_LENGTH 256
/*
typedef enum FUNC_MODE {
SUM, COUNT, NOR
}MODE;
typedef enum CAL {
GRE, LESS, EQU, NEQ
}OP;
typedef enum LOGIC_RELATION {
_AND, _OR
}LOGIC;
class select_attr {
public:
string attr_name;
bool alias;
string tablename;
int table_index;
int attr_index;
};
*/
class Insert_Command {
public:
string tablename;
vector<string> attr_name;
vector<Value> insert_values;
Insert_Command() {
attr_name.reserve(11);
insert_values.reserve(11);
}
void Set_Name(string &s)
{
//if (s.find(" ")!=s.length()-1)
//{
// printf("Parser error");
// exit(-1);
//}
tablename = s;
return;
}
void Add_Attribute(string &s)
{
attr_name.push_back(s);
return;
}
void Add_Value(string &s)
{
char type[20];
TYPE t = _NULL;
string v;
/*sscanf(s.c_str(), "%s", type);
if (strcmp(type, "int") == 0)
{
t = _INT;
}
if (strcmp(type, "str") == 0)
{
t = VARCHAR;
}
v = s.substr(4);*/
Value temp(t, v);
insert_values.push_back(temp);
return;
}
};
class Create_Command {
public:
string tablename;
vector<Attribute> attributes;
Create_Command() {
attributes.reserve(11);
}
void Set_Name(string &s)
{
/*if (s.find(" ") != s.length() - 1)
{
printf("Parser error\n");
return;
}*/
char temp[MAX_ID_LENGTH];
sscanf(s.c_str(),"%s", temp);
tablename = temp;
return;
}
void Add_Attribute(string &s)
{
string names;
TYPE t=_NULL;
int l = 0;
bool pri = false;
bool n = false;
char namec[MAX_ID_LENGTH];
char type[20];
sscanf(s.c_str(), "%s %s", namec, type);
//cout << type << endl;
names = namec;
if (strcmp(type, "int") == 0)t = _INT;
if (strstr(type, "varchar")) {
t = VARCHAR;
sscanf(type, "varchar(%d)", &l);
}
if (strstr(s.c_str(), "PRIMARY KEY"))
{
pri = n = true;
}
if (t == _NULL)
{
printf("Invalid type!");
return;
}
Attribute temp(names, t, l, pri, n);
attributes.push_back(temp);
return;
}
};
class Select_Command {
public:
vector<string> tablename;
bool is_all;
// is_all 就是 * ,代表选取所有的attr
MODE func_mode;
vector<select_attr> attr;
Condition condt;
Select_Command() {
tablename.reserve(2);
attr.reserve(11);
}
void Collapse()
{
tablename.clear();
is_all = false;
func_mode = NOR;
attr.clear();
condt.exp_num = 0;
return;
}
};
/*
class Element {
public:
bool is_imme;
// imme 有可能是数字,也有可能是字符串, 用string来表示,如果是整数类型,换成数字来做
string imme;
// 不是立即数则是一个Attr, 而且这个Attr不一定出现在select后面,要从表中找
select_attr attr;
Element() {};
};
class Expression {
public:
Element elem1;
Element elem2;
OP op;
Expression() {};
};
class Condition {
public:
int exp_num;
Expression exp1;
Expression exp2;
LOGIC logic;
Condition() {};
};
*/