update works

This commit is contained in:
Rebecca Schofield 2015-10-05 16:50:19 -05:00
parent 909df70f2d
commit 20fec486b6
6 changed files with 35 additions and 28 deletions

View file

@ -52,8 +52,7 @@ void Attribute::setName(string s){
name = s; name = s;
} }
void Attribute::setValue(string s, int index) void Attribute::setValue(string s, int index) {
{
values[index] = s; values[index] = s;
} }
@ -89,4 +88,5 @@ void Attribute::display(){
void Attribute::clearAllValues(){ void Attribute::clearAllValues(){
values.clear(); values.clear();
size = 0;
} }

View file

@ -291,20 +291,30 @@ Relation DBEngine::crossProduct(Relation r1, Relation r2){
//WHERE Name = Joseph Lieberman //WHERE Name = Joseph Lieberman
Relation DBEngine::updateCmd(Relation r, string attNameSet, string attSet, string attNameWhere, string attWhere){ Relation DBEngine::updateCmd(Relation r, string attNameSet, string attSet, string attNameWhere, string attWhere){
Relation temp = selection(attNameWhere, attWhere, r); //brute forcing this, sorry universe
vector<Attribute> atts = temp.getAttributes(); //add error matching!!
vector<int> inds;
for (int i = 0; i < r.getSize(); ++i){
if (r[i].getName() == attNameWhere){
for (int j = 0; j < r[i].getSize(); ++j){
if (r[i][j] == attWhere){
inds.push_back(j);
}
}
}
}
vector<Attribute> atts = r.getAttributes();
for (int i = 0; i < atts.size(); ++i){ for (int i = 0; i < atts.size(); ++i){
if (atts[i].getName() == attNameSet){ if (atts[i].getName() == attNameSet){
for (int j = 0; j < atts[i].getSize(); ++j){ for (int j = 0; j < inds.size(); ++j){
atts[i]setValue(attSet, j); atts[i].setValue(attSet, inds[j]);
} }
break;
} }
} }
//currently returns a relation with just the changed values, need to look at proper join r.setAttributes(atts);
//if proper join does not work, plan B is brute force return r;
return temp;
} }

View file

@ -45,6 +45,11 @@ vector<Attribute> Relation::getAttributes(){
return att; return att;
} }
void Relation::setAttributes(vector<Attribute> v){
size = v.size();
att = v;
}
vector<string> Relation::getAttributeNames(){ vector<string> Relation::getAttributeNames(){
vector<string> temp; vector<string> temp;
for(int i = 0; i < size; ++i){ for(int i = 0; i < size; ++i){

View file

@ -17,6 +17,7 @@ public:
Attribute operator[](int i); Attribute operator[](int i);
vector<string> getTuple(int index); vector<string> getTuple(int index);
vector<Attribute> getAttributes(); vector<Attribute> getAttributes();
void setAttributes(vector<Attribute> v);
vector<string> getAttributeNames(); vector<string> getAttributeNames();
Attribute& getAttributeByName(string s); Attribute& getAttributeByName(string s);
bool isAttribute(string s); bool isAttribute(string s);

BIN
a.out Executable file

Binary file not shown.

View file

@ -17,12 +17,15 @@ int main () {
att1.addCell("Pancakes"); att1.addCell("Pancakes");
att1.addCell("Waffles"); att1.addCell("Waffles");
att1.addCell("Biscuits"); att1.addCell("Biscuits");
att1.addCell("Pancakes");
att2.addCell("Turkey Sandwich"); att2.addCell("Turkey Sandwich");
att2.addCell("Caesar Salad"); att2.addCell("Caesar Salad");
att2.addCell("Pizza"); att2.addCell("Pizza");
att2.addCell("Sushi");
att3.addCell("Steak"); att3.addCell("Steak");
att3.addCell("Shrimp"); att3.addCell("Shrimp");
att3.addCell("Ribs"); att3.addCell("Ribs");
att3.addCell("Lasagna");
vector<Attribute> v; vector<Attribute> v;
v.push_back(att1); v.push_back(att1);
@ -30,18 +33,6 @@ int main () {
v.push_back(att3); v.push_back(att3);
engine.createTable("Food", v); engine.createTable("Food", v);
Relation temp = engine.updateCmd(engine.getTableFromName("Food"), "Dinner", "SUCCESS", "Breakfast", "Pancakes");
//engine.update temp.display();
/*actual testing
string x;
cout << "Enter DBMS Commands: ";
while(getline(cin, x))
{
//cout << x << endl;
parse(x, engine);
cout << "Enter DBMS Commands: ";
}
*/
} }