update being weird
This commit is contained in:
parent
25ce3c7248
commit
15185bcb8d
4 changed files with 35 additions and 5 deletions
11
DBEngine.cpp
11
DBEngine.cpp
|
@ -286,7 +286,7 @@ Relation DBEngine::crossProduct(Relation r1, Relation r2){
|
||||||
return new_r;
|
return new_r;
|
||||||
}
|
}
|
||||||
|
|
||||||
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!!
|
||||||
vector<int> inds;
|
vector<int> inds;
|
||||||
|
@ -313,6 +313,15 @@ Relation DBEngine::updateCmd(Relation r, string attNameSet, string attSet, strin
|
||||||
|
|
||||||
r.setAttributes(atts);
|
r.setAttributes(atts);
|
||||||
return r;
|
return r;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
void DBEngine::updateCmd(string relationName, string attNameSet, string attSet, string attNameWhere, string attWhere){
|
||||||
|
for(int i = 0; i < tables.size(); i++){
|
||||||
|
if (tables[i].getTableName() == relationName){
|
||||||
|
tables[i].updateCmd(attNameSet, attSet, attNameWhere, attWhere);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*Relation DBEngine::deleteCmd(Relation r, string attName, string att){
|
/*Relation DBEngine::deleteCmd(Relation r, string attName, string att){
|
||||||
|
|
|
@ -31,7 +31,8 @@ public:
|
||||||
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 updateCmd(Relation r, string attNameSet, string attSet, string attNameWhere, string attWhere);
|
//Relation updateCmd(Relation r, string attNameSet, string attSet, string attNameWhere, string attWhere);
|
||||||
|
void updateCmd(string relationName, string attNameSet, string attSet, string attNameWhere, string attWhere);
|
||||||
//Relation deleteCmd(Relation r, string attName, string att);
|
//Relation deleteCmd(Relation r, string attName, string att);
|
||||||
void deleteCmd(string relationName, string attName, string att);
|
void deleteCmd(string relationName, string attName, string att);
|
||||||
};
|
};
|
||||||
|
|
24
Relation.cpp
24
Relation.cpp
|
@ -158,8 +158,28 @@ void Relation::removeFromTuple(int rindex, int aindex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Relation::updateCmd(){
|
void Relation::updateCmd(string attNameSet, string attSet, string attNameWhere, string attWhere){
|
||||||
//
|
vector<int> inds;
|
||||||
|
|
||||||
|
for (int i = 0; i < att.size(); ++i){
|
||||||
|
if (att[i].getName() == attNameWhere){
|
||||||
|
for (int j = 0; j < att[i].getSize(); ++j){
|
||||||
|
if (att[i][j] == attWhere){
|
||||||
|
inds.push_back(j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < att.size(); ++i){
|
||||||
|
if (att[i].getName() == attNameSet){
|
||||||
|
for (int j = 0; j < inds.size(); ++j){
|
||||||
|
att[i].setValue(attSet, inds[j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Relation::deleteCmd(string attName, string s){
|
void Relation::deleteCmd(string attName, string s){
|
||||||
|
|
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);
|
||||||
engine.deleteCmd("Food", "Breakfast", "Pancakes");
|
engine.updateCmd("Food", "Dinner", "SUCCESS", "Breakfast", "Pancakes");
|
||||||
engine.getTableFromName("Food").display();
|
engine.getTableFromName("Food").display();
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue