commit
32fbf439f8
3 changed files with 265 additions and 3 deletions
|
@ -77,4 +77,3 @@ void DBEngine::rename(Relation& r, vector<string> oldnames, vector<string> newna
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
248
Parserv3.h
Normal file
248
Parserv3.h
Normal file
|
@ -0,0 +1,248 @@
|
|||
#include <string> // std::string
|
||||
#include <iostream> // std::cout
|
||||
#include <sstream> // std::stringstream
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
class Relation
|
||||
{
|
||||
string name;
|
||||
|
||||
Relation(string str)
|
||||
{
|
||||
name = str;
|
||||
}
|
||||
|
||||
void setRelation(string str)
|
||||
{
|
||||
name = str;
|
||||
}
|
||||
string getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
class Union
|
||||
{
|
||||
string Un1;
|
||||
string Un2;
|
||||
|
||||
Union (string s1, string s2)
|
||||
{
|
||||
Un1 = s1;
|
||||
Un2 = s2;
|
||||
}
|
||||
|
||||
string getUnion()
|
||||
{
|
||||
return "Union of " + Un1 + " and " + Un2;
|
||||
}
|
||||
};
|
||||
|
||||
class Product
|
||||
{
|
||||
string Pr1;
|
||||
string Pr2;
|
||||
|
||||
Product(string s1, string s2)
|
||||
{
|
||||
Pr1 = s1;
|
||||
Pr2 = s2;
|
||||
}
|
||||
|
||||
string getProduct()
|
||||
{
|
||||
return "Product of " + Pr1 + " and " + Pr2;
|
||||
}
|
||||
};
|
||||
|
||||
class Difference
|
||||
{
|
||||
string D1;
|
||||
string D2;
|
||||
|
||||
Difference(string s1, string s2)
|
||||
{
|
||||
D1 = s1;
|
||||
D2 = s2;
|
||||
}
|
||||
|
||||
string getDifference()
|
||||
{
|
||||
return "Difference of " + D1 + " and " + D2;
|
||||
}
|
||||
};
|
||||
|
||||
class Renaming
|
||||
{
|
||||
string newName;
|
||||
string oldName;
|
||||
|
||||
Renaming(string s1, string s2)
|
||||
{
|
||||
newName = s1;
|
||||
oldName = s2;
|
||||
}
|
||||
|
||||
string doRename()
|
||||
{
|
||||
return "Renaming " + oldName + " to " + newName;
|
||||
}
|
||||
};
|
||||
|
||||
class Projection
|
||||
{
|
||||
string newName;
|
||||
string oldName;
|
||||
|
||||
Projection(string s1, string s2)
|
||||
{
|
||||
newName = s1;
|
||||
oldName = s2;
|
||||
}
|
||||
|
||||
string doProjection()
|
||||
{
|
||||
return "Projecting " + oldName + " onto " + newName;
|
||||
}
|
||||
};
|
||||
|
||||
class Operand
|
||||
{
|
||||
string op;
|
||||
|
||||
public:
|
||||
|
||||
Operand()
|
||||
{
|
||||
}
|
||||
|
||||
Operand(string str)
|
||||
{
|
||||
op = str;
|
||||
}
|
||||
|
||||
void setOperand(string str)
|
||||
{
|
||||
op = str;
|
||||
}
|
||||
|
||||
string getOperand()
|
||||
{
|
||||
return op;
|
||||
}
|
||||
};
|
||||
|
||||
class Op
|
||||
{
|
||||
string op;
|
||||
|
||||
public:
|
||||
Op()
|
||||
{
|
||||
}
|
||||
|
||||
Op(string str)
|
||||
{
|
||||
op = str;
|
||||
}
|
||||
|
||||
void setOp(string str)
|
||||
{
|
||||
op = str;
|
||||
}
|
||||
|
||||
string getOp()
|
||||
{
|
||||
return op;
|
||||
}
|
||||
};
|
||||
|
||||
class Comparison
|
||||
{
|
||||
Op op;
|
||||
Operand operand1;
|
||||
Operand operand2;
|
||||
|
||||
public:
|
||||
|
||||
Comparison(string str1, string str2, string str3)
|
||||
{
|
||||
operand1.setOperand(str1);
|
||||
op.setOp(str2);
|
||||
operand2.setOperand(str3);
|
||||
}
|
||||
|
||||
void setComparison(string str1, string str2, string str3)
|
||||
{
|
||||
operand1.setOperand(str1);
|
||||
op.setOp(str2);
|
||||
operand2.setOperand(str3);
|
||||
}
|
||||
|
||||
string getComparison()
|
||||
{
|
||||
return operand1.getOperand() + " " + op.getOp() + " " + operand2.getOperand();
|
||||
}
|
||||
};
|
||||
|
||||
class Conjunction
|
||||
{
|
||||
string conj;
|
||||
public:
|
||||
Conjunction(string str)
|
||||
{
|
||||
conj = str;
|
||||
}
|
||||
|
||||
void setConjunction(string str)
|
||||
{
|
||||
conj = str;
|
||||
}
|
||||
|
||||
string getConjunction()
|
||||
{
|
||||
return conj;
|
||||
}
|
||||
};
|
||||
|
||||
class Condition
|
||||
{
|
||||
string cond;
|
||||
public:
|
||||
Condition(string str)
|
||||
{
|
||||
cond = str;
|
||||
}
|
||||
|
||||
void setCondition(string str)
|
||||
{
|
||||
cond = str;
|
||||
}
|
||||
|
||||
string getCondition()
|
||||
{
|
||||
return cond;
|
||||
}
|
||||
};
|
||||
|
||||
class Selection
|
||||
{
|
||||
string select;
|
||||
public:
|
||||
Selection(string str)
|
||||
{
|
||||
select = str;
|
||||
}
|
||||
|
||||
string getSelection()
|
||||
{
|
||||
return select;
|
||||
}
|
||||
};
|
15
test.cpp
15
test.cpp
|
@ -50,7 +50,22 @@ int main() {
|
|||
newa.push_back("Hcnul");
|
||||
newa.push_back("Rennid");
|
||||
|
||||
<<<<<<< HEAD
|
||||
//Projection test
|
||||
vector<string> projectTest;
|
||||
projectTest.push_back("Breakfast");
|
||||
projectTest.push_back("Dinner");
|
||||
|
||||
cout << "\n***Initiated Projection***\n" << endl;
|
||||
|
||||
Relation sub_r = engine.projection(projectTest, r);
|
||||
sub_r.display();
|
||||
|
||||
//engine.rename(r, o, n);
|
||||
}
|
||||
=======
|
||||
engine.rename(engine.getTableFromName("Food"), old, newa);
|
||||
engine.getTableFromName("Food").display();
|
||||
cout << "finished";
|
||||
}
|
||||
>>>>>>> master
|
||||
|
|
Reference in a new issue