Merge branch 'beccadev'
This commit is contained in:
commit
efd560a10e
6 changed files with 68 additions and 11 deletions
23
DBEngine.cpp
23
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,9 +313,18 @@ 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){
|
||||||
for (int i = 0; i < r.getSize(); ++i){
|
for (int i = 0; i < r.getSize(); ++i){
|
||||||
if (r[i].getName() == attName){
|
if (r[i].getName() == attName){
|
||||||
for (int j = 0; j < r[i].getSize(); ++j){
|
for (int j = 0; j < r[i].getSize(); ++j){
|
||||||
|
@ -326,6 +335,14 @@ Relation DBEngine::deleteCmd(Relation r, string attName, string att){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//r.setAttributes(atts);
|
|
||||||
return r;
|
return r;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
void DBEngine::deleteCmd(string relationName, string attName, string att){
|
||||||
|
for(int i = 0; i < tables.size(); i++){
|
||||||
|
if (tables[i].getTableName() == relationName){
|
||||||
|
tables[i].deleteCmd(attName, att);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +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);
|
||||||
Relation deleteCmd(Relation r, string attName, string att);
|
void updateCmd(string relationName, string attNameSet, string attSet, string attNameWhere, string attWhere);
|
||||||
|
//Relation deleteCmd(Relation r, string attName, string att);
|
||||||
|
void deleteCmd(string relationName, string attName, string att);
|
||||||
};
|
};
|
||||||
|
|
36
Relation.cpp
36
Relation.cpp
|
@ -157,3 +157,39 @@ void Relation::removeFromTuple(int rindex, int aindex)
|
||||||
att[rindex].removeCell(aindex);
|
att[rindex].removeCell(aindex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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){
|
||||||
|
for (int i = 0; i < att.size(); ++i){
|
||||||
|
if (att[i].getName() == attName){
|
||||||
|
for (int j = 0; j < att[i].getSize(); ++j){
|
||||||
|
if (att[i][j] == s){
|
||||||
|
removeTuple(j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,4 +28,6 @@ public:
|
||||||
void insertFromRelation(Relation r);
|
void insertFromRelation(Relation r);
|
||||||
void removeTuple(int index);
|
void removeTuple(int index);
|
||||||
void removeFromTuple(int rindex, int aindex);
|
void removeFromTuple(int rindex, int aindex);
|
||||||
|
void updateCmd(string attNameSet, string attSet, string attNameWhere, string attWhere);
|
||||||
|
void deleteCmd(string attName, string s);
|
||||||
};
|
};
|
BIN
a.out
BIN
a.out
Binary file not shown.
4
test.cpp
4
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.deleteCmd(engine.getTableFromName("Food"), "Breakfast", "Pancakes");
|
engine.updateCmd("Food", "Dinner", "SUCCESS", "Breakfast", "Pancakes");
|
||||||
temp.display();
|
engine.getTableFromName("Food").display();
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue