-
Notifications
You must be signed in to change notification settings - Fork 0
/
sql.h
128 lines (109 loc) · 3.1 KB
/
sql.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
#ifndef SQL_H
#define SQL_H
#include <string>
#include <vector>
#include <ctime>
#include <cstdio>
#define TIMERBEGIN do{ clock_t c_start = clock();
#define TIMEREND clock_t c_end = clock(); printf("executing time: %ld ms\n", c_end - c_start); } while(0);
using namespace std;
typedef enum{ INT, CHAR } Type;
typedef enum{ COT_AND, COT_OR, COT_LT, COT_GT, COT_EQ, COT_NEQ, COT_LE, COT_GE, COT_ASSIGN, COT_NIL } CmpOpType;
typedef enum{ CORT_ID, CORT_STR, CORT_INT, CORT_NIL } CmpOprType;
struct CreateFieldsDef {
string field;
Type type;
int length;
CreateFieldsDef(string field, Type type, int length) : field(field), type(type), length(length) {}
CreateFieldsDef() {}
};
struct CreateStruct {
string table;
vector<CreateFieldsDef> fields;
CreateStruct(string table, vector<CreateFieldsDef> fields) : table(table), fields(fields) {}
CreateStruct() {}
};
struct Conditions {
Conditions *left = nullptr;
Conditions *right = nullptr;
CmpOpType comp_op;
CmpOprType type;
string value;
string table;
Conditions() {}
Conditions(Conditions *left, Conditions *right, CmpOpType comp_op, CmpOprType type, string value, string table) : left(left), right(right), comp_op(comp_op), type(type), value(value), table(table) {}
~Conditions(){
if(left){
delete left;
left = nullptr;
}
if(right){
delete right;
right = nullptr;
}
}
};
struct SelectedFields {
string table;
string field;
SelectedFields(string table, string field) : table(table), field(field) {}
SelectedFields() {}
};
struct SelectedTables {
string table;
SelectedTables(string table) : table(table) {}
SelectedTables() {}
};
struct SelectStruct {
vector<SelectedFields> sf;
vector<SelectedTables> st;
Conditions *cons = nullptr;
SelectStruct(vector<SelectedFields> sf, vector<SelectedTables> st, Conditions *cons) : sf(sf), st(st), cons(cons) {}
SelectStruct() {}
~SelectStruct() {
if(cons)
delete cons;
}
};
struct InsertStruct {
vector<string> fields;
string table;
vector<string> ins;
InsertStruct(vector<string> fields, string table, vector<string> ins) : fields(fields), table(table), ins(ins) {}
InsertStruct() {}
};
struct DeleteStruct {
string table;
Conditions* cons = nullptr;
DeleteStruct(string table, Conditions* cons) : table(table), cons(cons) {}
DeleteStruct() {}
~DeleteStruct() {
if(cons)
delete cons;
}
};
struct UpdateStruct {
string table;
Conditions* cons = nullptr;
vector<Conditions*> sets;
UpdateStruct(string table, Conditions* cons, vector<Conditions*> sets) : table(table), cons(cons), sets(sets) {}
UpdateStruct() {}
~UpdateStruct() {
if(cons)
delete cons;
for(auto csets : sets){
delete csets;
}
}
};
inline void processBool(bool res){
if(res){
puts("Execution succeed.");
} else {
puts("Execution failed.");
}
}
inline void tips(){
printf("gpsql>");
}
#endif