update a tuple added

This commit is contained in:
Rebecca Schofield 2015-10-06 19:10:48 -05:00
parent bfe5e4e981
commit 949f846931
4 changed files with 28 additions and 2 deletions

View file

@ -108,6 +108,24 @@ void Relation::insertTuple(vector<string> tuple){
}
}
void Relation::updateTuple(vector<string> 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.";

View file

@ -25,6 +25,7 @@ public:
int getSize();
void display();
void insertTuple(vector<string> tuple); //assuming they are in order
void updateTuple(vector<string> tuple, int index); //assuming they are in order
void insertFromRelation(Relation r);
void removeTuple(int index);
void removeFromTuple(int rindex, int aindex);

BIN
a.out Executable file

Binary file not shown.

View file

@ -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<string> 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();
}