OPEN and CLOSE commands work properly, filtered SAVE command.

This commit is contained in:
Alexander Huddleston 2015-09-28 18:47:43 -05:00
parent 7c8eb084d9
commit abd415cb9b
4 changed files with 48 additions and 5 deletions

View file

@ -52,15 +52,46 @@ void DBEngine::save(){
file.close(); 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){ void DBEngine::save(string n){
ofstream file; ofstream file;
string name = n + ".txt"; string name = n + ".txt";
file.open(name); 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(); //file.close();

View file

@ -22,7 +22,8 @@ public:
void saveToFile(vector<string> cmds); void saveToFile(vector<string> cmds);
Relation selection(string attName, string s, Relation r); Relation selection(string attName, string s, Relation r);
Relation projection(vector<string> input, Relation r); Relation projection(vector<string> 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();
void save(string n); void save(string n);
void storeCommands(string s); void storeCommands(string s);

View file

@ -109,9 +109,11 @@ vector<string> closeCMD(vector<string> input, DBEngine &engine)
cout<<"Syntax error!"<<endl; cout<<"Syntax error!"<<endl;
} }
PRelation r(input[0]); //PRelation r(input[0]);
// send close command to DBEngine // send close command to DBEngine
engine.deleteRelation(input[0]);
input.erase(input.begin());
return input; return input;
} }
@ -123,9 +125,18 @@ vector<string> openCMD(vector<string> input, DBEngine &engine)
cout<<"Syntax error!"<<endl; cout<<"Syntax error!"<<endl;
} }
PRelation r(input[0]); //PRelation r(input[0]);
// send open command to DBEngine // send open command to DBEngine
string name = input[0] + ".txt";
ifstream file;
file.open(name);
string line;
while(getline(file, line))
{
parse(line, engine);
}
file.close();
return input; return input;
} }

BIN
test

Binary file not shown.