diff --git a/Relation.cpp b/Relation.cpp index 8b7e77e..de3078b 100755 --- a/Relation.cpp +++ b/Relation.cpp @@ -108,6 +108,24 @@ void Relation::insertTuple(vector tuple){ } } +void Relation::updateTuple(vector tuple, int index){ + if (tuple.size() != this->size) { + cout << "Failure to update: the sizes do not match."; + } + + if (!(index < att[0].getSize())) { + cout << "Failure to update: the requested index is out of bounds."; + } + + else { + for (int i = 0; i < att.size(); ++i) { + cout << "att[i][index]: " << att[i][index] << "\n"; + att[i].setValue(tuple[i], index); + cout << "att[i][index]: " << att[i][index] << "\n"; + } + } +} + void Relation::insertFromRelation(Relation r){ if (r.size != this->size) { cout << "Failure to insert: the sizes do not match."; diff --git a/Relation.h b/Relation.h index 73811aa..8d3f4d5 100755 --- a/Relation.h +++ b/Relation.h @@ -25,6 +25,7 @@ public: int getSize(); void display(); void insertTuple(vector tuple); //assuming they are in order + void updateTuple(vector tuple, int index); //assuming they are in order void insertFromRelation(Relation r); void removeTuple(int index); void removeFromTuple(int rindex, int aindex); diff --git a/a.out b/a.out new file mode 100755 index 0000000..2a0ac99 Binary files /dev/null and b/a.out differ diff --git a/test.cpp b/test.cpp index a03ae14..24e2e88 100755 --- a/test.cpp +++ b/test.cpp @@ -33,8 +33,15 @@ int main () { v.push_back(att3); engine.createTable("Food", v); - engine.updateCmd("Food", "Dinner", "SUCCESS", "Breakfast", "Pancakes"); + //engine.updateCmd("Food", "Dinner", "SUCCESS", "Breakfast", "Pancakes"); engine.getTableFromName("Food").display(); - engine.deleteCmd("Food", "Breakfast", "Pancakes"); + //engine.deleteCmd("Food", "Breakfast", "Pancakes"); + + vector tuple; + tuple.push_back("A pancake"); + tuple.push_back("A turkey sandwich"); + tuple.push_back("A steak"); + + engine.getTableFromName("Food").updateTuple(tuple, 0); engine.getTableFromName("Food").display(); }