diff --git a/Attribute.cpp b/Attribute.cpp index eb35167..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]; } @@ -60,4 +65,8 @@ void Attribute::display(){ } cout << "-------------\n"; +} + +void Attribute::clearAllValues(){ + values.clear(); } \ No newline at end of file diff --git a/Attribute.h b/Attribute.h index 0e92a40..9bb84fd 100755 --- a/Attribute.h +++ b/Attribute.h @@ -1,3 +1,4 @@ +#pragma once #include #include @@ -14,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(); @@ -22,4 +24,5 @@ public: bool isKey(); int getSize(); void display(); + void clearAllValues(); }; \ No newline at end of file diff --git a/Condition.h b/Condition.h index cc06978..51c031e 100755 --- a/Condition.h +++ b/Condition.h @@ -1,13 +1,7 @@ -#include -#include "Attribute.h" +#pragma once +#include "Relation.h" using namespace std; -class Condition{ - Attribute att; - -public: - //currently only implemented for comparison - Condition(Attribute a); - Condition(Attribute a); -}; \ No newline at end of file +//currently only implementing for comparison +Relation equality(string attName, string s, Relation r); diff --git a/DBEngine.cpp b/DBEngine.cpp index 26e15f2..21ba967 100755 --- a/DBEngine.cpp +++ b/DBEngine.cpp @@ -45,6 +45,10 @@ vector DBEngine::getRelations(){ return tables; } +<<<<<<< HEAD +======= + +>>>>>>> master Relation& DBEngine::getTableFromName(string n){ for(int i = 0; i < tables.size(); i++){ if (tables[i].getTableName() == n){ @@ -53,6 +57,11 @@ Relation& DBEngine::getTableFromName(string n){ } } +Relation DBEngine::selection(string attName, string s, Relation r){ + equality(attName, s, r); +} + + Relation DBEngine::selection(string attName, string s, Relation r){ equality(attName, s, r); } @@ -73,6 +82,7 @@ Relation DBEngine::projection(vector input, Relation r){ Relation temp(new_name, v); return temp; +<<<<<<< HEAD } Relation DBEngine::product(string new_name, Relation r1, Relation r2){ @@ -95,6 +105,8 @@ Relation DBEngine::product(string new_name, Relation r1, Relation r2){ vector result_tuple; return temp; +======= +>>>>>>> master } //test error matching @@ -116,6 +128,7 @@ void DBEngine::rename(Relation& r, vector oldnames, vector newna } } +<<<<<<< HEAD /*Relation DBEngine::setUnion(Relation r1, Relation r2){ @@ -126,6 +139,44 @@ void DBEngine::rename(Relation& r, vector oldnames, vector newna else { vector r1_atts = r1.getAttributes(); +======= +Relation DBEngine::setUnion(Relation r1, Relation r2){ + if (r1.getAttributeNames() != r2.getAttributeNames()){ + cout << "Failure to union: the relations are not union-compatible.\nreturning the first relation.\n"; + return r1; + } + + else { + //currently all returned relations are called TEMP + Relation new_r = r1; + vector temp; + bool duplicate = false; + + for (int i = 0; i < r2.getAttributes()[0].getSize(); ++i) { + temp = r2.getTuple(i); + + for (int j = 0; j < new_r.getAttributes()[0].getSize(); ++j){ + if (temp == new_r.getTuple(j)){ + duplicate = true; + break; + } + } + + if (!duplicate) { + new_r.insertTuple(temp); + } + + duplicate = false; + } + + return new_r; + + + + + + /*vector r1_atts = r1.getAttributes(); +>>>>>>> master vector r2_atts = r2.getAttributes(); vector new_atts = r1_atts; @@ -146,6 +197,12 @@ void DBEngine::rename(Relation& r, vector oldnames, vector newna //currently all returned relations are called TEMP Relation new_r("TEMP", new_atts); +<<<<<<< HEAD return new_r; } }*/ +======= + return new_r;*/ + } +} +>>>>>>> master diff --git a/DBEngine.h b/DBEngine.h index d5ae85a..ce1702c 100755 --- a/DBEngine.h +++ b/DBEngine.h @@ -23,9 +23,13 @@ public: Relation projection(vector input, Relation r); Relation product(string s1, Relation r1, Relation r2); void rename(Relation& r, vector oldnames, vector newnames); +<<<<<<< HEAD void save(); void storeCommands(string s); //Relation setUnion(Relation r1, Relation r2); +======= + Relation setUnion(Relation r1, Relation r2); +>>>>>>> master //void setDiff(); //void crossProduct(); }; diff --git a/Parserv3.h b/Parserv3.h index dea692c..0ddb5a7 100644 --- a/Parserv3.h +++ b/Parserv3.h @@ -7,6 +7,10 @@ using namespace std; +<<<<<<< HEAD +======= + +>>>>>>> master class PRelation { string name; @@ -262,6 +266,15 @@ class PComparison public: PComparison() +<<<<<<< HEAD + { + op.setPOp("~"); + operand1.setPOperand("~"); + operand2.setPOperand("~"); + } + + PComparison(string str1, string str2, string str3) +======= { op.setPOp("~"); operand1.setPOperand("~"); @@ -276,6 +289,15 @@ class PComparison } void setPComparison(string str1, string str2, string str3) +>>>>>>> master + { + operand1.setPOperand(str1); + op.setPOp(str2); + operand2.setPOperand(str3); + } + +<<<<<<< HEAD + void setPComparison(string str1, string str2, string str3) { operand1.setPOperand(str1); op.setPOp(str2); @@ -284,6 +306,10 @@ class PComparison string getPComparison() { +======= + string getPComparison() + { +>>>>>>> master return operand1.getPOperand() + " " + op.getPOp() + " " + operand2.getPOperand(); } }; @@ -391,6 +417,7 @@ class PExpression return temp; } }; +<<<<<<< HEAD vector tokenize(string ss) @@ -880,3 +907,5 @@ void parse(string input, DBEngine &engine) par_line(listOfTokens); } +======= +>>>>>>> master 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 diff --git a/Relation.cpp b/Relation.cpp index f81adee..86a6dad 100755 --- a/Relation.cpp +++ b/Relation.cpp @@ -13,10 +13,30 @@ Relation::Relation(string n, vector a){ size = a.size(); } +void Relation::insertAttributes(vector a){ + for (int i = 0; i < a.size(); ++i){ + att.push_back(a[i]); + } +} + string Relation::getTableName(){ return name; } +Attribute Relation::operator[](int i){ + return att[i]; +} + +vector Relation::getTuple(int index){ + vector temp; + + for (int i = 0; i < att.size(); ++i){ + temp.push_back(att[i][index]); + } + + return temp; +} + vector Relation::getAttributes(){ return att; } @@ -90,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 faa89ea..2a8846c 100755 --- a/Relation.h +++ b/Relation.h @@ -1,3 +1,4 @@ +#pragma once #include #include #include "Attribute.h" @@ -10,7 +11,10 @@ class Relation{ public: Relation(string n); Relation(string n, vector a); + void insertAttributes(vector a); string getTableName(); + Attribute operator[](int i); + vector getTuple(int index); vector getAttributes(); vector getAttributeNames(); Attribute& getAttributeByName(string s); @@ -19,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 deleted file mode 100755 index 6a77a3d..0000000 Binary files a/a.out and /dev/null differ diff --git a/test.cpp b/test.cpp index 0d7ee26..8ff77f2 100755 --- a/test.cpp +++ b/test.cpp @@ -1,6 +1,10 @@ #include #include +<<<<<<< HEAD #include "Parserv3.h" +======= +#include "Condition.h" +>>>>>>> master #include "DBEngine.h" using namespace std; @@ -28,6 +32,7 @@ int main() { v.push_back(att2); v.push_back(att3); +<<<<<<< HEAD Relation r("Food", v); //r.renameAttribute("Breakfast", "BFST"); //r.display(); @@ -93,4 +98,30 @@ int main () { engine.save(); +======= + engine.createTable("Food", v); + + Attribute att4("Breakfast", "VARCHAR(20)", true); + Attribute att5("Lunch", "VARCHAR(20)", false); + Attribute att6("Dinner", "VARCHAR(20)", false); + + att4.addCell("Pancakes"); + att4.addCell("Bacon"); + att4.addCell("Eggs"); + att5.addCell("Turkey Sandwich"); + att5.addCell("Pasta Salad"); + att5.addCell("Taco"); + att6.addCell("Steak"); + att6.addCell("Fajitas"); + att6.addCell("Spaghetti"); + + vector v2; + v2.push_back(att4); + v2.push_back(att5); + v2.push_back(att6); + + engine.createTable("MoarFood", v2); + + engine.setUnion(engine.getTableFromName("Food"), engine.getTableFromName("MoarFood")).display(); +>>>>>>> master }