-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstr.h
150 lines (131 loc) · 3.66 KB
/
str.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
#ifndef STR_H_H
#define STR_H_H
#define MAX_NUM 20
#define MAX_REL_NAME 20
#define MAX_ATTR_NAME 20
#define MAX_ERROR_MESSAGE 20
#define MAX_DATA 50
/*
文件: str.h
内容: the definition of sqls' structs
*/
#include<stdlib.h>
#include<string.h>
#include "RC.h"
//属性结构体
typedef struct {
char* relName; // relation name (may be NULL) 表名
char* attrName; // attribute name 属性名
}RelAttr;
typedef enum {
EQual, //"=" 0
LEqual, //"<=" 1
NEqual, //"<>" 2
LessT, //"<" 3
GEqual, //">=" 4
GreatT, //">" 5
NO_OP
}CompOp;
//属性值类型
typedef enum {
chars,
ints,
floats
}AttrType;
//属性值
typedef struct _Value Value;
struct _Value {
AttrType type; // type of value
void* data; // value
};
typedef struct _Condition Condition;
struct _Condition {
int bLhsIsAttr; // TRUE if left-hand side is an attribute
Value lhsValue; // left-hand side value if bLhsIsAttr = FALSE
RelAttr lhsAttr; // left-hand side attribute
CompOp op; // comparison operator
int bRhsIsAttr; // TRUE if right-hand side is an attribute
// and not a value
RelAttr rhsAttr; // right-hand side attribute if bRhsIsAttr = TRUE
Value rhsValue; // right-hand side value if bRhsIsAttr = FALSE
};
//struct of select
typedef struct {
int nSelAttrs; //Length of attrs in Select clause
RelAttr* selAttrs[MAX_NUM]; //attrs in Select clause
int nRelations; //Length of relations in Fro clause
char* relations[MAX_NUM]; //relations in From clause
int nConditions; //Length of conditions in Where clause
Condition conditions[MAX_NUM];//conditions in Where clause
}selects;
//struct of insert
typedef struct {
char* relName; //Relation to insert into
int nValues; //Length of values
Value values[MAX_NUM];//values to insert
}inserts;
//struct of delete
typedef struct {
char* relName; //Relation to delete from
int nConditions; //Length of conditions in Where clause
Condition conditions[MAX_NUM]; //conditions in Where clause
}deletes;
//struct of update
typedef struct {
char* relName; //Relation to update
char* attrName; //Attribute to update
Value value; //update value
int nConditions; //Length of conditions in Where clause
Condition conditions[MAX_NUM]; // conditions in Where clause
}updates;
//struct of AttrInfo
typedef struct _AttrInfo AttrInfo;
struct _AttrInfo {
char* attrName; //Attribute name
AttrType attrType; //Type of attribute
int attrLength; //Length of attribute
};
//struct of craete_table
typedef struct {
char* relName; //Relation name
int attrCount; //Length of attribute
AttrInfo attributes[MAX_NUM]; //attributes
}createTable;
//struct of drop_table
typedef struct {
char* relName; //Relation name
}dropTable;
//struct of create_index
typedef struct {
char* indexName; // Index name
char* relName; // Relation name
char* attrName; // Attribute name
}createIndex;
//struct of drop_index
typedef struct {
char* indexName; // Index name
}dropIndex;
//union of sql_structs
union sqls {
selects sel;
inserts ins;
deletes del;
updates upd;
createTable cret;
dropTable drt;
createIndex crei;
dropIndex dri;
char* errors;
};
// struct of flag and sql_struct
typedef struct {
int flag; /*match to the sqls 0--error;1--select;2--insert;3--update;4--delete;5--create table;6--drop table;7--create index;8--drop index;9--help;10--exit;*/
union sqls sstr;
}sqlstr;
#ifdef __cplusplus
extern "C" {
sqlstr* get_sqlstr();
RC parse(char* st, sqlstr* sqln);
};
#endif
#endif