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++;
}
void Attribute::removeCell(int index){
values.erase(values.begin() + index);
size--;
}
string Attribute::operator[](int i){
return values[i];
}
@ -61,3 +66,7 @@ void Attribute::display(){
cout << "-------------\n";
}
void Attribute::clearAllValues(){
values.clear();
}

View file

@ -1,3 +1,4 @@
#pragma once
#include <iostream>
#include <vector>
@ -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<string> getValues();
string getName();
@ -22,4 +24,5 @@ public:
bool isKey();
int getSize();
void display();
void clearAllValues();
};

View file

@ -1,13 +1,7 @@
#include <iostream>
#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);
};
//currently only implementing for comparison
Relation equality(string attName, string s, Relation r);

View file

@ -45,6 +45,10 @@ vector<Relation> 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<string> 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<string> result_tuple;
return temp;
=======
>>>>>>> master
}
//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){
@ -126,6 +139,44 @@ void DBEngine::rename(Relation& r, vector<string> oldnames, vector<string> newna
else {
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> 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
Relation new_r("TEMP", new_atts);
<<<<<<< HEAD
return new_r;
}
}*/
=======
return new_r;*/
}
}
>>>>>>> master

View file

@ -23,9 +23,13 @@ public:
Relation projection(vector<string> input, Relation r);
Relation product(string s1, Relation r1, Relation r2);
void rename(Relation& r, vector<string> oldnames, vector<string> 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();
};

View file

@ -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<string> tokenize(string ss)
@ -880,3 +907,5 @@ void parse(string input, DBEngine &engine)
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:
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();
}
void Relation::insertAttributes(vector<Attribute> 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<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(){
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 <vector>
#include "Attribute.h"
@ -10,7 +11,10 @@ class Relation{
public:
Relation(string n);
Relation(string n, vector<Attribute> a);
void insertAttributes(vector<Attribute> a);
string getTableName();
Attribute operator[](int i);
vector<string> getTuple(int index);
vector<Attribute> getAttributes();
vector<string> getAttributeNames();
Attribute& getAttributeByName(string s);
@ -19,5 +23,5 @@ public:
void display();
void insertTuple(vector<string> tuple); //assuming they are in order
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 <vector>
<<<<<<< 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<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
}