From 8e308110b847aa66930ae292c453159ad1db1305 Mon Sep 17 00:00:00 2001 From: Brandon Jackson <1drummer@att.net> Date: Mon, 21 Sep 2015 22:00:02 -0500 Subject: [PATCH 1/5] Projection implemented, correct output, but segfaults --- DBEngine.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/DBEngine.cpp b/DBEngine.cpp index 1e47c4a..eaa3e49 100755 --- a/DBEngine.cpp +++ b/DBEngine.cpp @@ -52,12 +52,13 @@ void DBEngine::saveToFile(vector cmds){ //assumes that all attribute titles are unique Relation DBEngine::projection(vector input, Relation r){ - -// for(int i = 0; i < input.size(); i++) { -// it = find(r.getAttributes().begin(), r.getAttributes().end(), input[i]) + for(int i = 0; i < input.size(); ++i) { - //if(r[i].getName == input[]) -// } + for(int j = 0; j < r.getSize(); ++j) { + if((r.getAttributes())[j].getName() == input[i]) + (r.getAttributes())[j].display(); + } + } } //ASAP: TEST ALL OF THIS From 94e2844ffa8b2bee1ff4aca1f4016bd03aca8b93 Mon Sep 17 00:00:00 2001 From: Brandon Jackson <1drummer@att.net> Date: Tue, 22 Sep 2015 00:03:53 -0500 Subject: [PATCH 2/5] Projection is now working correctly, no segfault --- DBEngine.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/DBEngine.cpp b/DBEngine.cpp index eaa3e49..16b6f7a 100755 --- a/DBEngine.cpp +++ b/DBEngine.cpp @@ -52,13 +52,19 @@ void DBEngine::saveToFile(vector cmds){ //assumes that all attribute titles are unique Relation DBEngine::projection(vector input, Relation r){ + vector v; + string new_name = r.getTableName() + " Projection"; + for(int i = 0; i < input.size(); ++i) { for(int j = 0; j < r.getSize(); ++j) { if((r.getAttributes())[j].getName() == input[i]) - (r.getAttributes())[j].display(); + v.push_back((r.getAttributes())[j]); } } + + Relation temp(new_name, v); + return temp; } //ASAP: TEST ALL OF THIS From 45eb8cf148aef08e7a9212bccbb6f0e98ba780a3 Mon Sep 17 00:00:00 2001 From: Brandon Jackson <1drummer@att.net> Date: Tue, 22 Sep 2015 00:05:17 -0500 Subject: [PATCH 3/5] Updated test to prove projection works --- test.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/test.cpp b/test.cpp index 1c138cb..e6f7261 100755 --- a/test.cpp +++ b/test.cpp @@ -47,5 +47,15 @@ int main() { n.push_back("Hcnul"); n.push_back("Rennid"); + //Projection test + vector projectTest; + projectTest.push_back("Breakfast"); + projectTest.push_back("Dinner"); + + cout << "\n***Initiated Projection***\n" << endl; + + Relation sub_r = engine.projection(projectTest, r); + sub_r.display(); + //engine.rename(r, o, n); -} \ No newline at end of file +} From 670668124b27d08890c7ea7ee11baf83e7953d80 Mon Sep 17 00:00:00 2001 From: Alex Huddleston Date: Tue, 22 Sep 2015 23:27:34 -0500 Subject: [PATCH 4/5] Create Parserv3.h --- Parserv3.h | 242 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 242 insertions(+) create mode 100644 Parserv3.h diff --git a/Parserv3.h b/Parserv3.h new file mode 100644 index 0000000..154cffe --- /dev/null +++ b/Parserv3.h @@ -0,0 +1,242 @@ +#include // std::string +#include // std::cout +#include // std::stringstream +#include +#include + +using namespace std; + + +class Relation +{ + string name; + + public: + + string getName() + { + return name; + } +} + + + +class Union +{ + string Un1; + string Un2; + + Union (string s1, string s2) + { + Un1 = s1; + Un2 = s2; + } + + string getUnion() + { + return "Union of " + Un1 + " and " + Un2; + } +} + +class Product +{ + string Pr1; + string Pr2; + + Product(string s1, string s2) + { + Pr1 = s1; + Pr2 = s2; + } + + string getProduct() + { + return "Product of " + Pr1 + " and " + Pr2; + } +} + +class Difference() +{ + string D1; + string D2; + + Difference(string s1, string s2) + { + D1 = s1; + D2 = s2; + } + + string getDifference() + { + return "Difference of " + D1 + " and " + D2; + } +} + +class Rename() +{ + string newName; + string oldName; + + Rename(string s1, string s2) + { + newName = s1; + oldName = s2; + } + + string doRename() + { + return "Renaming " + oldName + " to " + newName; + } +} + +class Projection() +{ + string newName; + string oldName; + + Rename(string s1, string s2) + { + newName = s1; + oldName = s2; + } + + string doRename() + { + return "Projecting " + oldName + " onto " + newName; + } +} + +class Operand() +{ + string op; + + Operand(string str) + { + op = str; + } + + void setOperand(string str) + { + op = str; + } + + string getOperand() + { + return op; + } +} + +class Op() +{ + string op; + + Op(string str) + { + op = str; + } + + void setOp(string str) + { + op = str; + } + + string getOp() + { + return op; + } +} + +class Comparison() +{ + Op op; + Operand operand1; + Operand operand2; + + Comparison(string str1, string str2, string str3) + { + operand1.setOperand(str1); + op.setOp(str2); + operand2.setOperand(str3); + } + + void setComparison(string str1, string str2, string str3) + { + operand1.setOperand(str1); + op.setOp(str2); + operand2.setOperand(str3); + } + + string getComparison() + { + return op1.getOperand() + " " + op.getOp() + " " + op2.getOperand(); + } +} + +class Conjunction() +{ + string conj; + + Conjunction(string str) + { + conj = str; + } + + void setConjunction(string str) + { + conj = str; + } + + string getConjunction() + { + return conj; + } +} + +class Condition() +{ + string cond; + + Condition(string str) + { + cond = str; + } + + void setCondition(string str) + { + cond = str; + } + + string getCondition() + { + return cond; + } +} + +class Selection() +{ + string select; + + Selection(string str) + { + select = str; + } + + string getSelection() + { + return select; + } +} + +class expr +{ + Relation r; + + selection + projection + renaming + Union + difference + product + +} + From 6f10af0b32a8ace8f2129d0525225b38eac82976 Mon Sep 17 00:00:00 2001 From: Alex Huddleston Date: Tue, 22 Sep 2015 23:44:51 -0500 Subject: [PATCH 5/5] Update Parserv3.h --- Parserv3.h | 254 +++++++++++++++++++++++++++-------------------------- 1 file changed, 130 insertions(+), 124 deletions(-) diff --git a/Parserv3.h b/Parserv3.h index 154cffe..1fb63d7 100644 --- a/Parserv3.h +++ b/Parserv3.h @@ -7,17 +7,24 @@ using namespace std; -class Relation +class Relation { string name; - public: + Relation(string str) + { + name = str; + } + void setRelation(string str) + { + name = str; + } string getName() { return name; } -} +}; @@ -36,7 +43,7 @@ class Union { return "Union of " + Un1 + " and " + Un2; } -} +}; class Product { @@ -53,9 +60,9 @@ class Product { return "Product of " + Pr1 + " and " + Pr2; } -} +}; -class Difference() +class Difference { string D1; string D2; @@ -70,14 +77,14 @@ class Difference() { return "Difference of " + D1 + " and " + D2; } -} +}; -class Rename() +class Renaming { string newName; string oldName; - Rename(string s1, string s2) + Renaming(string s1, string s2) { newName = s1; oldName = s2; @@ -87,156 +94,155 @@ class Rename() { return "Renaming " + oldName + " to " + newName; } -} +}; -class Projection() +class Projection { string newName; string oldName; - Rename(string s1, string s2) + Projection(string s1, string s2) { newName = s1; oldName = s2; } - string doRename() + string doProjection() { return "Projecting " + oldName + " onto " + newName; } -} +}; -class Operand() +class Operand { string op; - Operand(string str) - { - op = str; - } + public: - void setOperand(string str) - { - op = str; - } - - string getOperand() - { - return op; - } -} + Operand() + { + } + + Operand(string str) + { + op = str; + } + + void setOperand(string str) + { + op = str; + } + + string getOperand() + { + return op; + } +}; -class Op() +class Op { string op; - Op(string str) - { - op = str; - } - - void setOp(string str) - { - op = str; - } - - string getOp() - { - return op; - } -} + public: + Op() + { + } + + Op(string str) + { + op = str; + } + + void setOp(string str) + { + op = str; + } + + string getOp() + { + return op; + } +}; -class Comparison() +class Comparison { Op op; Operand operand1; Operand operand2; - Comparison(string str1, string str2, string str3) - { - operand1.setOperand(str1); - op.setOp(str2); - operand2.setOperand(str3); - } + public: - void setComparison(string str1, string str2, string str3) - { - operand1.setOperand(str1); - op.setOp(str2); - operand2.setOperand(str3); - } - - string getComparison() - { - return op1.getOperand() + " " + op.getOp() + " " + op2.getOperand(); - } -} + Comparison(string str1, string str2, string str3) + { + operand1.setOperand(str1); + op.setOp(str2); + operand2.setOperand(str3); + } + + void setComparison(string str1, string str2, string str3) + { + operand1.setOperand(str1); + op.setOp(str2); + operand2.setOperand(str3); + } + + string getComparison() + { + return operand1.getOperand() + " " + op.getOp() + " " + operand2.getOperand(); + } +}; -class Conjunction() +class Conjunction { string conj; - - Conjunction(string str) - { - conj = str; - } - - void setConjunction(string str) - { - conj = str; - } - - string getConjunction() - { - return conj; - } -} + public: + Conjunction(string str) + { + conj = str; + } + + void setConjunction(string str) + { + conj = str; + } + + string getConjunction() + { + return conj; + } +}; -class Condition() +class Condition { string cond; - - Condition(string str) - { - cond = str; - } - - void setCondition(string str) - { - cond = str; - } - - string getCondition() - { - return cond; - } -} + public: + Condition(string str) + { + cond = str; + } + + void setCondition(string str) + { + cond = str; + } + + string getCondition() + { + return cond; + } +}; -class Selection() +class Selection { string select; - - Selection(string str) - { - select = str; - } - - string getSelection() - { - return select; - } -} - -class expr -{ - Relation r; - - selection - projection - renaming - Union - difference - product - -} - + public: + Selection(string str) + { + select = str; + } + + string getSelection() + { + return select; + } +};