delete and update work
This commit is contained in:
parent
20fec486b6
commit
4515a7073b
4 changed files with 17 additions and 6 deletions
19
DBEngine.cpp
19
DBEngine.cpp
|
@ -286,10 +286,6 @@ Relation DBEngine::crossProduct(Relation r1, Relation r2){
|
||||||
return new_r;
|
return new_r;
|
||||||
}
|
}
|
||||||
|
|
||||||
//UPDATE Senator
|
|
||||||
//SET Party = ‘Independent’
|
|
||||||
//WHERE Name = ‘Joseph Lieberman’
|
|
||||||
|
|
||||||
Relation DBEngine::updateCmd(Relation r, string attNameSet, string attSet, string attNameWhere, string attWhere){
|
Relation DBEngine::updateCmd(Relation r, string attNameSet, string attSet, string attNameWhere, string attWhere){
|
||||||
//brute forcing this, sorry universe
|
//brute forcing this, sorry universe
|
||||||
//add error matching!!
|
//add error matching!!
|
||||||
|
@ -318,3 +314,18 @@ Relation DBEngine::updateCmd(Relation r, string attNameSet, string attSet, strin
|
||||||
r.setAttributes(atts);
|
r.setAttributes(atts);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Relation DBEngine::deleteCmd(Relation r, string attName, string att){
|
||||||
|
for (int i = 0; i < r.getSize(); ++i){
|
||||||
|
if (r[i].getName() == attName){
|
||||||
|
for (int j = 0; j < r[i].getSize(); ++j){
|
||||||
|
if (r[i][j] == att){
|
||||||
|
r.removeTuple(j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//r.setAttributes(atts);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
|
@ -32,5 +32,5 @@ public:
|
||||||
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 updateCmd(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(Relation r, string attName, string att);
|
||||||
};
|
};
|
||||||
|
|
BIN
a.out
BIN
a.out
Binary file not shown.
2
test.cpp
2
test.cpp
|
@ -33,6 +33,6 @@ int main () {
|
||||||
v.push_back(att3);
|
v.push_back(att3);
|
||||||
|
|
||||||
engine.createTable("Food", v);
|
engine.createTable("Food", v);
|
||||||
Relation temp = engine.updateCmd(engine.getTableFromName("Food"), "Dinner", "SUCCESS", "Breakfast", "Pancakes");
|
Relation temp = engine.deleteCmd(engine.getTableFromName("Food"), "Breakfast", "Pancakes");
|
||||||
temp.display();
|
temp.display();
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue