Fixing commit issues

This commit is contained in:
Alexander Huddleston 2015-09-26 23:24:24 -05:00
parent d32864988f
commit b4c4dfd448
11 changed files with 183 additions and 11 deletions

View file

@ -21,6 +21,11 @@ void Attribute::addCell(string v){
size++; size++;
} }
void Attribute::removeCell(int index){
values.erase(values.begin() + index);
size--;
}
string Attribute::operator[](int i){ string Attribute::operator[](int i){
return values[i]; return values[i];
} }
@ -60,4 +65,8 @@ void Attribute::display(){
} }
cout << "-------------\n"; cout << "-------------\n";
}
void Attribute::clearAllValues(){
values.clear();
} }

View file

@ -1,3 +1,4 @@
#pragma once
#include <iostream> #include <iostream>
#include <vector> #include <vector>
@ -14,6 +15,7 @@ public:
Attribute(); Attribute();
Attribute(string n, string t, bool k); Attribute(string n, string t, bool k);
void addCell(string v); void addCell(string v);
void removeCell(int index);
string operator[](int i); string operator[](int i);
vector<string> getValues(); vector<string> getValues();
string getName(); string getName();
@ -22,4 +24,5 @@ public:
bool isKey(); bool isKey();
int getSize(); int getSize();
void display(); void display();
void clearAllValues();
}; };

View file

@ -1,13 +1,7 @@
#include <iostream> #pragma once
#include "Attribute.h" #include "Relation.h"
using namespace std; using namespace std;
class Condition{ //currently only implementing for comparison
Attribute att; Relation equality(string attName, string s, Relation r);
public:
//currently only implemented for comparison
Condition(Attribute a);
Condition(Attribute a);
};

View file

@ -45,6 +45,10 @@ vector<Relation> DBEngine::getRelations(){
return tables; return tables;
} }
<<<<<<< HEAD
=======
>>>>>>> master
Relation& DBEngine::getTableFromName(string n){ Relation& DBEngine::getTableFromName(string n){
for(int i = 0; i < tables.size(); i++){ for(int i = 0; i < tables.size(); i++){
if (tables[i].getTableName() == n){ 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){ Relation DBEngine::selection(string attName, string s, Relation r){
equality(attName, s, r); equality(attName, s, r);
} }
@ -73,6 +82,7 @@ Relation DBEngine::projection(vector<string> input, Relation r){
Relation temp(new_name, v); Relation temp(new_name, v);
return temp; return temp;
<<<<<<< HEAD
} }
Relation DBEngine::product(string new_name, Relation r1, Relation r2){ 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<string> result_tuple; vector<string> result_tuple;
return temp; return temp;
=======
>>>>>>> master
} }
//test error matching //test error matching
@ -116,6 +128,7 @@ void DBEngine::rename(Relation& r, vector<string> oldnames, vector<string> newna
} }
} }
<<<<<<< HEAD
/*Relation DBEngine::setUnion(Relation r1, Relation r2){ /*Relation DBEngine::setUnion(Relation r1, Relation r2){
@ -126,6 +139,44 @@ void DBEngine::rename(Relation& r, vector<string> oldnames, vector<string> newna
else { else {
vector<Attribute> r1_atts = r1.getAttributes(); vector<Attribute> 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<string> 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<Attribute> r1_atts = r1.getAttributes();
>>>>>>> master
vector<Attribute> r2_atts = r2.getAttributes(); vector<Attribute> r2_atts = r2.getAttributes();
vector<Attribute> new_atts = r1_atts; vector<Attribute> new_atts = r1_atts;
@ -146,6 +197,12 @@ void DBEngine::rename(Relation& r, vector<string> oldnames, vector<string> newna
//currently all returned relations are called TEMP //currently all returned relations are called TEMP
Relation new_r("TEMP", new_atts); Relation new_r("TEMP", new_atts);
<<<<<<< HEAD
return new_r; return new_r;
} }
}*/ }*/
=======
return new_r;*/
}
}
>>>>>>> master

View file

@ -23,9 +23,13 @@ public:
Relation projection(vector<string> input, Relation r); Relation projection(vector<string> input, Relation r);
Relation product(string s1, Relation r1, Relation r2); Relation product(string s1, Relation r1, Relation r2);
void rename(Relation& r, vector<string> oldnames, vector<string> newnames); void rename(Relation& r, vector<string> oldnames, vector<string> newnames);
<<<<<<< HEAD
void save(); void save();
void storeCommands(string s); void storeCommands(string s);
//Relation setUnion(Relation r1, Relation r2); //Relation setUnion(Relation r1, Relation r2);
=======
Relation setUnion(Relation r1, Relation r2);
>>>>>>> master
//void setDiff(); //void setDiff();
//void crossProduct(); //void crossProduct();
}; };

