-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.cpp
More file actions
63 lines (53 loc) · 1.32 KB
/
database.cpp
File metadata and controls
63 lines (53 loc) · 1.32 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
#include "database.h"
Database::Database(std::string name, std::vector<Table> db) {
this->name = name;
this->db = db;
}
std::vector<Table> Database::getTables() {
return db;
}
Table Database::getTable(std::string name) {
std::vector<Table>::iterator iter;
for (iter = db.begin(); iter != db.end(); iter++) {
if ((*iter).getName().compare(name) == 0) {
return *iter;
}
}
// if don't exist, return null
std::vector<Column> nul;
std::vector<std::string> pk;
std::string fuck = "";
Table t(fuck, nul, pk);
return t;
}
Table& Database::getTableRef(std::string name) {
std::vector<Table>::iterator iter;
for (iter = db.begin(); iter != db.end(); iter++) {
if ((*iter).getName().compare(name) == 0) {
return *iter;
}
}
// if don't exist, return null
static std::vector<Column> nul;
static std::vector<std::string> pk;
static std::string fuck = "";
static Table t(fuck, nul, pk);
return t;
}
void Database::addTable(Table t) {
db.push_back(t);
}
/*
* check whether the table is exist
*/
bool Database::isTableExist(std::string name) {
bool isExist = false;
std::vector<Table>::iterator iter;
for (iter = db.begin(); iter != db.end(); iter++) {
if ((*iter).getName().compare(name) == 0) {
isExist = true;
break;
}
}
return isExist;
}