-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDataBase.cpp
More file actions
46 lines (44 loc) · 974 Bytes
/
DataBase.cpp
File metadata and controls
46 lines (44 loc) · 974 Bytes
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
#include"DataBase.h"
#include"sql.h"
#include"Table.h"
#include<vector>
DataBase::DataBase(string name):name(name)
{
}
DataBase::DataBase(DataBase && d):name(d.name), tables(d.tables) {
d.tables.clear();
}
DataBase & DataBase::operator=(DataBase && d) {
if (&d==this) return *this;
// 就地重新构造
this->~DataBase();
return *new(this) DataBase(std::move(d));
}
void DataBase::CreateTable(SQLCreateTable& statement)
{
tables.push_back(new Table(statement.get_tb_name(), statement.GetAttributes(), statement.get_primary()));
}
void DataBase::DropTable(string name)
{
for(int i = 0; i < tables.size(); ++i)
if(tables[i]->name == name)
{
tables.erase(tables.begin() + i); //
break;
}
}
Table* DataBase::getTB(string name)
{
for(int i = 0; i < tables.size(); ++i)
if(tables[i]->name == name)
return tables[i];
}
vector<Table*> DataBase::GetTables()
{
return tables;
}
DataBase::~DataBase() {
for (auto i: tables)
delete i;
tables.clear();
}