updating with NO testing

This commit is contained in:
scho4077 2015-09-29 21:34:21 -05:00
parent f3a378672d
commit 18ba9c1112

View file

@ -45,174 +45,193 @@ void displayTokenList(vector<string> input)
Relation condition(vector<string> input, Relation &r)
{
Relation rfinal = r;
Attribute a1 = r.getAttributeByName(input[0]);
input.erase(input.begin());
string op = input[0];
input.erase(input.begin());
Attribute a2;
string c;
//cout << input[0] << endl;
if(input[0].at(0) == '\"')
{
c = input[0].substr(1, input[0].find_last_of("\"") - 1);
//cout << c << endl;
}
if(r.isAttribute(input[0]))
{
a2 = r.getAttributeByName(input[0]);
input.erase(input.begin());
for(int i = 0; i < r.getAttributes().size(); ++i)
{
if(r.getAttributes()[i].getName() == a1.getName())
{
/*
for(int j = 0; j < r.getAttributeByName(a1.getName()).getValues().size; ++j)
{
if(r.getAttributeByName(a1.getName()).getValues()[j] == )
{
rfinal.insertTuple(r.getTuple(j));
}
}*/
if(op == "==")
{
for(int x = 0; x < r.getAttributeByName(a1.getName()).getSize(); ++x)
{
if(r.getAttributeByName(a1.getName()).getValues()[x] != r.getAttributeByName(a2.getName()).getValues()[x])
{
rfinal.removeTuple(x);
//rfinal.insertAttributes(a);
}
}
}
else if(op == "!=")
{
for(int x = 0; x < r.getAttributeByName(a1.getName()).getSize(); ++x)
{
if(r.getAttributeByName(a1.getName()).getValues()[x] == r.getAttributeByName(a2.getName()).getValues()[x])
{
rfinal.removeTuple(x);
//rfinal.insertAttributes(a);
}
}
}
else if(op == ">=")
{
if(r.getAttributeByName(a1.getName()).getType() == "INTEGER" && r.getAttributeByName(a2.getName()).getType() == "INTEGER")
{
for(int x = 0; x < r.getAttributeByName(a1.getName()).getSize(); ++x)
{
if(stoi(r.getAttributeByName(a1.getName()).getValues()[x]) < stoi(r.getAttributeByName(a2.getName()).getValues()[x]))
{
rfinal.removeTuple(x);
//rfinal.insertAttributes(a);
}
}
}
else
{
cout << "Attribute type is not an INTEGER." << endl;
exit(1);
}
}
else if(op == "<=")
{
if(r.getAttributeByName(a1.getName()).getType() == "INTEGER" && r.getAttributeByName(a2.getName()).getType() == "INTEGER")
{
for(int x = 0; x < r.getAttributeByName(a1.getName()).getSize(); ++x)
{
if(stoi(r.getAttributeByName(a1.getName()).getValues()[x]) > stoi(r.getAttributeByName(a2.getName()).getValues()[x]))
{
rfinal.removeTuple(x);
//rfinal.insertAttributes(a);
}
}
}
else
{
cout << "Attribute type is not an INTEGER." << endl;
exit(1);
}
}
else if(op == ">")
{
if(r.getAttributeByName(a1.getName()).getType() == "INTEGER" && r.getAttributeByName(a2.getName()).getType() == "INTEGER")
{
for(int x = 0; x < r.getAttributeByName(a1.getName()).getSize(); ++x)
{
if(stoi(r.getAttributeByName(a1.getName()).getValues()[x]) <= stoi(r.getAttributeByName(a2.getName()).getValues()[x]))
{
rfinal.removeTuple(x);
//rfinal.insertAttributes(a);
}
}
}
else
{
cout << "Attribute type is not an INTEGER." << endl;
exit(1);
}
}
else if(op == "<")
{
if(r.getAttributeByName(a1.getName()).getType() == "INTEGER" && r.getAttributeByName(a2.getName()).getType() == "INTEGER")
{
for(int x = 0; x < r.getAttributeByName(a1.getName()).getSize(); ++x)
{
if(stoi(r.getAttributeByName(a1.getName()).getValues()[x]) >= stoi(r.getAttributeByName(a2.getName()).getValues()[x]))
{
rfinal.removeTuple(x);
//rfinal.insertAttributes(a);
}
}
}
else
{
cout << "Attribute type is not an INTEGER." << endl;
exit(1);
}
}
}
//UNTESTED
//testing to see if there is an && or || present
if (input.size() > 3) {
//test print
for (int i = 0; i < input.size(); ++i)
cout << "input[i]: " << input[i] << "\n";
//this is probably wrong, added a cout for testing
string bin_op = input[3];
cout << "bin_op, should be && or ||: " << bin_op << "\n";
//making each half a new vector, probably a better way to do this
vector<string> firsthalf;
vector<string> secondhalf;
//again, all untested. it's weird to not test this stuff
for (int i = 0; i < input.size(); ++i){
if (i < 3)
firsthalf.push_back(input[i]);
else
secondhalf.push_back(input[i]);
}
//calling condition again with each half
Relation r1 = condition(firsthalf, rfinal);
Relation r2 = condition(secondhalf, rfinal);
//NO IDEA IF THIS ACTUALLY WORKS
//HOORAY
//HOW THE FUCK DO PEOPLE CODE LIKE THIS
if (bin_op == "&&"){
//with engine as the DBEngine object that maybe exists
return engine.crossProduct(r1, r2);
}
else if (bin_op == "||"){
//with engine as the DBEngine object that maybe exists
return engine.setUnion(r1, r2);
}
else {
cout << "Something strange happened. bin_op: " << bin_op << "\n";
cout << "Returning the initial relation.";
return rfinal;
}
}
else
{
else {
Attribute a1 = r.getAttributeByName(input[0]);
input.erase(input.begin());
if(op == "==")
string op = input[0];
input.erase(input.begin());
Attribute a2;
string c;
//cout << input[0] << endl;
if(input[0].at(0) == '\"')
{
c = input[0].substr(1, input[0].find_last_of("\"") - 1);
//cout << c << endl;
}
if(r.isAttribute(input[0]))
{
a2 = r.getAttributeByName(input[0]);
input.erase(input.begin());
for(int i = 0; i < r.getAttributes().size(); ++i)
{
if(r.getAttributes()[i].getName() == a1.getName())
{
for(int j = 0; j < r.getAttributeByName(a1.getName()).getValues().size(); ++j)
/*
for(int j = 0; j < r.getAttributeByName(a1.getName()).getValues().size; ++j)
{
if(r.getAttributeByName(a1.getName()).getValues()[j] != c)
if(r.getAttributeByName(a1.getName()).getValues()[j] == )
{
rfinal.removeTuple(j);
rfinal.insertTuple(r.getTuple(j));
}
}*/
if(op == "==")
{
for(int x = 0; x < r.getAttributeByName(a1.getName()).getSize(); ++x)
{
if(r.getAttributeByName(a1.getName()).getValues()[x] != r.getAttributeByName(a2.getName()).getValues()[x])
{
rfinal.removeTuple(x);
//rfinal.insertAttributes(a);
}
}
}
else if(op == "!=")
{
for(int x = 0; x < r.getAttributeByName(a1.getName()).getSize(); ++x)
{
if(r.getAttributeByName(a1.getName()).getValues()[x] == r.getAttributeByName(a2.getName()).getValues()[x])
{
rfinal.removeTuple(x);
//rfinal.insertAttributes(a);
}
}
}
else if(op == ">=")
{
if(r.getAttributeByName(a1.getName()).getType() == "INTEGER" && r.getAttributeByName(a2.getName()).getType() == "INTEGER")
{
for(int x = 0; x < r.getAttributeByName(a1.getName()).getSize(); ++x)
{
if(stoi(r.getAttributeByName(a1.getName()).getValues()[x]) < stoi(r.getAttributeByName(a2.getName()).getValues()[x]))
{
rfinal.removeTuple(x);
//rfinal.insertAttributes(a);
}
}
}
else
{
cout << "Attribute type is not an INTEGER." << endl;
exit(1);
}
}
else if(op == "<=")
{
if(r.getAttributeByName(a1.getName()).getType() == "INTEGER" && r.getAttributeByName(a2.getName()).getType() == "INTEGER")
{
for(int x = 0; x < r.getAttributeByName(a1.getName()).getSize(); ++x)
{
if(stoi(r.getAttributeByName(a1.getName()).getValues()[x]) > stoi(r.getAttributeByName(a2.getName()).getValues()[x]))
{
rfinal.removeTuple(x);
//rfinal.insertAttributes(a);
}
}
}
else
{
cout << "Attribute type is not an INTEGER." << endl;
exit(1);
}
}
else if(op == ">")
{
if(r.getAttributeByName(a1.getName()).getType() == "INTEGER" && r.getAttributeByName(a2.getName()).getType() == "INTEGER")
{
for(int x = 0; x < r.getAttributeByName(a1.getName()).getSize(); ++x)
{
if(stoi(r.getAttributeByName(a1.getName()).getValues()[x]) <= stoi(r.getAttributeByName(a2.getName()).getValues()[x]))
{
rfinal.removeTuple(x);
//rfinal.insertAttributes(a);
}
}
}
else
{
cout << "Attribute type is not an INTEGER." << endl;
exit(1);
}
}
else if(op == "<")
{
if(r.getAttributeByName(a1.getName()).getType() == "INTEGER" && r.getAttributeByName(a2.getName()).getType() == "INTEGER")
{
for(int x = 0; x < r.getAttributeByName(a1.getName()).getSize(); ++x)
{
if(stoi(r.getAttributeByName(a1.getName()).getValues()[x]) >= stoi(r.getAttributeByName(a2.getName()).getValues()[x]))
{
rfinal.removeTuple(x);
//rfinal.insertAttributes(a);
}
}
}
else
{
cout << "Attribute type is not an INTEGER." << endl;
exit(1);
}
}
}
}
}
else if(op == "!=")
else
{
for(int i = 0; i < r.getAttributes().size(); ++i)
{
if(r.getAttributes()[i].getName() == a1.getName())
{
for(int j = 0; j < r.getAttributeByName(a1.getName()).getValues().size(); ++j)
{
if(r.getAttributeByName(a1.getName()).getValues()[j] == c)
{
rfinal.removeTuple(j);
}
}
}
}
}
else if(op == ">=")
{
if(r.getAttributeByName(a1.getName()).getType() == "INTEGER")
input.erase(input.begin());
if(op == "==")
{
for(int i = 0; i < r.getAttributes().size(); ++i)
{
@ -220,7 +239,7 @@ Relation condition(vector<string> input, Relation &r)
{
for(int j = 0; j < r.getAttributeByName(a1.getName()).getValues().size(); ++j)
{
if(stoi(r.getAttributeByName(a1.getName()).getValues()[j]) < stoi(c))
if(r.getAttributeByName(a1.getName()).getValues()[j] != c)
{
rfinal.removeTuple(j);
}
@ -228,15 +247,7 @@ Relation condition(vector<string> input, Relation &r)
}
}
}
else
{
cout << "Attribute type is not an INTEGER." << endl;
exit(1);
}
}
else if(op == "<=")
{
if(r.getAttributeByName(a1.getName()).getType() == "INTEGER")
else if(op == "!=")
{
for(int i = 0; i < r.getAttributes().size(); ++i)
{
@ -244,7 +255,7 @@ Relation condition(vector<string> input, Relation &r)
{
for(int j = 0; j < r.getAttributeByName(a1.getName()).getValues().size(); ++j)
{
if(stoi(r.getAttributeByName(a1.getName()).getValues()[j]) > stoi(c))
if(r.getAttributeByName(a1.getName()).getValues()[j] == c)
{
rfinal.removeTuple(j);
}
@ -252,64 +263,107 @@ Relation condition(vector<string> input, Relation &r)
}
}
}
else
else if(op == ">=")
{
cout << "Attribute type is not an INTEGER." << endl;
exit(1);
}
}
else if(op == ">")
{
if(r.getAttributeByName(a1.getName()).getType() == "INTEGER")
{
for(int i = 0; i < r.getAttributes().size(); ++i)
if(r.getAttributeByName(a1.getName()).getType() == "INTEGER")
{
if(r.getAttributes()[i].getName() == a1.getName())
for(int i = 0; i < r.getAttributes().size(); ++i)
{
for(int j = 0; j < r.getAttributeByName(a1.getName()).getValues().size(); ++j)
if(r.getAttributes()[i].getName() == a1.getName())
{
if(stoi(r.getAttributeByName(a1.getName()).getValues()[j]) <= stoi(c))
for(int j = 0; j < r.getAttributeByName(a1.getName()).getValues().size(); ++j)
{
rfinal.removeTuple(j);
if(stoi(r.getAttributeByName(a1.getName()).getValues()[j]) < stoi(c))
{
rfinal.removeTuple(j);
}
}
}
}
}
}
else
{
cout << "Attribute type is not an INTEGER." << endl;
exit(1);
}
}
else if(op == "<")
{
if(r.getAttributeByName(a1.getName()).getType() == "INTEGER")
{
for(int i = 0; i < r.getAttributes().size(); ++i)
else
{
if(r.getAttributes()[i].getName() == a1.getName())
cout << "Attribute type is not an INTEGER." << endl;
exit(1);
}
}
else if(op == "<=")
{
if(r.getAttributeByName(a1.getName()).getType() == "INTEGER")
{
for(int i = 0; i < r.getAttributes().size(); ++i)
{
for(int j = 0; j < r.getAttributeByName(a1.getName()).getValues().size(); ++j)
if(r.getAttributes()[i].getName() == a1.getName())
{
if(stoi(r.getAttributeByName(a1.getName()).getValues()[j]) >= stoi(c))
for(int j = 0; j < r.getAttributeByName(a1.getName()).getValues().size(); ++j)
{
rfinal.removeTuple(j);
if(stoi(r.getAttributeByName(a1.getName()).getValues()[j]) > stoi(c))
{
rfinal.removeTuple(j);
}
}
}
}
}
else
{
cout << "Attribute type is not an INTEGER." << endl;
exit(1);
}
}
else
else if(op == ">")
{
cout << "Attribute type is not an INTEGER." << endl;
exit(1);
if(r.getAttributeByName(a1.getName()).getType() == "INTEGER")
{
for(int i = 0; i < r.getAttributes().size(); ++i)
{
if(r.getAttributes()[i].getName() == a1.getName())
{
for(int j = 0; j < r.getAttributeByName(a1.getName()).getValues().size(); ++j)
{
if(stoi(r.getAttributeByName(a1.getName()).getValues()[j]) <= stoi(c))
{
rfinal.removeTuple(j);
}
}
}
}
}
else
{
cout << "Attribute type is not an INTEGER." << endl;
exit(1);
}
}
else if(op == "<")
{
if(r.getAttributeByName(a1.getName()).getType() == "INTEGER")
{
for(int i = 0; i < r.getAttributes().size(); ++i)
{
if(r.getAttributes()[i].getName() == a1.getName())
{
for(int j = 0; j < r.getAttributeByName(a1.getName()).getValues().size(); ++j)
{
if(stoi(r.getAttributeByName(a1.getName()).getValues()[j]) >= stoi(c))
{
rfinal.removeTuple(j);
}
}
}
}
}
else
{
cout << "Attribute type is not an INTEGER." << endl;
exit(1);
}
}
}
return rfinal;
}
return rfinal;
}
tuple<vector<string>, Relation> expression(vector<string> input, DBEngine &engine)
@ -1214,4 +1268,4 @@ int main () {
}
*/
*/