diff --git a/Attribute.cpp b/Attribute.cpp index 81efb67..a2ae7f6 100755 --- a/Attribute.cpp +++ b/Attribute.cpp @@ -32,7 +32,6 @@ void Attribute::addCell(string v){ } void Attribute::removeCell(int index){ - cout << values[index] << " " << index << endl; values.erase(values.begin() + index); size--; } diff --git a/DBEngine.cpp b/DBEngine.cpp index 2638942..1819cf0 100755 --- a/DBEngine.cpp +++ b/DBEngine.cpp @@ -135,11 +135,14 @@ Relation DBEngine::projection(vector input, Relation r){ vector v; string new_name = r.getTableName() + " Projection"; - for(int i = 0; i < input.size(); ++i) { - - for(int j = 0; j < r.getSize(); ++j) { + for(int i = 0; i < input.size(); ++i) + { + for(int j = 0; j < r.getSize(); ++j) + { if((r.getAttributes())[j].getName() == input[i]) + { v.push_back((r.getAttributes())[j]); + } } } @@ -221,37 +224,37 @@ Relation DBEngine::setDiff(Relation r1, Relation r2){ */ int size = 0; - cout << "test1" << endl; + //cout << "test1" << endl; for(int x = 0; x < r2.getAttributes().size(); ++x) { - cout << "test2" << endl; + //cout << "test2" << endl; for (int i = 0; i < r2.getAttributes()[x].getSize(); ++i) { - cout << "test3" << endl; + //cout << "test3" << endl; temp = r2.getTuple(i); for(int y = 0; y < new_r.getAttributes().size(); ++y) { size = new_r.getAttributes()[y].getSize(); - cout << "test4" << endl; + //cout << "test4" << endl; new_r.getAttributes()[y].getSize(); for (int j = 0; j < size; ++j) { - cout << "test5" << endl; + //cout << "test5" << endl; for(int a = 0; a < temp.size(); ++a) { - cout << "test6" << endl; + //cout << "test6" << endl; for(int b = 0; b < new_r.getTuple(j).size(); ++b) { - cout << "test7" << endl; - cout << temp[a] << " " << new_r.getTuple(j)[b] << " " << b << endl; + //cout << "test7" << endl; + //cout << temp[a] << " " << new_r.getTuple(j)[b] << " " << b << endl; if (temp[a] == new_r.getTuple(j)[b]) { new_r.removeFromTuple(b, j); - cout << "test" << endl; + //cout << "test" << endl; //duplicate = true; //break; } diff --git a/Parser.cpp b/Parser.cpp index 02d4475..75c988f 100644 --- a/Parser.cpp +++ b/Parser.cpp @@ -53,7 +53,40 @@ tuple, Relation> expression(vector input, DBEngine &engin else if(input[0] == "project") { - + input.erase(input.begin()); + if(input[0] == "(") + { + input.erase(input.begin()); + vector temp; + while(input[0] != ")") + { + temp.push_back(input[0]); + input.erase(input.begin()); + } + input.erase(input.begin()); + Relation rfinal("TEMP"); + if(engine.isRelation(input[0])) + { + rfinal = engine.projection(temp, engine.getTableFromName(input[0])); + input.erase(input.begin()); + get<0>(t) = input; + get<1>(t) = rfinal; + return t; + } + else if(input[0] == "(") + { + t = expression(input, engine); + rfinal = engine.projection(temp, get<1>(t)); + //get<0>(t) = input; + get<1>(t) = rfinal; + return t; + } + } + else + { + cout << "Projection syntax incorrect." << endl; + exit(1); + } } else if(input[0] == "rename") @@ -214,15 +247,24 @@ tuple, Relation> expression(vector input, DBEngine &engin vector showCMD(vector input, DBEngine &engine) { + /* if (input.size() > 3) { cout<<"Syntax error!"<, Relation> t = expression(input, engine); + get<1>(t).display(); + } return input; } diff --git a/Relation.cpp b/Relation.cpp index 6839ee7..b53ac36 100755 --- a/Relation.cpp +++ b/Relation.cpp @@ -139,7 +139,6 @@ void Relation::removeFromTuple(int rindex, int aindex) else { - cout << aindex << endl; att[rindex].removeCell(aindex); } } \ No newline at end of file diff --git a/test b/test index 786e618..76fc12b 100755 Binary files a/test and b/test differ