diff --git a/DBEngine.cpp b/DBEngine.cpp index 9bfc700..b0eb5d2 100755 --- a/DBEngine.cpp +++ b/DBEngine.cpp @@ -52,15 +52,46 @@ void DBEngine::save(){ file.close(); } +void DBEngine::deleteRelation(string n) +{ + // to conserve memory after closing a file. + for(int i = 0; i < tables.size(); i++) + { + if (tables[i].getTableName() == n) + { + tables.erase(tables.begin() + i); + } + } +} + void DBEngine::save(string n){ ofstream file; string name = n + ".txt"; file.open(name); - for(int i = 0; i < commands.size(); ++i) + for(int i = 0; i < commands.size() - 1; ++i) { - file << commands[i] << endl; + if(commands[i].substr(0, 4) == "SAVE") + { + continue; + } + if(commands[i].substr(0, 4) == "SHOW") + { + continue; + } + if(commands[i].substr(0, 4) == "OPEN") + { + continue; + } + if(commands[i].substr(0, 5) == "CLOSE") + { + continue; + } + else + { + file << commands[i] << endl; + } } //file.close(); diff --git a/DBEngine.h b/DBEngine.h index d23dffb..de714f6 100755 --- a/DBEngine.h +++ b/DBEngine.h @@ -22,7 +22,8 @@ public: void saveToFile(vector cmds); Relation selection(string attName, string s, Relation r); Relation projection(vector input, Relation r); - Relation product(string s1, Relation r1, Relation r2); + Relation product(string s1, Relation r1, Relation r2); + void deleteRelation(string n); void save(); void save(string n); void storeCommands(string s); diff --git a/Parserv4.cpp b/Parserv4.cpp index 92dcb19..78b39a5 100644 --- a/Parserv4.cpp +++ b/Parserv4.cpp @@ -109,9 +109,11 @@ vector closeCMD(vector input, DBEngine &engine) cout<<"Syntax error!"< openCMD(vector input, DBEngine &engine) cout<<"Syntax error!"<