View file

@ -7,6 +7,10 @@
using namespace std; using namespace std;
<<<<<<< HEAD
=======
>>>>>>> master
class PRelation class PRelation
{ {
string name; string name;
@ -262,6 +266,15 @@ class PComparison
public: public:
PComparison() PComparison()
<<<<<<< HEAD
{
op.setPOp("~");
operand1.setPOperand("~");
operand2.setPOperand("~");
}
PComparison(string str1, string str2, string str3)
=======
{ {
op.setPOp("~"); op.setPOp("~");
operand1.setPOperand("~"); operand1.setPOperand("~");
@ -276,6 +289,15 @@ class PComparison
} }
void setPComparison(string str1, string str2, string str3) 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); operand1.setPOperand(str1);
op.setPOp(str2); op.setPOp(str2);
@ -284,6 +306,10 @@ class PComparison
string getPComparison() string getPComparison()
{ {
=======
string getPComparison()
{
>>>>>>> master
return operand1.getPOperand() + " " + op.getPOp() + " " + operand2.getPOperand(); return operand1.getPOperand() + " " + op.getPOp() + " " + operand2.getPOperand();
} }
}; };
@ -391,6 +417,7 @@ class PExpression
return temp; return temp;
} }
}; };
<<<<<<< HEAD
vector<string> tokenize(string ss) vector<string> tokenize(string ss)
@ -880,3 +907,5 @@ void parse(string input, DBEngine &engine)
par_line(listOfTokens); par_line(listOfTokens);
} }
=======
>>>>>>> master

View file

@ -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: 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 git remote set-url origin https://github.tamu.edu/USERNAME/DMS.git

View file

@ -13,10 +13,30 @@ Relation::Relation(string n, vector<Attribute> a){
size = a.size(); size = a.size();
} }
void Relation::insertAttributes(vector<Attribute> a){
for (int i = 0; i < a.size(); ++i){
att.push_back(a[i]);
}
}
string Relation::getTableName(){ string Relation::getTableName(){
return name; return name;
} }
Attribute Relation::operator[](int i){
return att[i];
}
vector<string> Relation::getTuple(int index){
vector<string> temp;
for (int i = 0; i < att.size(); ++i){
temp.push_back(att[i][index]);
}
return temp;
}
vector<Attribute> Relation::getAttributes(){ vector<Attribute> Relation::getAttributes(){
return att; 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);
}
}
}

View file

@ -1,3 +1,4 @@
#pragma once
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include "Attribute.h" #include "Attribute.h"
@ -10,7 +11,10 @@ class Relation{
public: public:
Relation(string n); Relation(string n);
Relation(string n, vector<Attribute> a); Relation(string n, vector<Attribute> a);
void insertAttributes(vector<Attribute> a);
string getTableName(); string getTableName();
Attribute operator[](int i);
vector<string> getTuple(int index);
vector<Attribute> getAttributes(); vector<Attribute> getAttributes();
vector<string> getAttributeNames(); vector<string> getAttributeNames();
Attribute& getAttributeByName(string s); Attribute& getAttributeByName(string s);
@ -19,5 +23,5 @@ public:
void display(); void display();
void insertTuple(vector<string> tuple); //assuming they are in order void insertTuple(vector<string> tuple); //assuming they are in order
void insertFromRelation(Relation r); void insertFromRelation(Relation r);
//void removeTuple(); void removeTuple(int index);
}; };

BIN
a.out

Binary file not shown.

View file

@ -1,6 +1,10 @@
#include <iostream> #include <iostream>
#include <vector> #include <vector>
<<<<<<< HEAD
#include "Parserv3.h" #include "Parserv3.h"
=======
#include "Condition.h"
>>>>>>> master
#include "DBEngine.h" #include "DBEngine.h"
using namespace std; using namespace std;
@ -28,6 +32,7 @@ int main() {
v.push_back(att2); v.push_back(att2);
v.push_back(att3); v.push_back(att3);
<<<<<<< HEAD
Relation r("Food", v); Relation r("Food", v);
//r.renameAttribute("Breakfast", "BFST"); //r.renameAttribute("Breakfast", "BFST");
//r.display(); //r.display();
@ -93,4 +98,30 @@ int main () {
engine.save(); 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<Attribute> 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
} }