-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauxiliary.hpp
179 lines (163 loc) · 3.8 KB
/
auxiliary.hpp
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
//
// aux.hpp
// MiniSQL
//
// Created by jason on 10/11/15.
// Copyright © 2015 jason. All rights reserved.
//
#ifndef aux_hpp
#define aux_hpp
#include <iostream>
#include <string>
#include <vector>
#include <map>
using namespace std;
/*
create table
drop table
create index
drop index
insert into
select from
delete from
create table student (
sno char(8),
sname char(16) unique,
sage int,
sgender char (1),
primary key ( sno )
);
drop table student;
create index stunameidx on student ( sname );
DROP INDEX indexname ON tblname
select * from student where sage > 20 and sgender = ‘F’;
delete from student where sage > 20 and sgender = ‘F’
*/
class Where
{
public:
string attribute;
string op;
string parameter;
};
class WhereForRecorder
{
public:
int type;
string op;
string value;
int offset; //the first: 0
int length; //int, float: 0, char: not 0
};
class AUX
{
protected:
string database_name;
string table_name;
string type;
string information;
string content;
public:
AUX(){}
void setTableName(string name){table_name = name;}
void setType(string type_in){type = type_in;}
void setContent(string content_in){content = content_in;}
void setInformation(string info){information = info;}
string getType(){return type;}
string getInformation(){return information;}
string getDatabaseName(){return database_name;}
string getTableName(){return table_name;}
string getContent(){return content;}
bool quit;
};
class AUXCreateTable : public AUX
{
private:
//3 variables for attr
map<string, string> attributes;
map<string, int> attributes_length;
map<string, int> float_size;
vector<string> attributes_order;
string primary_key;
vector<string> unique;
public:
AUXCreateTable(){}
void setAttributes(string attr_name, string attr_type, int length);
void setFloatSize(string attr_name, int size);
void setPrimaryKeys(string key);
void setUnique(string unique);
map<string, string> getAttributes();
map<string, int> getAttributesLength();
vector<string> getAttributesOrder();
string getPrimaryKey();
vector<string> getUniqueKeys();
};
class AUXDropTable : public AUX
{
public:
AUXDropTable(){}
};
class AUXCreateIndex : public AUX
{
private:
string index_name;
string attribute_name;
public:
void setIndexName(string name);
void setAttributeName(string name);
string getIndexName();
string getAttributeName();
};
class AUXDropIndex : public AUX
{
private:
string index_name;
public:
void setIndexName(string name);
string getIndexName();
};
class AUXInsertInto : public AUX
{
private:
vector<string> attributes_name;
vector<string> values;
public:
void setAttributes(string value);
void setValues(string value);
vector<string> getAttributeNames();
vector<string> getValues();
};
class AUXSelectFrom : public AUX
{
private:
vector<string> attributes;
vector<Where> conditions;
bool all_values = false;
bool all_attributes = false;
public:
void setAttributes(string attribute);
void setConditions(Where condition);
void setIsAllValues(bool in);
void setIsAllAttributes(bool in);
vector<string> getAttributes();
vector<Where> getConditions();
bool getIsAllValues();
bool getIsAllAttributes();
};
class AUXDeleteFrom : public AUX
{
private:
vector<Where> conditions;
bool delete_all = false;
public:
void setConditions(Where condition);
vector<Where> getConditions();
void setIsDeleteAll(bool in);
bool getIsDeleteAll();
};
bool isNumber(string input);
bool isFloat(string input);
bool isInt(string input);
bool checkAttrNameValid(string input);
string normalize(string input);
#endif /* aux_hpp */