diff --git a/Attribute.cpp b/Attribute.cpp index 01437da..5c2a0d6 100755 --- a/Attribute.cpp +++ b/Attribute.cpp @@ -21,6 +21,11 @@ void Attribute::addCell(string v){ size++; } +void Attribute::removeCell(int index){ + values.erase(values.begin() + index); + size--; +} + string Attribute::operator[](int i){ return values[i]; } diff --git a/Attribute.h b/Attribute.h index f721ff7..9bb84fd 100755 --- a/Attribute.h +++ b/Attribute.h @@ -15,6 +15,7 @@ public: Attribute(); Attribute(string n, string t, bool k); void addCell(string v); + void removeCell(int index); string operator[](int i); vector getValues(); string getName(); diff --git a/DBEngine.cpp b/DBEngine.cpp index f622cd5..fb4e210 100755 --- a/DBEngine.cpp +++ b/DBEngine.cpp @@ -87,8 +87,22 @@ void DBEngine::rename(Relation& r, vector oldnames, vector newna Relation DBEngine::setUnion(Relation r1, Relation r2){ if (r1.getAttributeNames() != r2.getAttributeNames()){ - cout << "Failure to union: the relations are not union-compatible"; - return; + vector v1 = r1.getAttributeNames(); + vector v2 = r2.getAttributeNames(); + + for (int i = 0; i < v1.size(); ++i){ + cout << v1[i] << " "; + } + cout << "\n"; + + for (int i = 0; i < v2.size(); ++i){ + cout << v2[i] << " "; + } + cout << "\n"; + + + cout << "Failure to union: the relations are not union-compatible.\nreturning the first relation.\n"; + return r1; } else { diff --git a/Relation.cpp b/Relation.cpp index d2dca12..86a6dad 100755 --- a/Relation.cpp +++ b/Relation.cpp @@ -110,3 +110,15 @@ void Relation::insertFromRelation(Relation r){ } } } + +void Relation::removeTuple(int index){ + if (index >= this->size) { + cout << "Failure to delete: the requested index is out of bounds."; + } + + else { + for (int i = 0; i < att.size(); ++i) { + att[i].removeCell(index); + } + } +} \ No newline at end of file diff --git a/Relation.h b/Relation.h index 7de9d11..2a8846c 100755 --- a/Relation.h +++ b/Relation.h @@ -23,5 +23,5 @@ public: void display(); void insertTuple(vector tuple); //assuming they are in order void insertFromRelation(Relation r); - //void removeTuple(); + void removeTuple(int index); }; \ No newline at end of file diff --git a/a.out b/a.out new file mode 100755 index 0000000..c56b01f Binary files /dev/null and b/a.out differ diff --git a/test.cpp b/test.cpp index f21b31b..bf7b4c3 100755 --- a/test.cpp +++ b/test.cpp @@ -29,9 +29,9 @@ int main() { engine.createTable("Food", v); - Attribute att4("SecondBreakfast", "VARCHAR(20)", true); - Attribute att5("SecondLunch", "VARCHAR(20)", false); - Attribute att6("SecondDinner", "VARCHAR(20)", false); + Attribute att4("Breakfast", "VARCHAR(20)", true); + Attribute att5("Lunch", "VARCHAR(20)", false); + Attribute att6("Dinner", "VARCHAR(20)", false); att4.addCell("Pancakes"); att4.addCell("Bacon"); @@ -50,5 +50,5 @@ int main() { engine.createTable("MoarFood", v2); - //engine.setUnion(engine.getTableFromName("Food"), engine.getTableFromName("MoarFood")).display(); + engine.setUnion(engine.getTableFromName("Food"), engine.getTableFromName("MoarFood")).display(); }