diff --git a/Parserv3.h b/Parserv3.h index 50355ed..d686cfa 100644 --- a/Parserv3.h +++ b/Parserv3.h @@ -36,32 +36,28 @@ class PAttribute { string name; string type; - string size; - bool key; + int size; public: PAttribute() { name = "~"; type = "~"; - size = "~"; - key = false; + size = 0; } PAttribute(string str, string t) { name = str; type = t; - size = "~"; - key = false; + size = 0; } - PAttribute(string str, string t, string s) + PAttribute(string str, string t, int s) { name = str; type = t; size = s; - key = false; } void setPAttributeName(string str) @@ -74,16 +70,11 @@ class PAttribute type = t; } - void setPAttributeSize(string s) + void setPAttributeSize(int s) { size = s; } - void setPAttributeKey() - { - key = true; - } - string getPAttribute() { return name; @@ -188,35 +179,25 @@ class PRenaming class PProjection { - string AName; - string RName; + string newName; + string oldName; public: PProjection() { - AName = "~"; - RName = "~"; + newName = "~"; + oldName = "~"; } PProjection(string s1, string s2) { - AName = s1; - RName = s2; - } - - void setAName(string s) - { - AName = s; - } - - void setRName(string s) - { - RName = s; + newName = s1; + oldName = s2; } string doPProjection() { - return "Projecting " + AName + " onto " + RName; + return "Projecting " + oldName + " onto " + newName; } }; @@ -398,22 +379,11 @@ class PExpression PExpression(string str) { temp = str; - /* - if(str == "project") - { - proj.setAName(""); - proj.setRName(""); - }*/ } void setPExpression(string str) { temp = str; - /* - if(proj.getAName() != "~" && proj.getRName() != "~") - { - proj.setAName() - }*/ } string getPExpression() diff --git a/Parserv4.cpp b/Parserv4.cpp index b947cc2..0752b54 100644 --- a/Parserv4.cpp +++ b/Parserv4.cpp @@ -127,6 +127,8 @@ vector createCMD(vector input) { input.erase(input.begin()); + //vector e1; + vector a; while(input[0] != ")") //inserting all values to relation @@ -150,13 +152,15 @@ vector createCMD(vector input) else { temp.setPAttributeType(input[0].substr(0,input[0].find("("))); - temp.setPAttributeSize(input[0].substr(input[0].find("("), input[0].find(")"))); + temp.setPAttributeSize(stoi(input[0].substr(input[0].find("("), input[0].find(")")))); input.erase(input.begin()); } a.push_back(temp); } + vector apk; //save primary keys temp storage + if(input[0] == "PRIMARY" && input[1] == "KEY") { input.erase(input.begin()); @@ -167,26 +171,22 @@ vector createCMD(vector input) while(input[0] != ")") //inserting all values to relation { + PAttribute temp; if (input[0] == ",") { input.erase(input.begin()); } - for(int i = 0; i < a.size(); ++i) - { - if(input[0] == a[i].getPAttribute()) - { - a[i].setPAttributeKey(); - break; - } - } + temp.setPAttributeName(input[0]); + + apk.push_back(temp); input.erase(input.begin()); } - // send create commands to DBEngine + return input; } } @@ -253,30 +253,15 @@ vector insertCMD(vector input) { input.erase(input.begin()); - //PExpression e(input[0]); + PExpression e; - //input.erase(input.begin()); - - if(input[0] == "project") + while(input[0] != ";") { - PProjection p; - - input.erase(input.begin()); - - if(intput[0].at(0) == "(") - { - p.setAName(input[0].substr(1, input[0].find(")"))); - } - - input.erase(input.begin()); - - p.setRName(input[0]); - - input.erase(input.begin()); - - // send projection command to DBengine. + e.setPExpression(e.getPExpression() + input[0]); } + cout << "Inserting: " << e.getPExpression() << " into " << r.getName() << ".\n"; + return input; } @@ -293,22 +278,23 @@ vector insertCMD(vector input) vector updateCMD(vector input) { - //parse Relation r + PRelation r(input[0]); + + input.erase(input.begin()); - //parse out SET if(input[0] == "SET") { input.erase(input.begin()); - PRelation r(input[0]); - - input.erase(input.begin()); - //parse out ( and send everything until ) into an Expression vector if(input[0] == "(") { + vector a; + vector s; + vector e; + input.erase(input.begin()); while(input[0] != ")") diff --git a/README.txt b/README.txt index bc38460..f4baea9 100755 --- a/README.txt +++ b/README.txt @@ -1,3 +1,12 @@ +//---IMPORTANT---// + +The function stoi() is used in the parser .cpp file to parse integers from the input. +When compiling things with the parser included, make sure you compile using: + +g++ -std=c++11 *.cpp + +//---------------// + I changed the name of the repo. To make everything pretty, rename your working folder, and type this line: git remote set-url origin https://github.tamu.edu/USERNAME/DMS.git