-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMinisql.h
118 lines (102 loc) · 3.17 KB
/
Minisql.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
#ifndef __MINISQL__H__
#define __MINISQL__H__
#include <iostream>
#include <string>
#include <stdlib.h>
#include <math.h>
#include <fstream>
#include <direct.h>
#include <algorithm>
#include <vector>
#include <map>
#include <list>
using namespace std;
#define FILE_COUNTER 1
#define FILE_INFO_LENGTH 671
#define ATTR_INFO_LENGTH 20
#define FILE_HEAD_LENGTH 31
typedef map< string, vector<string> > AttributeValuesMap;
enum TYPE { MYINT, MYFLOAT, MYCHAR };
enum RELATION_TYPE { UNDEFINED_RELATION, EQUAL, NOT_EQUAL, GREATER, GREATER_EQUAL, SMALLER, SMALLER_EQUAL, AND, OR };
enum STATEMENT_TYPE { CREATE_DATABASE, CREATE_TABLE, CREATE_INDEX, DROP_TABLE, DROP_INDEX, DROP_DATABASE, SELECT, SELECT_WHERE, INSERT, MYDELETE, DELETE_WHERE, USE, EXECFILE, QUIT, HELP, ILLEGAL};
//定义属性信息
class Attribute
{
public:
friend class CatalogManager;
friend class Table;
string name ;
string indexName ; //index名
TYPE type ;
int length ;
bool isPrimaryKey ;
bool isUnique ;
Attribute():name(""),indexName(""),type(MYINT),length(0),isPrimaryKey(false),isUnique(false){}
Attribute(const Attribute & from) :name(from.name), indexName(from.indexName), type(from.type), length(from.length), isPrimaryKey(from.isPrimaryKey), isUnique(from.isUnique){}
Attribute(string name) :name(name){}
Attribute(string name, TYPE type, int length, bool isPrimaryKey = false, bool isUnique = false) :name(name), type(type), length(length), isPrimaryKey(isPrimaryKey), isUnique(isUnique){}
~Attribute(){}
};
//定义条件信息
class Condition
{
public:
Attribute attribute;
string value;
RELATION_TYPE relationType;
Condition(){}
Condition(Attribute attribute, string value, RELATION_TYPE relationType) :attribute(attribute), value(value), relationType(relationType){}
~Condition(){}
};
//定义表信息
class Table
{
public:
string name; // 表名
int blockNum ; // 在name.table中占用的block数
int recordNum; // 记录条数
int attriNum; // 属性数
int tupleLength; // 每条记录的长度
string primaryKey; // 主键名字
//int freeNum = 0; // 有几条被删除的记录
vector<Attribute> attributes; // 指向元数据链表的指针
//vector<Attribute>::iterator AttriItor; // Attribute的iterator
//vector<string> data; // 指向数据链表的指针
//long dataBlockInFile = -1; // data开头在file中的块的位置(每张表的数据一定是从一块的开头开始)
//vector<string> emptyList; // 指向等待删除链表的指针(这东西到底干吗用)
Table():blockNum(0),recordNum(0),attriNum(0),tupleLength(0){}
Table(string name, string primaryKey) :name(name), primaryKey(primaryKey){}
~Table(){}
};
// 语句类
class SQLstatement
{
public:
STATEMENT_TYPE type;
string tableName;
string indexName;
vector<Attribute> attributes;
vector<Condition> conditions;
//vector<RELATION_TYPE> relations;
string content;
SQLstatement(STATEMENT_TYPE type, string tableName);
SQLstatement(string SQL);
~SQLstatement();
void outputinfo();
Condition genCondition(string exp);
RELATION_TYPE getRelationType(string oper);
STATEMENT_TYPE identify(string type_code);
};
// 定义索引信息
class Index
{
public:
string index_name;
string table_name;
int startposition;
int tuplelength;
int columnLength;
int IndexOffset;
Index() :IndexOffset(0){}
};
#endif