diff --git a/Attribute.cpp b/Attribute.cpp index a2ae7f6..dad5d6a 100755 --- a/Attribute.cpp +++ b/Attribute.cpp @@ -52,6 +52,11 @@ void Attribute::setName(string s){ name = s; } +void Attribute::setValue(string s, int index) +{ + values[index] = s; +} + string Attribute::getType(){ return type; } diff --git a/Attribute.h b/Attribute.h index 72b97d6..46bd0b3 100755 --- a/Attribute.h +++ b/Attribute.h @@ -22,6 +22,7 @@ public: vector getValues(); string getName(); void setName(string s); + void setValue(string s, int index); string getType(); bool isKey(); int getSize(); diff --git a/DBApp.cpp b/DBApp.cpp index cb9dc19..50c8918 100755 --- a/DBApp.cpp +++ b/DBApp.cpp @@ -37,4 +37,4 @@ int main() } } -*/ \ No newline at end of file +*/ diff --git a/DBAppV2.cpp b/DBAppV2.cpp new file mode 100644 index 0000000..3b96c2b --- /dev/null +++ b/DBAppV2.cpp @@ -0,0 +1,126 @@ +#include + +using namespace std; + +/* + +void yourAccount() +{ + cout<<"name: yourName"<>choice; + cout<<"0. Return to main menu"<>choice; + cout<<"0. Return to main menu"<>choice; + cout<<"0. Return to main menu"<>choice; + cout<<"Boards will be displayed soon"<>choice; + cout<<"0. Return to main menu"<>choice; + cout<<"0. Return to main menu"<>choice; + + switch (choice) + { + case 1: yourAccount(); + case 2: BoardMenu(); + case 3: showMessages(); + case 4: showGroups(); + } +} + + +int main() +{ + cout<<"***************************************"<>choice; + + + if (choice == 1) + { + cout<<"ramera"< DBEngine::getRelations(){ @@ -167,18 +167,6 @@ Relation DBEngine::rename(vector newnames, Relation &r) } return r; } - /* - else if (oldnames != r.getAttributeNames()) { - cout << "FAILURE TO RENAME: the attributes to be renamed do not exist in the relation.\n"; - return; - } - - else { - for(int i = 0; i < oldnames.size(); ++i){ - r.renameAttribute(oldnames[i], newnames[i]); - } - } - */ } @@ -230,10 +218,11 @@ Relation DBEngine::setDiff(Relation r1, Relation r2){ int size = 0; +<<<<<<< HEAD for(int x = 0; x < r2.getAttributes().size(); ++x) { for (int i = 0; i < r2.getAttributes()[x].getSize(); ++i) - { + { temp = r2.getTuple(i); for(int y = 0; y < new_r.getAttributes().size(); ++y) @@ -256,8 +245,7 @@ Relation DBEngine::setDiff(Relation r1, Relation r2){ } } } - } - + } return new_r; } } diff --git a/DBEngine.h b/DBEngine.h index 7916e96..c688cb8 100755 --- a/DBEngine.h +++ b/DBEngine.h @@ -18,7 +18,6 @@ public: void insertValues(string r, vector v); vector getRelations(); bool isRelation(string n); - //void showTable(Relation r); Relation& getTableFromName(string n); void saveToFile(vector cmds); Relation selection(string attName, string s, Relation r); diff --git a/Parser.cpp b/Parser.cpp index 43ed941..c41a61b 100644 --- a/Parser.cpp +++ b/Parser.cpp @@ -19,17 +19,6 @@ vector tokenize(string ss) { output.push_back(tempString); } - - //testing--------------- - //cout<<"TokenList: "; - - // for (int i = 0; i input) } } -Relation condition(vector input, Relation &r) +Relation condition(vector input, Relation &r, DBEngine &engine) { Relation rfinal = r; - - //UNTESTED - //testing to see if there is an && or || present - if (input.size() > 3) { - //test print - for (int i = 0; i < input.size(); ++i) - cout << "input[i]: " << input[i] << "\n"; - - - //this is probably wrong, added a cout for testing - string bin_op = input[3]; - cout << "bin_op, should be && or ||: " << bin_op << "\n"; - - //making each half a new vector, probably a better way to do this - vector firsthalf; - vector secondhalf; - - //again, all untested. it's weird to not test this stuff - for (int i = 0; i < input.size(); ++i){ - if (i < 3) - firsthalf.push_back(input[i]); - else - secondhalf.push_back(input[i]); - + + Attribute a1 = r.getAttributeByName(input[0]); + input.erase(input.begin()); + string op = input[0]; + input.erase(input.begin()); + Attribute a2; + string c; + if(r.isAttribute(input[0])) + { + a2 = r.getAttributeByName(input[0]); + input.erase(input.begin()); + for(int i = 0; i < r.getAttributes().size(); ++i) + { + if(r.getAttributes()[i].getName() == a1.getName()) + { + int offset = 0; + if(op == "==") + { + for(int x = 0; x < r.getAttributeByName(a1.getName()).getSize(); ++x) + { + if(r.getAttributeByName(a1.getName()).getValues()[x] != r.getAttributeByName(a2.getName()).getValues()[x]) + { + rfinal.removeTuple(x - offset); + offset += 1; + } + } + } + else if(op == "!=") + { + for(int x = 0; x < r.getAttributeByName(a1.getName()).getSize(); ++x) + { + if(r.getAttributeByName(a1.getName()).getValues()[x] == r.getAttributeByName(a2.getName()).getValues()[x]) + { + rfinal.removeTuple(x - offset); + offset += 1; + } + } + } + else if(op == ">=") + { + if(r.getAttributeByName(a1.getName()).getType() == "INTEGER" && r.getAttributeByName(a2.getName()).getType() == "INTEGER") + { + for(int x = 0; x < r.getAttributeByName(a1.getName()).getSize(); ++x) + { + if(stoi(r.getAttributeByName(a1.getName()).getValues()[x]) < stoi(r.getAttributeByName(a2.getName()).getValues()[x])) + { + rfinal.removeTuple(x - offset); + offset += 1; + } + } + } + else + { + cout << "Attribute type is not an INTEGER." << endl; + exit(1); + } + } + else if(op == "<=") + { + if(r.getAttributeByName(a1.getName()).getType() == "INTEGER" && r.getAttributeByName(a2.getName()).getType() == "INTEGER") + { + for(int x = 0; x < r.getAttributeByName(a1.getName()).getSize(); ++x) + { + if(stoi(r.getAttributeByName(a1.getName()).getValues()[x]) > stoi(r.getAttributeByName(a2.getName()).getValues()[x])) + { + rfinal.removeTuple(x - offset); + offset += 1; + } + } + } + else + { + cout << "Attribute type is not an INTEGER." << endl; + exit(1); + } + } + else if(op == ">") + { + + if(r.getAttributeByName(a1.getName()).getType() == "INTEGER" && r.getAttributeByName(a2.getName()).getType() == "INTEGER") + { + for(int x = 0; x < r.getAttributeByName(a1.getName()).getSize(); ++x) + { + if(stoi(r.getAttributeByName(a1.getName()).getValues()[x]) <= stoi(r.getAttributeByName(a2.getName()).getValues()[x])) + { + rfinal.removeTuple(x - offset); + offset += 1; + } + } + } + else + { + cout << "Attribute type is not an INTEGER." << endl; + exit(1); + } + } + else if(op == "<") + { + if(r.getAttributeByName(a1.getName()).getType() == "INTEGER" && r.getAttributeByName(a2.getName()).getType() == "INTEGER") + { + for(int x = 0; x < r.getAttributeByName(a1.getName()).getSize(); ++x) + { + if(stoi(r.getAttributeByName(a1.getName()).getValues()[x]) >= stoi(r.getAttributeByName(a2.getName()).getValues()[x])) + { + rfinal.removeTuple(x - offset); + offset += 1; + } + } + } + else + { + cout << "Attribute type is not an INTEGER." << endl; + exit(1); + } + } + } } - - //calling condition again with each half - Relation r1 = condition(firsthalf, rfinal); - Relation r2 = condition(secondhalf, rfinal); - - //NO IDEA IF THIS ACTUALLY WORKS - //HOORAY - //HOW THE FUCK DO PEOPLE CODE LIKE THIS - if (bin_op == "&&"){ - //with engine as the DBEngine object that maybe exists - return engine.crossProduct(r1, r2); - } - - else if (bin_op == "||"){ - //with engine as the DBEngine object that maybe exists - return engine.setUnion(r1, r2); - } - - else { - cout << "Something strange happened. bin_op: " << bin_op << "\n"; - cout << "Returning the initial relation."; - return rfinal; - } - } - - else { - - Attribute a1 = r.getAttributeByName(input[0]); + else if(input[0].at(0) == '\"') + { + c = input[0].substr(1, input[0].find_last_of("\"") - 1); input.erase(input.begin()); - string op = input[0]; - input.erase(input.begin()); - Attribute a2; - string c; - //cout << input[0] << endl; - if(input[0].at(0) == '\"') + int offset = 0; + //input.erase(input.begin()); + if(op == "==") { - c = input[0].substr(1, input[0].find_last_of("\"") - 1); - //cout << c << endl; - } - if(r.isAttribute(input[0])) - { - a2 = r.getAttributeByName(input[0]); - input.erase(input.begin()); for(int i = 0; i < r.getAttributes().size(); ++i) { if(r.getAttributes()[i].getName() == a1.getName()) { - /* - for(int j = 0; j < r.getAttributeByName(a1.getName()).getValues().size; ++j) + for(int j = 0; j < r.getAttributeByName(a1.getName()).getValues().size(); ++j) { - if(r.getAttributeByName(a1.getName()).getValues()[j] == ) + if(r.getAttributeByName(a1.getName()).getValues()[j] != c) { - rfinal.insertTuple(r.getTuple(j)); - } - }*/ - if(op == "==") - { - for(int x = 0; x < r.getAttributeByName(a1.getName()).getSize(); ++x) - { - if(r.getAttributeByName(a1.getName()).getValues()[x] != r.getAttributeByName(a2.getName()).getValues()[x]) - { - rfinal.removeTuple(x); - //rfinal.insertAttributes(a); - } - } - } - else if(op == "!=") - { - for(int x = 0; x < r.getAttributeByName(a1.getName()).getSize(); ++x) - { - if(r.getAttributeByName(a1.getName()).getValues()[x] == r.getAttributeByName(a2.getName()).getValues()[x]) - { - rfinal.removeTuple(x); - //rfinal.insertAttributes(a); - } - } - } - else if(op == ">=") - { - if(r.getAttributeByName(a1.getName()).getType() == "INTEGER" && r.getAttributeByName(a2.getName()).getType() == "INTEGER") - { - for(int x = 0; x < r.getAttributeByName(a1.getName()).getSize(); ++x) - { - if(stoi(r.getAttributeByName(a1.getName()).getValues()[x]) < stoi(r.getAttributeByName(a2.getName()).getValues()[x])) - { - rfinal.removeTuple(x); - //rfinal.insertAttributes(a); - } - } - } - else - { - cout << "Attribute type is not an INTEGER." << endl; - exit(1); - } - } - else if(op == "<=") - { - if(r.getAttributeByName(a1.getName()).getType() == "INTEGER" && r.getAttributeByName(a2.getName()).getType() == "INTEGER") - { - for(int x = 0; x < r.getAttributeByName(a1.getName()).getSize(); ++x) - { - if(stoi(r.getAttributeByName(a1.getName()).getValues()[x]) > stoi(r.getAttributeByName(a2.getName()).getValues()[x])) - { - rfinal.removeTuple(x); - //rfinal.insertAttributes(a); - } - } - } - else - { - cout << "Attribute type is not an INTEGER." << endl; - exit(1); - } - } - else if(op == ">") - { - - if(r.getAttributeByName(a1.getName()).getType() == "INTEGER" && r.getAttributeByName(a2.getName()).getType() == "INTEGER") - { - for(int x = 0; x < r.getAttributeByName(a1.getName()).getSize(); ++x) - { - if(stoi(r.getAttributeByName(a1.getName()).getValues()[x]) <= stoi(r.getAttributeByName(a2.getName()).getValues()[x])) - { - rfinal.removeTuple(x); - //rfinal.insertAttributes(a); - } - } - } - else - { - cout << "Attribute type is not an INTEGER." << endl; - exit(1); - } - } - else if(op == "<") - { - if(r.getAttributeByName(a1.getName()).getType() == "INTEGER" && r.getAttributeByName(a2.getName()).getType() == "INTEGER") - { - for(int x = 0; x < r.getAttributeByName(a1.getName()).getSize(); ++x) - { - if(stoi(r.getAttributeByName(a1.getName()).getValues()[x]) >= stoi(r.getAttributeByName(a2.getName()).getValues()[x])) - { - rfinal.removeTuple(x); - //rfinal.insertAttributes(a); - } - } - } - else - { - cout << "Attribute type is not an INTEGER." << endl; - exit(1); + rfinal.removeTuple(j - offset); + offset += 1; } } } } } - else + else if(op == "!=") { - input.erase(input.begin()); - if(op == "==") + for(int i = 0; i < r.getAttributes().size(); ++i) { - for(int i = 0; i < r.getAttributes().size(); ++i) + if(r.getAttributes()[i].getName() == a1.getName()) { - if(r.getAttributes()[i].getName() == a1.getName()) + for(int j = 0; j < r.getAttributeByName(a1.getName()).getValues().size(); ++j) { - for(int j = 0; j < r.getAttributeByName(a1.getName()).getValues().size(); ++j) + if(r.getAttributeByName(a1.getName()).getValues()[j] == c) { - if(r.getAttributeByName(a1.getName()).getValues()[j] != c) - { - rfinal.removeTuple(j); - } + rfinal.removeTuple(j - offset); + offset += 1; } } } } - else if(op == "!=") - { - for(int i = 0; i < r.getAttributes().size(); ++i) - { - if(r.getAttributes()[i].getName() == a1.getName()) - { - for(int j = 0; j < r.getAttributeByName(a1.getName()).getValues().size(); ++j) - { - if(r.getAttributeByName(a1.getName()).getValues()[j] == c) - { - rfinal.removeTuple(j); - } - } - } - } - } - else if(op == ">=") - { - if(r.getAttributeByName(a1.getName()).getType() == "INTEGER") - { - for(int i = 0; i < r.getAttributes().size(); ++i) - { - if(r.getAttributes()[i].getName() == a1.getName()) - { - for(int j = 0; j < r.getAttributeByName(a1.getName()).getValues().size(); ++j) - { - if(stoi(r.getAttributeByName(a1.getName()).getValues()[j]) < stoi(c)) - { - rfinal.removeTuple(j); - } - } - } - } - } - else - { - cout << "Attribute type is not an INTEGER." << endl; - exit(1); - } - } - else if(op == "<=") - { - if(r.getAttributeByName(a1.getName()).getType() == "INTEGER") - { - for(int i = 0; i < r.getAttributes().size(); ++i) - { - if(r.getAttributes()[i].getName() == a1.getName()) - { - for(int j = 0; j < r.getAttributeByName(a1.getName()).getValues().size(); ++j) - { - if(stoi(r.getAttributeByName(a1.getName()).getValues()[j]) > stoi(c)) - { - rfinal.removeTuple(j); - } - } - } - } - } - else - { - cout << "Attribute type is not an INTEGER." << endl; - exit(1); - } - } - else if(op == ">") - { - - if(r.getAttributeByName(a1.getName()).getType() == "INTEGER") - { - for(int i = 0; i < r.getAttributes().size(); ++i) - { - if(r.getAttributes()[i].getName() == a1.getName()) - { - for(int j = 0; j < r.getAttributeByName(a1.getName()).getValues().size(); ++j) - { - if(stoi(r.getAttributeByName(a1.getName()).getValues()[j]) <= stoi(c)) - { - rfinal.removeTuple(j); - } - } - } - } - } - else - { - cout << "Attribute type is not an INTEGER." << endl; - exit(1); - } - } - else if(op == "<") - { - - if(r.getAttributeByName(a1.getName()).getType() == "INTEGER") - { - for(int i = 0; i < r.getAttributes().size(); ++i) - { - if(r.getAttributes()[i].getName() == a1.getName()) - { - for(int j = 0; j < r.getAttributeByName(a1.getName()).getValues().size(); ++j) - { - if(stoi(r.getAttributeByName(a1.getName()).getValues()[j]) >= stoi(c)) - { - rfinal.removeTuple(j); - } - } - } - } - } - else - { - cout << "Attribute type is not an INTEGER." << endl; - exit(1); - } - } } - return rfinal; + else if(op == ">=") + { + if(r.getAttributeByName(a1.getName()).getType() == "INTEGER") + { + for(int i = 0; i < r.getAttributes().size(); ++i) + { + if(r.getAttributes()[i].getName() == a1.getName()) + { + for(int j = 0; j < r.getAttributeByName(a1.getName()).getValues().size(); ++j) + { + if(stoi(r.getAttributeByName(a1.getName()).getValues()[j]) < stoi(c)) + { + rfinal.removeTuple(j - offset); + offset += 1; + } + } + } + } + } + else + { + cout << "Attribute type is not an INTEGER." << endl; + exit(1); + } + } + else if(op == "<=") + { + if(r.getAttributeByName(a1.getName()).getType() == "INTEGER") + { + for(int i = 0; i < r.getAttributes().size(); ++i) + { + if(r.getAttributes()[i].getName() == a1.getName()) + { + for(int j = 0; j < r.getAttributeByName(a1.getName()).getValues().size(); ++j) + { + if(stoi(r.getAttributeByName(a1.getName()).getValues()[j]) > stoi(c)) + { + rfinal.removeTuple(j - offset); + offset += 1; + } + } + } + } + } + else + { + cout << "Attribute type is not an INTEGER." << endl; + exit(1); + } + } + else if(op == ">") + { + + if(r.getAttributeByName(a1.getName()).getType() == "INTEGER") + { + for(int i = 0; i < r.getAttributes().size(); ++i) + { + if(r.getAttributes()[i].getName() == a1.getName()) + { + for(int j = 0; j < r.getAttributeByName(a1.getName()).getValues().size(); ++j) + { + if(stoi(r.getAttributeByName(a1.getName()).getValues()[j]) <= stoi(c)) + { + rfinal.removeTuple(j - offset); + offset += 1; + } + } + } + } + } + else + { + cout << "Attribute type is not an INTEGER." << endl; + exit(1); + } + } + else if(op == "<") + { + + if(r.getAttributeByName(a1.getName()).getType() == "INTEGER") + { + for(int i = 0; i < r.getAttributes().size(); ++i) + { + if(r.getAttributes()[i].getName() == a1.getName()) + { + for(int j = 0; j < r.getAttributeByName(a1.getName()).getValues().size(); ++j) + { + if(stoi(r.getAttributeByName(a1.getName()).getValues()[j]) >= stoi(c)) + { + rfinal.removeTuple(j - offset); + offset += 1; + } + } + } + } + } + else + { + cout << "Attribute type is not an INTEGER." << endl; + exit(1); + } + } } + if(input[0] == "&&") + { + input.erase(input.begin()); + Relation rtemp = rfinal; + rfinal = condition(input, rtemp, engine); + } + else if(input[0] == "||") + { + input.erase(input.begin()); + Relation rtemp = rfinal; + Relation rtemp2 = condition(input, r, engine); + rfinal = engine.setUnion(rtemp, rtemp2); + } + return rfinal; } tuple, Relation> expression(vector input, DBEngine &engine) @@ -372,10 +317,6 @@ tuple, Relation> expression(vector input, DBEngine &engin tuple, Relation> t(input, rfinal); if(input[0] == "select") { - /* - cout << "Not yet implemented." << endl; - exit(1); - */ input.erase(input.begin()); vector s; Relation r("TEMP"); @@ -390,13 +331,13 @@ tuple, Relation> expression(vector input, DBEngine &engin input.erase(input.begin()); if(engine.isRelation(input[0])) { - r = condition(s, engine.getTableFromName(input[0])); + r = condition(s, engine.getTableFromName(input[0]), engine); input.erase(input.begin()); } else if(input[0] == "(") { tuple, Relation> t = expression(input, engine); - r = condition(s, get<1>(t)); + r = condition(s, get<1>(t), engine); input.erase(input.begin()); } } @@ -425,16 +366,13 @@ tuple, Relation> expression(vector input, DBEngine &engin input.erase(input.begin()); get<0>(t) = input; get<1>(t) = rfinal; - //cout << rfinal.getSize() << endl; return t; } else if(input[0] == "(") { t = expression(input, engine); rfinal = engine.projection(temp, get<1>(t)); - //get<0>(t) = input; get<1>(t) = rfinal; - //cout << rfinal.getSize() << endl; return t; } } @@ -642,12 +580,6 @@ tuple, Relation> expression(vector input, DBEngine &engin vector showCMD(vector input, DBEngine &engine) { - /* - if (input.size() > 3) - { - cout<<"Syntax error!"< saveCMD(vector input, DBEngine &engine) { cout<<"Syntax error!"< att = r.getAttributes(); - for (int i = 0; i < att.size(); ++i) - { - output << "-------------\n"; - output << att[i].getName() << "\n" << att[i].getType(); - if(att[i].getType() == "VARCHAR") - { - output << "(" << att[i].getSize() << ")"; - } - output << "\n\n"; - - vector values = att[i].getValues(); - vector::iterator it = values.begin(); - while (it != values.end()) - { - output << *it << "\n"; - it++; - } - output << "-------------\n"; - } - output << "\n--------------------------"; - */ input.erase(input.begin()); return input; @@ -716,10 +614,6 @@ vector closeCMD(vector input, DBEngine &engine) { cout<<"Syntax error!"< openCMD(vector input, DBEngine &engine) { cout<<"Syntax error!"< exitCMD(vector input, DBEngine &engine) vector createCMD(vector input, DBEngine &engine) { - //relation name will be the first element of the vector of data returned by this function if (input[0] == "TABLE") { @@ -775,8 +664,6 @@ vector createCMD(vector input, DBEngine &engine) { input.erase(input.begin()); - //vector e1; - vector a; while(input[0] != ")") //inserting all values to relation @@ -807,8 +694,6 @@ vector createCMD(vector input, DBEngine &engine) a.push_back(temp); } - //vector apk; //save primary keys temp storage - if(input[0] == "PRIMARY" && input[1] == "KEY") { input.erase(input.begin()); @@ -819,17 +704,12 @@ vector createCMD(vector input, DBEngine &engine) while(input[0] != ")") //inserting all values to relation { - //PAttribute temp; if (input[0] == ",") { input.erase(input.begin()); } - //temp.setPAttributeName(input[0]); - - //apk.push_back(temp); - for(int i = 0; i < a.size(); ++i) { if(input[0] == a[i].getPAttribute()) @@ -917,7 +797,6 @@ vector insertCMD(vector input, DBEngine &engine) if(input[0].at(0) == '\"') { s.push_back(input[0].substr(1,input[0].find_last_of("\"") - 1 )); - //engine.getTableFromName(pr.getName()).getAttributes()[i].display(); input.erase(input.begin()); } else @@ -996,14 +875,18 @@ vector insertCMD(vector input, DBEngine &engine) vector updateCMD(vector input, DBEngine &engine) { - PRelation r(input[0]); + Relation r = engine.getTableFromName(input[0]); + Relation rcond("TEMP"); + Relation rfinal("TEMP"); input.erase(input.begin()); if(input[0] == "SET") { input.erase(input.begin()); + vector a = r.getAttributes(); + //parse out ( and send everything until ) into an Expression vector if(input[0] == "(") { @@ -1020,8 +903,6 @@ vector updateCMD(vector input, DBEngine &engine) while(input[0] != ")") { temp.setPAttributeName(input[0]); - a.push_back(temp); - temp.setPAttributeName("~"); input.erase(input.begin()); @@ -1030,6 +911,15 @@ vector updateCMD(vector input, DBEngine &engine) input.erase(input.begin()); s.push_back(input[0]); + + if(input[0].at(0) == '\"') + { + s.push_back(input[0].substr(1, input[0].find_last_of("\""))); + } + else + { + s.push_back(input[0]); + } } else @@ -1041,34 +931,27 @@ vector updateCMD(vector input, DBEngine &engine) { input.erase(input.begin()); } + + a.push_back(temp); + temp.setPAttributeName("~"); } + } if(input[0] == "WHERE") { + vector s; if(input[0] == "(") { - //PCondition c; - - PComparison c; - POperand oops1; - POperand oops2; - POp op; - + input.erase(input.begin()); while(input[0] != ")") { - oops1.setPOperand(input[0]); + s.push_back(input[0]); input.erase(input.begin()); - - oops2.setPOperand(input[0]); - input.erase(input.begin()); - - op.setPOp(input[0]); - input.erase(input.begin()); - - c.setPComparison(oops1.getPOperand(), op.getPOp(), oops2.getPOperand()); } + rcond = condition(s, r, engine); } + } // send update command to DBEngine @@ -1128,7 +1011,6 @@ vector query(vector input, DBEngine &engine) tuple, Relation> t = expression(input, engine); Relation r = get<1>(t); r.setTableName(pr.getName()); - //r.display(); input = get<0>(t); engine.createTable(r); @@ -1157,8 +1039,6 @@ void par_line(vector input, DBEngine &engine) //calls par_command() or p cout<<"\nPassing the following arguments to dbEngine: \nCommand: "< insertInput = insertCMD(input, engine); - //cout<<"arguments: "< input, DBEngine &engine) //calls par_command() or p input.erase(input.begin()); vector insertInput = createCMD(input, engine); - //cout<<"arguments: "< input, DBEngine &engine) //calls par_command() or p input.erase(input.begin()); vector insertInput = deleteCMD(input, engine); - //cout<<"arguments: "< input, DBEngine &engine) //calls par_command() or p input.erase(input.begin()); vector insertInput = updateCMD(input, engine); - //cout<<"arguments: "< listOfTokens = tokenize(input); par_line(listOfTokens, engine); } -/* -int main () { - - - string ss = "INSERT INTO animals VALUES FROM ( Joe , cat , 4 ) ;"; - string ss2 = "SHOW Dogs ;"; - string ss3 = "EXIT ; "; - - vector listOfTokens = tokenize(ss); - vector listOfTokens2 = tokenize(ss2); - vector listOfTokens3 = tokenize(ss3); - - par_line(listOfTokens); - par_line(listOfTokens2); - par_line(listOfTokens3); - - -} -*/ diff --git a/Parser.h b/Parser.h index e6422ca..08f37da 100644 --- a/Parser.h +++ b/Parser.h @@ -416,493 +416,4 @@ class PExpression } }; -/* -vector tokenize(string ss) -{ - - string tempString; - stringstream lineStream(ss); - vector output; - - while (lineStream >> tempString) - { - output.push_back(tempString); - } - - //testing--------------- - cout<<"TokenList: "; - - for (int i = 0; i input) -{ - cout<<"TokenList: "< showCMD(vector input) -{ - if (input.size() > 3) - { - cout<<"Syntax error!"< saveCMD(vector input) -{ - if (input.size() > 3) - { - cout<<"Syntax error!"< closeCMD(vector input) -{ - if (input.size() > 3) - { - cout<<"Syntax error!"< openCMD(vector input) -{ - if (input.size() > 2) - { - cout<<"Syntax error!"< exitCMD(vector input) -{ - if (input[1] != ";") - { - cout<<"ERROR: missing semicolon!"< createCMD(vector input) -{ - //relation name will be the first element of the vector of data returned by this function - - if (input[0] == "CREATE" && input[1] == "TABLE") - { - input.erase(input.begin()); - input.erase(input.begin()); - - PRelation r; - r.setPRelation(input[0]); - - input.erase(input.begin()); - - if(input[0] == "(") - { - input.erase(input.begin()); - - //vector e1; - - vector a; - - while(input[0] != ")") //inserting all values to relation - { - PAttribute temp; - - if (input[0] == ",") - { - input.erase(input.begin()); - } - - temp.setPAttributeName(input[0]); - - input.erase(input.begin()); - - if(input[0] == "INTEGER") - { - temp.setPAttributeType(input[0]); - input.erase(input.begin()); - } - else - { - temp.setPAttributeType(input[0].substr(0,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()); - input.erase(input.begin()); - - if(input[0] == "(") - { - - while(input[0] != ")") //inserting all values to relation - { - PAttribute temp; - - if (input[0] == ",") - { - input.erase(input.begin()); - } - - temp.setPAttributeName(input[0]); - - apk.push_back(temp); - - input.erase(input.begin()); - } - - - - return input; - } - } - } - - else cout<<"Syntax error!"< insertCMD(vector input) -{ - //relation name will be the first element of the vector of data returned by this function - - if (input[0] == "INTO") - { - input.erase(input.begin()); - - PRelation r(input[0]); - - input.erase(input.begin()); - - vector s; - - if (input[0] == "VALUES" && input[1] == "FROM") - { - input.erase(input.begin()); - input.erase(input.begin()); - - - if(input[0] == "(") - { - if(input[0].at(0) == '\"') - { - s.push_back(input[0].substr(1,input[0].find_last_of("\""))); - } - vector e; - input.erase(input.begin()); - - while(input[0] != ")") //inserting all values to relation - //for (int i = 0; i < 2; ++i) - { - if (input[0] == ",") input.erase(input.begin()); - - e.push_back(input[0]); - - input.erase(input.begin()); - } - - cout << "Inserting: "; - while(!e.empty()) - { - cout << e[0].getPExpression() << " "; - e.erase(e.begin()); - } - cout << "into " << r.getName() << ".\n"; - - return input; - - } - - else if (input[0] == "RELATION") - { - input.erase(input.begin()); - - PExpression e; - - while(input[0] != ";") - { - e.setPExpression(e.getPExpression() + input[0]); - } - - cout << "Inserting: " << e.getPExpression() << " into " << r.getName() << ".\n"; - - return input; - } - - else cout<<"Syntax error!"< updateCMD(vector input) -{ - PRelation r(input[0]); - - input.erase(input.begin()); - - if(input[0] == "SET") - { - input.erase(input.begin()); - - //parse out ( and send everything until ) into an Expression vector - if(input[0] == "(") - { - - vector a; - PAttribute temp; - - vector s; - - //vector e; - - input.erase(input.begin()); - - while(input[0] != ")") - { - temp.setPAttributeName(input[0]); - a.push_back(temp); - temp.setPAttributeName("~"); - - input.erase(input.begin()); - - if(input[0] == "=") - { - input.erase(input.begin()); - - s.push_back(input[0]); - } - - else - { - cout<<"Syntax error!"< deleteCMD(vector input) -{ - if (input[0] == "DELETE" && input[1] == "FROM") - { - input.erase(input.begin()); - input.erase(input.begin()); - - PRelation r(input[0]); - - if(input[0] == "WHERE") - { - if(input[0] == "(") - { - //PCondition c; - - PComparison c; - POperand oops1; - POperand oops2; - POp op; - - while(input[0] != ")") - { - oops1.setPOperand(input[0]); - input.erase(input.begin()); - - oops2.setPOperand(input[0]); - input.erase(input.begin()); - - op.setPOp(input[0]); - input.erase(input.begin()); - - c.setPComparison(oops1.getPOperand(), op.getPOp(), oops2.getPOperand()); - } - } - } - - // send delete command to DBEngine - } - else cout<<"Syntax error!"< input) //calls par_command() or par_query() depending on first item from token list -{ -/* -• Match the first item in the token list and determine weather this is a command or a query. -• Call functions par_command() or par_query(); -• After either par_command() or par_query() returns, make sure the line ends properly with “;” token - - string tempChar = input.back(); - - if (tempChar != ";") - { - cout<<"ERROR! missing semicolon "< insertInput = insertCMD(input); - cout<<"arguments: "< insertInput = createCMD(input); - cout<<"arguments: "< insertInput = deleteCMD(input); - cout<<"arguments: "< insertInput = updateCMD(input); - cout<<"arguments: "< listOfTokens = tokenize(input); - par_line(listOfTokens); -} -*/ - void parse(string s, DBEngine &e); \ No newline at end of file diff --git a/Relation.cpp b/Relation.cpp index bf32b20..18a1277 100755 --- a/Relation.cpp +++ b/Relation.cpp @@ -92,8 +92,6 @@ void Relation::display(){ } void Relation::insertTuple(vector tuple){ - cout << name << " " << size << endl; - cout << tuple.size() << endl; if (tuple.size() != this->size) { cout << "Failure to insert: the sizes do not match."; } diff --git a/test b/test index 9b3ff7f..c4326f6 100755 Binary files a/test and b/test differ diff --git a/test.cpp b/test.cpp index 82732f7..0e22c79 100755 --- a/test.cpp +++ b/test.cpp @@ -7,7 +7,7 @@ using namespace std; int main () { - DBEngine engine; + DBEngine engine; Attribute att1("Breakfast", "VARCHAR(20)", true); Attribute att2("Lunch", "VARCHAR(20)", false); @@ -32,7 +32,7 @@ int main () { //engine.update - /*actual testing + /*actual testing string x; cout << "Enter DBMS Commands: ";