OPEN and CLOSE commands work properly, filtered SAVE command.
This commit is contained in:
parent
7c8eb084d9
commit
abd415cb9b
4 changed files with 48 additions and 5 deletions
35
DBEngine.cpp
35
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();
|
||||
|
|
|
@ -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);
|
||||
|
|
15
Parserv4.cpp
15
Parserv4.cpp
|
@ -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
BIN
test
Binary file not shown.
Reference in a new issue