diff --git a/DBEngine.cpp b/DBEngine.cpp index c9a55ac..93bc89d 100755 --- a/DBEngine.cpp +++ b/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 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 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){ diff --git a/DBEngine.h b/DBEngine.h index 1db9b32..06d8b2f 100755 --- a/DBEngine.h +++ b/DBEngine.h @@ -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); }; diff --git a/Relation.cpp b/Relation.cpp index c7377ab..8b7e77e 100755 --- a/Relation.cpp +++ b/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 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; + } } \ No newline at end of file diff --git a/a.out b/a.out deleted file mode 100755 index df7d737..0000000 Binary files a/a.out and /dev/null differ diff --git a/test b/test deleted file mode 100755 index 2817c04..0000000 Binary files a/test and /dev/null differ