diff --git a/Attribute.cpp b/Attribute.cpp index dad5d6a..48eff2f 100755 --- a/Attribute.cpp +++ b/Attribute.cpp @@ -52,8 +52,7 @@ void Attribute::setName(string s){ name = s; } -void Attribute::setValue(string s, int index) -{ +void Attribute::setValue(string s, int index) { values[index] = s; } @@ -89,4 +88,5 @@ void Attribute::display(){ void Attribute::clearAllValues(){ values.clear(); + size = 0; } \ No newline at end of file diff --git a/DBEngine.cpp b/DBEngine.cpp index 1eb0e4e..04bc35f 100755 --- a/DBEngine.cpp +++ b/DBEngine.cpp @@ -291,20 +291,30 @@ Relation DBEngine::crossProduct(Relation r1, Relation r2){ //WHERE Name = ‘Joseph Lieberman’ Relation DBEngine::updateCmd(Relation r, string attNameSet, string attSet, string attNameWhere, string attWhere){ - Relation temp = selection(attNameWhere, attWhere, r); - vector atts = temp.getAttributes(); - - for (int i = 0; i < atts.size(); ++i){ - if (atts[i].getName() == attNameSet) { - for (int j = 0; j < atts[i].getSize(); ++j){ - atts[i]setValue(attSet, j); + //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); + } } - - break; } } - //currently returns a relation with just the changed values, need to look at proper join - //if proper join does not work, plan B is brute force - return temp; + 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; } diff --git a/Relation.cpp b/Relation.cpp index 18a1277..2dd5e14 100755 --- a/Relation.cpp +++ b/Relation.cpp @@ -45,6 +45,11 @@ vector Relation::getAttributes(){ return att; } +void Relation::setAttributes(vector v){ + size = v.size(); + att = v; +} + vector Relation::getAttributeNames(){ vector temp; for(int i = 0; i < size; ++i){ diff --git a/Relation.h b/Relation.h index 4c7e1e2..dbff948 100755 --- a/Relation.h +++ b/Relation.h @@ -17,6 +17,7 @@ public: Attribute operator[](int i); vector getTuple(int index); vector getAttributes(); + void setAttributes(vector v); vector getAttributeNames(); Attribute& getAttributeByName(string s); bool isAttribute(string s); diff --git a/a.out b/a.out new file mode 100755 index 0000000..833637f Binary files /dev/null and b/a.out differ diff --git a/test.cpp b/test.cpp index 8b4189e..4bbd43b 100755 --- a/test.cpp +++ b/test.cpp @@ -17,12 +17,15 @@ int main () { att1.addCell("Pancakes"); att1.addCell("Waffles"); att1.addCell("Biscuits"); + att1.addCell("Pancakes"); att2.addCell("Turkey Sandwich"); att2.addCell("Caesar Salad"); att2.addCell("Pizza"); + att2.addCell("Sushi"); att3.addCell("Steak"); att3.addCell("Shrimp"); att3.addCell("Ribs"); + att3.addCell("Lasagna"); vector v; v.push_back(att1); @@ -30,18 +33,6 @@ int main () { v.push_back(att3); engine.createTable("Food", v); - - //engine.update - - /*actual testing - string x; - - cout << "Enter DBMS Commands: "; - while(getline(cin, x)) - { - //cout << x << endl; - parse(x, engine); - cout << "Enter DBMS Commands: "; - } - */ + Relation temp = engine.updateCmd(engine.getTableFromName("Food"), "Dinner", "SUCCESS", "Breakfast", "Pancakes"); + temp.display(); }