-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
63 lines (57 loc) · 1.69 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
#include <iostream>
#include "queries/query_factory.cpp"
#include <map>
int main()
{
DbInfo db("db");
cout << "-- Welcome to ooooouuuu database management system -- " << endl;
bool start = true;
while (1)
{
bool error = false;
string errorMessage = "";
string input = "";
if (start)
{
cout << "Here are all the tables available : " << endl;
vector<string> tables = db.getTables();
// display the list of tables
for (auto table : tables) cout << "\t- " << table << endl;
if (tables.size() == 0)cout << "none" << endl;
start = false;
}
cout << "please enter a sql query (or tap exit) :" << endl;
getline(cin, input); // get user input from the keyboard
if (input == "exit")
break;
try
{
QueryFactory factory;
cout << input << endl;
SqlQuery *query = factory.generate_query(input, db);
query->check();
query->execute();
}
catch (const QueryErrorException &e)
{
error = true;
errorMessage = e.getMessage();
}
catch (const exception &e)
{
error = true;
errorMessage = "Unkown error : please try again";
}
if (error)
{
cout << "Error : " << errorMessage << endl;
cout << "try another query :" << endl;
}
else
{
cout << "Your query have been successfuly executed !" << endl;
}
}
cout << " -- exiting oooouuu database management system ----" << endl;
return 0;
}