2015-09-15 16:30:25 -05:00
|
|
|
#include <fstream>
|
|
|
|
#include <iostream>
|
|
|
|
#include <vector>
|
|
|
|
#include "Relation.h"
|
|
|
|
|
2015-09-15 23:48:50 -05:00
|
|
|
//still in progress
|
2015-09-15 21:13:15 -05:00
|
|
|
class DBEngine {
|
2015-09-15 21:31:19 -05:00
|
|
|
vector<Relation> tables;
|
2015-09-15 23:48:50 -05:00
|
|
|
int size;
|
2015-09-15 16:30:25 -05:00
|
|
|
|
|
|
|
public:
|
2015-09-15 21:31:19 -05:00
|
|
|
DBEngine(){
|
|
|
|
size = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void createTable(string n, vector<Attribute> a) {
|
|
|
|
Relation r(n, a);
|
|
|
|
tables.push_back(r);
|
|
|
|
}
|
2015-09-15 21:13:15 -05:00
|
|
|
|
2015-09-15 23:13:28 -05:00
|
|
|
void createTable(Relation r) { tables.push_back(r); }
|
|
|
|
vector<Relation> getRelations() { return tables; }
|
|
|
|
void showTable(Relation r) { r.display(); }
|
2015-09-15 21:13:15 -05:00
|
|
|
|
2015-09-15 21:58:44 -05:00
|
|
|
Relation getTableFromName(string n) {
|
|
|
|
//will return first occurence
|
2015-09-15 21:42:08 -05:00
|
|
|
for(int i = 0; i < tables.size(); i++) {
|
2015-09-15 21:58:44 -05:00
|
|
|
if (tables[i].getTableName() == n) {
|
|
|
|
return tables[i];
|
2015-09-15 21:42:08 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-15 23:13:28 -05:00
|
|
|
void saveToFile(vector<string> cmds) {
|
|
|
|
ofstream file;
|
2015-09-15 23:38:44 -05:00
|
|
|
file.open("savefile.db");
|
2015-09-15 23:13:28 -05:00
|
|
|
|
|
|
|
for(int i = 0; i < cmds.size(); ++i){
|
|
|
|
file << cmds[i] << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
file.close();
|
2015-09-15 21:58:44 -05:00
|
|
|
}
|
|
|
|
|
2015-09-15 23:44:58 -05:00
|
|
|
//void insertTuple(Relation r, vector<string> t) { r.addTuple(t); }
|
2015-09-15 23:38:44 -05:00
|
|
|
|
|
|
|
//need to add find by name
|
2015-09-15 23:44:58 -05:00
|
|
|
/*void deleteTuple(Relation r, int n) {
|
2015-09-15 23:38:44 -05:00
|
|
|
cout << "a";
|
2015-09-15 23:44:58 -05:00
|
|
|
r.removeTuple(n); }*/
|
2015-09-15 23:38:44 -05:00
|
|
|
|
|
|
|
void selectTuples() {
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
2015-09-15 23:13:28 -05:00
|
|
|
void project(Relation r, string n) { r.projectQuery(n); }
|
2015-09-15 23:38:44 -05:00
|
|
|
|
2015-09-15 23:48:50 -05:00
|
|
|
/*
|
|
|
|
Relation product(string p_name, Relation table_1, Relation table_2) {
|
|
|
|
|
|
|
|
vector<Attribute> all_att;
|
|
|
|
|
|
|
|
//Insert table 1 attributes
|
|
|
|
all_att.insert(all_att.begin(), (table_1.getAttributes()).begin(), (table_1.getAttributes()).end());
|
|
|
|
//Insert table 2 attributes
|
|
|
|
all_att.insert(all_att.begin(), (table_2.getAttributes()).begin(), (table_2.getAttributes()).end());
|
|
|
|
|
|
|
|
Relation temp(p_name, all_att);
|
|
|
|
|
|
|
|
vector<string> table1_stuff;
|
|
|
|
|
|
|
|
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
*/
|
2015-09-15 21:58:44 -05:00
|
|
|
|
|
|
|
bool unionComp(Relation r1, Relation r2) {
|
2015-09-15 22:36:44 -05:00
|
|
|
return ((r1.getSize() == r2.getSize()) && (r1.getDomains() == r2.getDomains()));
|
2015-09-15 21:58:44 -05:00
|
|
|
}
|
2015-09-15 16:30:25 -05:00
|
|
|
};
|