update a tuple added
This commit is contained in:
parent
bfe5e4e981
commit
949f846931
4 changed files with 28 additions and 2 deletions
18
Relation.cpp
18
Relation.cpp
|
@ -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.";
|
||||
|
|
|
@ -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
BIN
a.out
Executable file
Binary file not shown.
11
test.cpp
11
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<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();
|
||||
}
|
||||
|
|
Reference in a new issue