update works
This commit is contained in:
parent
909df70f2d
commit
20fec486b6
6 changed files with 35 additions and 28 deletions
|
@ -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;
|
||||
}
|
34
DBEngine.cpp
34
DBEngine.cpp
|
@ -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();
|
||||
|
||||
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);
|
||||
//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);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
vector<Attribute> atts = r.getAttributes();
|
||||
|
||||
for (int i = 0; i < atts.size(); ++i){
|
||||
if (atts[i].getName() == attNameSet){
|
||||
for (int j = 0; j < inds.size(); ++j){
|
||||
atts[i].setValue(attSet, inds[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
r.setAttributes(atts);
|
||||
return r;
|
||||
}
|
||||
|
|
|
@ -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){
|
||||
|
|
|
@ -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
BIN
a.out
Executable file
Binary file not shown.
19
test.cpp
19
test.cpp
|
@ -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();
|
||||
}
|
||||
|
|
Reference in a new issue