added the error matching
This commit is contained in:
parent
c444b7368f
commit
bfe5e4e981
5 changed files with 14 additions and 46 deletions
43
DBEngine.cpp
43
DBEngine.cpp
|
@ -286,35 +286,6 @@ Relation DBEngine::crossProduct(Relation r1, Relation r2){
|
|||
return new_r;
|
||||
}
|
||||
|
||||
/*Relation DBEngine::updateCmd(Relation r, string attNameSet, string attSet, string attNameWhere, string attWhere){
|
||||
//brute forcing this, sorry universe
|
||||
//add error matching!!
|
||||
vector<int> inds;
|
||||
|
||||
for (int i = 0; i < r.getSize(); ++i){
|
||||
if (r[i].getName() == attNameWhere){
|
||||
for (int j = 0; j < r[i].getSize(); ++j){
|
||||
if (r[i][j] == attWhere){
|
||||
inds.push_back(j);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vector<Attribute> atts = r.getAttributes();
|
||||
|
||||
for (int i = 0; i < atts.size(); ++i){
|
||||
if (atts[i].getName() == attNameSet){
|
||||
for (int j = 0; j < inds.size(); ++j){
|
||||
atts[i].setValue(attSet, inds[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
r.setAttributes(atts);
|
||||
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){
|
||||
|
@ -324,20 +295,6 @@ void DBEngine::updateCmd(string relationName, string attNameSet, string attSet,
|
|||
}
|
||||
}
|
||||
|
||||
/*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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return r;
|
||||
}*/
|
||||
|
||||
void DBEngine::deleteCmd(string relationName, string attName, string att){
|
||||
for(int i = 0; i < tables.size(); i++){
|
||||
if (tables[i].getTableName() == relationName){
|
||||
|
|
|
@ -31,8 +31,6 @@ public:
|
|||
Relation setUnion(Relation r1, Relation r2);
|
||||
Relation setDiff(Relation r1, Relation r2);
|
||||
Relation crossProduct(Relation r1, Relation r2);
|
||||
//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);
|
||||
void deleteCmd(string relationName, string attName, string att);
|
||||
};
|
||||
|
|
15
Relation.cpp
15
Relation.cpp
|
@ -160,9 +160,11 @@ void Relation::removeFromTuple(int rindex, int aindex)
|
|||
|
||||
void Relation::updateCmd(string attNameSet, string attSet, string attNameWhere, string attWhere){
|
||||
vector<int> inds;
|
||||
bool found = false;
|
||||
|
||||
for (int i = 0; i < att.size(); ++i){
|
||||
if (att[i].getName() == attNameWhere){
|
||||
found = true;
|
||||
for (int j = 0; j < att[i].getSize(); ++j){
|
||||
if (att[i][j] == attWhere){
|
||||
inds.push_back(j);
|
||||
|
@ -170,7 +172,11 @@ void Relation::updateCmd(string attNameSet, string attSet, string attNameWhere,
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!found){
|
||||
cout << "Failure to update, the requested attribute was not found." << endl;
|
||||
}
|
||||
|
||||
for (int i = 0; i < att.size(); ++i){
|
||||
if (att[i].getName() == attNameSet){
|
||||
for (int j = 0; j < inds.size(); ++j){
|
||||
|
@ -183,8 +189,11 @@ void Relation::updateCmd(string attNameSet, string attSet, string attNameWhere,
|
|||
}
|
||||
|
||||
void Relation::deleteCmd(string attName, string s){
|
||||
bool found = false;
|
||||
|
||||
for (int i = 0; i < att.size(); ++i){
|
||||
if (att[i].getName() == attName){
|
||||
found = true;
|
||||
for (int j = 0; j < att[i].getSize(); ++j){
|
||||
if (att[i][j] == s){
|
||||
removeTuple(j);
|
||||
|
@ -192,4 +201,8 @@ void Relation::deleteCmd(string attName, string s){
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!found){
|
||||
cout << "Failure to delete, the requested attribute was not found." << endl;
|
||||
}
|
||||
}
|
BIN
a.out
BIN
a.out
Binary file not shown.
BIN
test
BIN
test
Binary file not shown.
Reference in a new issue