Added the save function
This commit is contained in:
parent
5cadbd35ae
commit
391cc2ab50
1 changed files with 18 additions and 29 deletions
47
DBEngine.cpp
47
DBEngine.cpp
|
@ -24,12 +24,27 @@ void DBEngine::createTable(Relation r){
|
||||||
tables.push_back(r);
|
tables.push_back(r);
|
||||||
size++;
|
size++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DBEngine::storeCommands(string s){
|
||||||
|
commands.push_back(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DBEngine::save(){
|
||||||
|
|
||||||
|
ofstream file;
|
||||||
|
file.open("savefile.txt");
|
||||||
|
|
||||||
|
for(int i = 0; i < commands.size(); ++i){
|
||||||
|
file << commands[i] << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
|
||||||
vector<Relation> DBEngine::getRelations(){
|
vector<Relation> DBEngine::getRelations(){
|
||||||
return tables;
|
return tables;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Relation& DBEngine::getTableFromName(string n){
|
Relation& DBEngine::getTableFromName(string n){
|
||||||
for(int i = 0; i < tables.size(); i++){
|
for(int i = 0; i < tables.size(); i++){
|
||||||
if (tables[i].getTableName() == n){
|
if (tables[i].getTableName() == n){
|
||||||
|
@ -38,19 +53,6 @@ Relation& DBEngine::getTableFromName(string n){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//currently writes nothing meaningful
|
|
||||||
void DBEngine::saveToFile(vector<string> cmds){
|
|
||||||
ofstream file;
|
|
||||||
file.open("savefile.db");
|
|
||||||
|
|
||||||
for(int i = 0; i < cmds.size(); ++i){
|
|
||||||
file << cmds[i] << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
file.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Relation DBEngine::selection(string attName, string s, Relation r){
|
Relation DBEngine::selection(string attName, string s, Relation r){
|
||||||
equality(attName, s, r);
|
equality(attName, s, r);
|
||||||
}
|
}
|
||||||
|
@ -78,7 +80,6 @@ Relation DBEngine::product(string new_name, Relation r1, Relation r2){
|
||||||
Relation temp(new_name);
|
Relation temp(new_name);
|
||||||
vector<Attribute> a1;
|
vector<Attribute> a1;
|
||||||
|
|
||||||
|
|
||||||
for(int i = 0; i < r1.getAttributes().size(); ++i){
|
for(int i = 0; i < r1.getAttributes().size(); ++i){
|
||||||
a1.push_back(r1.getAttributes()[i]);
|
a1.push_back(r1.getAttributes()[i]);
|
||||||
}
|
}
|
||||||
|
@ -93,20 +94,6 @@ Relation DBEngine::product(string new_name, Relation r1, Relation r2){
|
||||||
vector<string> tuple2;
|
vector<string> tuple2;
|
||||||
vector<string> result_tuple;
|
vector<string> result_tuple;
|
||||||
|
|
||||||
|
|
||||||
//Don't we need to find the bigger one to start first?
|
|
||||||
if(r1.getSize() >= r2.getSize())
|
|
||||||
{
|
|
||||||
//Combine tuples from relations into one, push back that tuple into the resultant relation via insertTuple
|
|
||||||
//Yeah have fun
|
|
||||||
}
|
|
||||||
|
|
||||||
else if(r2.getSize() > r1.getSize())
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,6 +116,8 @@ void DBEngine::rename(Relation& r, vector<string> oldnames, vector<string> newna
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*Relation DBEngine::setUnion(Relation r1, Relation r2){
|
/*Relation DBEngine::setUnion(Relation r1, Relation r2){
|
||||||
if (r1.getAttributeNames() != r2.getAttributeNames()){
|
if (r1.getAttributeNames() != r2.getAttributeNames()){
|
||||||
cout << "Failure to union: the relations are not union-compatible";
|
cout << "Failure to union: the relations are not union-compatible";
|
||||||
|
|
Reference in a new issue