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,16 +52,47 @@ 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)
{
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();
}

View file

@ -23,6 +23,7 @@ public:
Relation selection(string attName, string s, Relation r);
Relation projection(vector<string> input, Relation r);
Relation product(string s1, Relation r1, Relation r2);
void deleteRelation(string n);
void save();
void save(string n);
void storeCommands(string s);

View file

@ -109,9 +109,11 @@ vector<string> closeCMD(vector<string> input, DBEngine &engine)
cout<<"Syntax error!"<<endl;
}
PRelation r(input[0]);
//PRelation r(input[0]);
// send close command to DBEngine
engine.deleteRelation(input[0]);
input.erase(input.begin());
return input;
}
@ -123,9 +125,18 @@ vector<string> openCMD(vector<string> input, DBEngine &engine)
cout<<"Syntax error!"<<endl;
}
PRelation r(input[0]);
//PRelation r(input[0]);
// 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;
}

BIN
test

Binary file not shown.