-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabase.cc
More file actions
51 lines (40 loc) · 1.41 KB
/
Copy pathDatabase.cc
File metadata and controls
51 lines (40 loc) · 1.41 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
#include "Database.h"
#include "Schema.h"
#include "DBFile.h"
#include "Comparison.h"
#include <iostream>
using namespace std;
void Database::Create(char *tableName, ColumnList *columns, NameList *order) {
Schema schema(columns);
schema.WriteToFile(tableName);
std::string fileName = std::string("data/") + tableName + ".bin";
if (order) {
OrderMaker orderMaker(&schema, order);
SortInfo sortInfo(&orderMaker, 100);
DBFile dbFile;
dbFile.Create(fileName.c_str(), sorted, &sortInfo);
dbFile.Close();
} else {
DBFile dbFile;
dbFile.Create(fileName.c_str(), heap, nullptr);
dbFile.Close();
}
}
void Database::Load(char *tableName, char *filePath) {
char *schemaPath = const_cast<char *>((std::string("schema/") + tableName).c_str());
Schema schema(schemaPath, tableName);
DBFile dbFile;
std::string table = std::string("data/") + tableName + ".bin";
// std::cerr << "Schema Complete\n";
dbFile.Open(table.c_str());
dbFile.Load(schema, filePath);
dbFile.Close();
}
void Database::Drop(char *tableName) {
std::string schemaPath = std::string("schema/") + tableName;
remove(schemaPath.c_str());
std::string table = std::string("data/") + tableName + ".bin";
remove(table.c_str());
std::string tableMetadata = std::string("data/") + tableName + ".bin.metadata";
remove(tableMetadata.c_str());
}