-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
142 lines (130 loc) · 4.26 KB
/
Copy pathmain.cpp
File metadata and controls
142 lines (130 loc) · 4.26 KB
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
#include <cstdio>
#include <cstdlib>
#include <readline/readline.h>
#include <readline/history.h>
#include "Executor.cpp"
//void sigintHandler(int sig_num)
//{
// signal(SIGINT, sigintHandler);
// /*
// Yeh Function run hoga
// */
// printf("\n Cannot be terminated using Ctrl+C \n");
// fflush(stdout);
//}
InputBuffer inputBuffer;
Parser parser;
Executor executor("./MyDatabase");
void runCommand(char* line){
inputBuffer.buffer = line;
if(inputBuffer.isMetaCommand()){
switch(inputBuffer.performMetaCommand()){
case MetaCommandResult::exit:
executor.sharedManager->closeAll();
printw("Exited Successfully\n");
exit(EXIT_SUCCESS);
case MetaCommandResult::flush:
printw("Flushed All Opened Tables.\n");
executor.sharedManager->flushAll();
case MetaCommandResult::empty:
return;
case MetaCommandResult::unrecognized:
printw("Unrecognized command '%s'.\n", inputBuffer.str());
return;
}
}
switch(parser.parse(inputBuffer)){
case PrepareResult::success:
break;
case PrepareResult::syntaxError:
printw("Syntax Error. Could not parse statement\n");
return;
case PrepareResult::stringTooLong :
printw("String is too long.\n");
return;
case PrepareResult::negativeID:
printw("ID must be positive.\n");
return;
case PrepareResult::invalidType:
printw("Invalid Data Type.\n");
return;
case PrepareResult::noSizeForString:
printw("No size provided for string.\n");
return;
case PrepareResult::unrecognized:
printw("Unrecognized keyword at start of '%s'.\n", inputBuffer.str());
return;
case PrepareResult::invalidOperator:
printw("Invalid Operator\n");
return;
case PrepareResult::comparisonOnDifferentRows:
printw("Comparison on different rows is not allowed\n");
return;
case PrepareResult::cannotCreateEmptyTable:
printw("Cannot Create Empty Table. Please add some columns\n");
return;
case PrepareResult::noTableName:
printw("Please provide Table Name\n");
return;
case PrepareResult::noInsertData:
printw("No Data Provided to Insert\n");
return;
case PrepareResult::noUpdateData:
printw("No Data Provided to Update\n");
return;
case PrepareResult::noCondition:
printw("Provide Condition To Delete Selected Table using `where` clause.\n"
"To delete all entries use `delete table` instead\n");
return;
}
switch(executor.execute(parser)){
case ExecuteResult::success:
printw("Executed.\n");
break;
case ExecuteResult::tableFull:
printw("Error: Table full.\n");
break;
case ExecuteResult::faliure:
printw("Action Failed\n");
break;
case ExecuteResult::typeMismatch:
printw("Type Mismatch Occured\n");
break;
case ExecuteResult::stringTooLarge:
printw("String Too Large\n");
break;
case ExecuteResult::invalidColumnName:
printw("Column names don't match table column names\n");
break;
case ExecuteResult::tableNotIndexed:
printw("There are no indexes for this table.\n"
"Create atleast one and then try again.\n");
break;
case ExecuteResult::unexpectedError:
printw("Unexpected Error occured\n");
break;
}
}
int main(){
while(true){
char* line = readline("db> ");
if(!line) break;
if(*line) add_history(line);
runCommand(line);
}
return 0;
}
//int main() {
//// signal(SIGINT, sigintHandler);
//// CommandInput commandInput;
//// int c;
//// initscr();
//// commandInput.initialize();
// while(true){
// func();
//// c = getch();
//// commandInput.handleKeys(c);
// }
// endwin();
// return 0;
//}