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;
}
void Attribute::setValue(string s, int index)
{
void Attribute::setValue(string s, int index) {
values[index] = s;
}
@ -89,4 +88,5 @@ void Attribute::display(){
void Attribute::clearAllValues(){
values.clear();
size = 0;
}

View file

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

View file

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

View file

@ -17,6 +17,7 @@ public:
Attribute operator[](int i);
vector<string> getTuple(int index);
vector<Attribute> getAttributes();
void setAttributes(vector<Attribute> v);
vector<string> getAttributeNames();
Attribute& getAttributeByName(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("Waffles");
att1.addCell("Biscuits");
att1.addCell("Pancakes");
att2.addCell("Turkey Sandwich");
att2.addCell("Caesar Salad");
att2.addCell("Pizza");
att2.addCell("Sushi");
att3.addCell("Steak");
att3.addCell("Shrimp");
att3.addCell("Ribs");
att3.addCell("Lasagna");
vector<Attribute> v;
v.push_back(att1);
@ -30,18 +33,6 @@ int main () {
v.push_back(att3);
engine.createTable("Food", v);
//engine.update
/*actual testing
string x;
cout << "Enter DBMS Commands: ";
while(getline(cin, x))
{
//cout << x << endl;
parse(x, engine);
cout << "Enter DBMS Commands: ";
}
*/
Relation temp = engine.updateCmd(engine.getTableFromName("Food"), "Dinner", "SUCCESS", "Breakfast", "Pancakes");
temp.display();
}