working on update & delete
This commit is contained in:
parent
c7c701a169
commit
909df70f2d
2 changed files with 29 additions and 18 deletions
37
DBEngine.cpp
37
DBEngine.cpp
|
@ -214,15 +214,15 @@ Relation DBEngine::setDiff(Relation r1, Relation r2){
|
||||||
//currently all returned relations are called TEMP
|
//currently all returned relations are called TEMP
|
||||||
Relation new_r = r1;
|
Relation new_r = r1;
|
||||||
new_r.setTableName("TEMP");
|
new_r.setTableName("TEMP");
|
||||||
vector<string> temp;
|
vector<string> temp;
|
||||||
//bool duplicate = false;
|
//bool duplicate = false;
|
||||||
|
|
||||||
int size = 0;
|
int size = 0;
|
||||||
|
|
||||||
for(int x = 0; x < r2.getAttributes().size(); ++x)
|
for(int x = 0; x < r2.getAttributes().size(); ++x)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < r2.getAttributes()[x].getSize(); ++i)
|
for (int i = 0; i < r2.getAttributes()[x].getSize(); ++i)
|
||||||
{
|
{
|
||||||
temp = r2.getTuple(i);
|
temp = r2.getTuple(i);
|
||||||
|
|
||||||
for(int y = 0; y < new_r.getAttributes().size(); ++y)
|
for(int y = 0; y < new_r.getAttributes().size(); ++y)
|
||||||
|
@ -244,8 +244,8 @@ Relation DBEngine::setDiff(Relation r1, Relation r2){
|
||||||
size = new_r.getAttributes()[y].getSize();
|
size = new_r.getAttributes()[y].getSize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new_r;
|
return new_r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -283,17 +283,28 @@ Relation DBEngine::crossProduct(Relation r1, Relation r2){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return new_r;
|
return new_r;
|
||||||
}
|
}
|
||||||
|
|
||||||
//UPDATE Senator
|
//UPDATE Senator
|
||||||
//SET Party = ‘Independent’
|
//SET Party = ‘Independent’
|
||||||
//WHERE Name = ‘Joseph Lieberman’
|
//WHERE Name = ‘Joseph Lieberman’
|
||||||
|
|
||||||
Relation DBEngine::update(Relation r, string attNameSet, string attSet, string attNameWhere, string attWhere){
|
Relation DBEngine::updateCmd(Relation r, string attNameSet, string attSet, string attNameWhere, string attWhere){
|
||||||
Relation temp = equality(attNameWhere, attWhere, r);
|
Relation temp = selection(attNameWhere, attWhere, r);
|
||||||
|
vector<Attribute> atts = temp.getAttributes();
|
||||||
|
|
||||||
|
for (int i = 0; i < atts.size(); ++i){
|
||||||
|
if (atts[i].getName() == attNameSet) {
|
||||||
|
for (int j = 0; j < atts[i].getSize(); ++j){
|
||||||
|
atts[i]setValue(attSet, j);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//currently returns a relation with just the changed values, need to look at proper join
|
||||||
|
//if proper join does not work, plan B is brute force
|
||||||
return r;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
10
DBEngine.h
10
DBEngine.h
|
@ -21,16 +21,16 @@ public:
|
||||||
Relation& getTableFromName(string n);
|
Relation& getTableFromName(string n);
|
||||||
void saveToFile(vector<string> cmds);
|
void saveToFile(vector<string> cmds);
|
||||||
Relation selection(string attName, string s, Relation r);
|
Relation selection(string attName, string s, Relation r);
|
||||||
Relation projection(vector<string> input, Relation r);
|
Relation projection(vector<string> input, Relation r);
|
||||||
Relation product(string s1, Relation r1, Relation r2);
|
Relation product(string s1, Relation r1, Relation r2);
|
||||||
void deleteRelation(string n);
|
void deleteRelation(string n);
|
||||||
void save();
|
void save();
|
||||||
void save(string n);
|
void save(string n);
|
||||||
void storeCommands(string s);
|
void storeCommands(string s);
|
||||||
Relation rename(vector<string> newnames, Relation &r);
|
Relation rename(vector<string> newnames, Relation &r);
|
||||||
Relation setUnion(Relation r1, Relation r2);
|
Relation setUnion(Relation r1, Relation r2);
|
||||||
Relation setDiff(Relation r1, Relation r2);
|
Relation setDiff(Relation r1, Relation r2);
|
||||||
Relation crossProduct(Relation r1, Relation r2);
|
Relation crossProduct(Relation r1, Relation r2);
|
||||||
Relation update(Relation r, string attNameSet, string attSet, string attNameWhere, string attWhere);
|
Relation updateCmd(Relation r, string attNameSet, string attSet, string attNameWhere, string attWhere);
|
||||||
//Relation deleteCmd();
|
//Relation deleteCmd();
|
||||||
};
|
};
|
||||||
|
|
Reference in a new issue