Projection linked.
This commit is contained in:
parent
1f6fa55754
commit
fa50473ad4
5 changed files with 61 additions and 18 deletions
|
@ -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--;
|
||||
}
|
||||
|
|
27
DBEngine.cpp
27
DBEngine.cpp
|
@ -135,11 +135,14 @@ Relation DBEngine::projection(vector<string> input, Relation r){
|
|||
vector<Attribute> 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;
|
||||
}
|
||||
|
|
50
Parser.cpp
50
Parser.cpp
|
@ -53,7 +53,40 @@ tuple<vector<string>, Relation> expression(vector<string> input, DBEngine &engin
|
|||
|
||||
else if(input[0] == "project")
|
||||
{
|
||||
|
||||
input.erase(input.begin());
|
||||
if(input[0] == "(")
|
||||
{
|
||||
input.erase(input.begin());
|
||||
vector<string> 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<vector<string>, Relation> expression(vector<string> input, DBEngine &engin
|
|||
|
||||
vector<string> showCMD(vector<string> input, DBEngine &engine)
|
||||
{
|
||||
/*
|
||||
if (input.size() > 3)
|
||||
{
|
||||
cout<<"Syntax error!"<<endl;
|
||||
}
|
||||
*/
|
||||
|
||||
PRelation r(input[0]);
|
||||
if(engine.isRelation(input[0]))
|
||||
{
|
||||
engine.getTableFromName(input[0]).display();
|
||||
input.erase(input.begin());
|
||||
}
|
||||
|
||||
// send show command to DBEngine
|
||||
engine.getTableFromName(r.getName()).display();
|
||||
else
|
||||
{
|
||||
tuple<vector<string>, Relation> t = expression(input, engine);
|
||||
get<1>(t).display();
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
|
|
|
@ -139,7 +139,6 @@ void Relation::removeFromTuple(int rindex, int aindex)
|
|||
|
||||
else
|
||||
{
|
||||
cout << aindex << endl;
|
||||
att[rindex].removeCell(aindex);
|
||||
}
|
||||
}
|
BIN
test
BIN
test
Binary file not shown.
Reference in a new issue