From 391cc2ab50948a30394f97dc2dc7b6110a992b50 Mon Sep 17 00:00:00 2001 From: Brandon Jackson <1drummer@att.net> Date: Fri, 25 Sep 2015 00:31:23 -0500 Subject: [PATCH] Added the save function --- DBEngine.cpp | 47 ++++++++++++++++++----------------------------- 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/DBEngine.cpp b/DBEngine.cpp index 5c3e864..26e15f2 100755 --- a/DBEngine.cpp +++ b/DBEngine.cpp @@ -24,12 +24,27 @@ void DBEngine::createTable(Relation r){ tables.push_back(r); 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 DBEngine::getRelations(){ return tables; } - Relation& DBEngine::getTableFromName(string n){ for(int i = 0; i < tables.size(); i++){ if (tables[i].getTableName() == n){ @@ -38,19 +53,6 @@ Relation& DBEngine::getTableFromName(string n){ } } -//currently writes nothing meaningful -void DBEngine::saveToFile(vector 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){ equality(attName, s, r); } @@ -78,7 +80,6 @@ Relation DBEngine::product(string new_name, Relation r1, Relation r2){ Relation temp(new_name); vector a1; - for(int i = 0; i < r1.getAttributes().size(); ++i){ a1.push_back(r1.getAttributes()[i]); } @@ -93,20 +94,6 @@ Relation DBEngine::product(string new_name, Relation r1, Relation r2){ vector tuple2; vector 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; } @@ -129,6 +116,8 @@ void DBEngine::rename(Relation& r, vector oldnames, vector newna } } + + /*Relation DBEngine::setUnion(Relation r1, Relation r2){ if (r1.getAttributeNames() != r2.getAttributeNames()){ cout << "Failure to union: the relations are not union-compatible";