-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
151 lines (134 loc) · 4.28 KB
/
main.cpp
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
#include "BPlus_Tree.h"
#include "minisql.h"
#include "Interpreter.h"
#include "IndexManager.h"
#include "API.h"
#include "ctime"
#include "fstream"
using namespace std;
/*void Print_Block(IndexInfo index, int k)
{
<< "----------------------- " << k << " -----------------------" << endl;
int type, keynum;
memcpy(&type, indexBlock[k], 4);
memcpy(&keynum, indexBlock[k] + 4, 4);
int ofst = INDEX_BLOCK_INFO;
cout << type << ' ' << keynum << ' ' << index.maxKeyNum << endl;
for (int i = 0; i < keynum; i++){
int position;
float key;
memcpy(&position, indexBlock[k] + ofst , 4);
getElement(&key, indexBlock[k] + ofst + 4, 4);
ofst += 8;
cout << position << ' ' << key << endl;
}
//ÑéÖ¤²åÈëÄ£¿éÊÇ·ñÕýÈ·
int next;
memcpy(&next, indexBlock[k] + ofst, 4);
cout << next << endl;
}*/
/*int main()
{
ifstream infile;
infile.open("./student/student.txt", ios::in);
if (!infile) {
cerr << "Can't open file!" << endl;
exit(1);
}
char cmd[1024];
char ch;
int i;
while (!infile.eof()){
i = 0;
memset(cmd, 0, 1024);
infile.getline(cmd, 1024);
if (infile.eof()) break;
string command(cmd);
handleWithCommand(command);
}
return 0;
}*/
int main()
{
Block();
cout << "-----------------------------------------MINISQL-----------------------------------------\n"
"|Copyright(c) 2016, 2016, Wang Haobo, Zhang Jin, Qiu Zhenting and / or its affiliates. |\n"
"|All rights reserved.Other names may be trademarks of their respective owners. |\n"
"| |\n"
"|Type ';' to Run your codes.Type 'exit;' quit the execution. |\n"
"-----------------------------------------------------------------------------------------"
<< endl;
while (1){
clock_t start, end;
cout << "zwqSQL>";
try{
string command = getUserCommand();
start = clock();
if (command == "exit;") break;
handleWithCommand(command);
end = clock();
cout << "(" << double(end - start)/CLOCKS_PER_SEC << " sec)" << endl;
}
catch (File_openfail fo){
cerr << "Error: 1001 (ER_CANT_OPEN_FILE)" << endl;
cerr << "Message: Can't open file: '" << fo.filename << "'!" << endl;
}
catch (Grammer_error ge){
cerr << "Error: 1002 (ER_SYNTAX_ERROR)" << endl;
cerr << "Message: You have an error in your SQL syntax.At position :" << ge.errorPos << "." << endl;
}
catch (Conflict_Error ce){
cerr << "Error: 1169 (ER_DUP_UNIQUE)" << endl;
cerr << "Message: Can't write, because of unique constraint, to table '" << ce.tablename << "' " << endl;
}
catch (Table_Index_Error te){
cerr << "Error: 1760 (ER_DUP_UNIQUE)" << endl;
cerr << "Error: " << te.errorType << " " << te.name << " does not existed!" << endl;
}
catch (Multip_Error me){
cerr << "Error: 1760 (ER_DUP_UNIQUE)" << endl;
cerr << "The attribute maybe multi-valued. Can't create index on it!" << endl;
}
catch (...){
cerr << "Unkonwn Exception." << endl;
}
cout << endl;
/*float id;
int age;
INT32 position;
memcpy(&position, indexBlock[0] + INDEX_BLOCK_INFO, sizeof(INT32));
memcpy(&id, indexBlock[0] + INDEX_BLOCK_INFO + 4, sizeof(float));
cout <<id<<' '<<position << endl;
memcpy(&id, tableBlock[0] + 1, sizeof(float));
memcpy(&age, tableBlock[0] + 4 + 1, sizeof(int));
cout << id << " " << age << endl;*/
getchar();
Block::flush_all_blocks();
//Block::Print();
}
return 0;
}
/*
create table student(
id float primary key,
age int unique);
insert into student values (10001, 18);
insert into student values (10002, 19);
insert into student values (10003, 20);
insert into student values (10004, 21);
insert into student values (10005, 22);
select * from student where id = 10003;
delete from student where id = 10004;
select * from student;
*/
/*drop table student;*/
/*insert into student values('10001', 'zj', 18);
insert into student values('10002', 'hb', 18);
insert into student values('10003', 'qzt', 19);*/
/*
create table student(id int primary key,name int unique);
insert into student values(10001,15);
insert into student values(10002,16);
create index hb on student(name);
select * from student where name > 1000;
*/