diff --git a/DBEngine.h b/DBEngine.h index 64fcef2..ecb9590 100755 --- a/DBEngine.h +++ b/DBEngine.h @@ -43,9 +43,7 @@ public: void product() { /*Brandon*/ } bool unionComp(Relation r1, Relation r2) { - //Two relations are union-compatible if they have the same # of attributes and each attribute must be - //from the same domain - //return (() && ()); + return ((r1.getSize() == r2.getSize()) && (r1.getDomains() == r2.getDomains())); } diff --git a/Relation.h b/Relation.h index 5edec44..525a0d9 100755 --- a/Relation.h +++ b/Relation.h @@ -88,4 +88,16 @@ public: } } + + //make this better + vector getDomains() { + vector ds; + + for (int i = 0; i < size; ++i) + { + ds.push_back(att[i].getType()); + } + + return ds; + } }; diff --git a/a.out b/a.out index 1483993..428fec6 100755 Binary files a/a.out and b/a.out differ diff --git a/test.cpp b/test.cpp index 884021d..93f1781 100755 --- a/test.cpp +++ b/test.cpp @@ -25,16 +25,16 @@ int main() { vec.push_back(att2); Attribute att3("name", "VARCHAR(20)", true); - att1.addRow("Fry"); - att1.addRow("Bender"); - att1.addRow("Leela"); - att1.addRow("Zoidberg"); + att3.addRow("Fry"); + att3.addRow("Bender"); + att3.addRow("Leela"); + att3.addRow("Zoidberg"); Attribute att4("age", "INTEGER", false); - att2.addRow("22"); - att2.addRow("5"); - att2.addRow("22"); - att2.addRow("50"); + att4.addRow("22"); + att4.addRow("5"); + att4.addRow("22"); + att4.addRow("50"); vector vec2; vec2.push_back(att3); @@ -45,4 +45,26 @@ int main() { engine.createTable("table2", vec2); engine.showTables(engine.getTableFromName("table1")); + Attribute att5("name", "VARCHAR(20)", true); + att5.addRow("Yrf"); + att5.addRow("Redneb"); + att5.addRow("Aleel"); + att5.addRow("Grebdoiz"); + + Attribute att6("age", "INTEGER", false); + att6.addRow("44"); + att6.addRow("10"); + att6.addRow("44"); + att6.addRow("100"); + + vector vec3; + vec3.push_back(att5); + vec3.push_back(att6); + + engine.createTable("table3", vec3); + + cout << "a"; + cout << engine.unionComp(engine.getTableFromName("table1"), engine.getTableFromName("table2")); + cout << engine.unionComp(engine.getTableFromName("table2"), engine.getTableFromName("table3")); + }