delete working
This commit is contained in:
parent
4515a7073b
commit
25ce3c7248
6 changed files with 36 additions and 9 deletions
12
DBEngine.cpp
12
DBEngine.cpp
|
@ -315,7 +315,7 @@ Relation DBEngine::updateCmd(Relation r, string attNameSet, string attSet, strin
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
Relation DBEngine::deleteCmd(Relation r, string attName, string att){
|
/*Relation DBEngine::deleteCmd(Relation r, string attName, string att){
|
||||||
for (int i = 0; i < r.getSize(); ++i){
|
for (int i = 0; i < r.getSize(); ++i){
|
||||||
if (r[i].getName() == attName){
|
if (r[i].getName() == attName){
|
||||||
for (int j = 0; j < r[i].getSize(); ++j){
|
for (int j = 0; j < r[i].getSize(); ++j){
|
||||||
|
@ -326,6 +326,14 @@ Relation DBEngine::deleteCmd(Relation r, string attName, string att){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//r.setAttributes(atts);
|
|
||||||
return r;
|
return r;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
void DBEngine::deleteCmd(string relationName, string attName, string att){
|
||||||
|
for(int i = 0; i < tables.size(); i++){
|
||||||
|
if (tables[i].getTableName() == relationName){
|
||||||
|
tables[i].deleteCmd(attName, att);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,5 +32,6 @@ public:
|
||||||
Relation setDiff(Relation r1, Relation r2);
|
Relation setDiff(Relation r1, Relation r2);
|
||||||
Relation crossProduct(Relation r1, Relation r2);
|
Relation crossProduct(Relation r1, Relation r2);
|
||||||
Relation updateCmd(Relation r, string attNameSet, string attSet, string attNameWhere, string attWhere);
|
Relation updateCmd(Relation r, string attNameSet, string attSet, string attNameWhere, string attWhere);
|
||||||
Relation deleteCmd(Relation r, string attName, string att);
|
//Relation deleteCmd(Relation r, string attName, string att);
|
||||||
|
void deleteCmd(string relationName, string attName, string att);
|
||||||
};
|
};
|
||||||
|
|
16
Relation.cpp
16
Relation.cpp
|
@ -157,3 +157,19 @@ void Relation::removeFromTuple(int rindex, int aindex)
|
||||||
att[rindex].removeCell(aindex);
|
att[rindex].removeCell(aindex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Relation::updateCmd(){
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void Relation::deleteCmd(string attName, string s){
|
||||||
|
for (int i = 0; i < att.size(); ++i){
|
||||||
|
if (att[i].getName() == attName){
|
||||||
|
for (int j = 0; j < att[i].getSize(); ++j){
|
||||||
|
if (att[i][j] == s){
|
||||||
|
removeTuple(j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,4 +28,6 @@ public:
|
||||||
void insertFromRelation(Relation r);
|
void insertFromRelation(Relation r);
|
||||||
void removeTuple(int index);
|
void removeTuple(int index);
|
||||||
void removeFromTuple(int rindex, int aindex);
|
void removeFromTuple(int rindex, int aindex);
|
||||||
|
void updateCmd();
|
||||||
|
void deleteCmd(string attName, string s);
|
||||||
};
|
};
|
BIN
a.out
BIN
a.out
Binary file not shown.
4
test.cpp
4
test.cpp
|
@ -33,6 +33,6 @@ int main () {
|
||||||
v.push_back(att3);
|
v.push_back(att3);
|
||||||
|
|
||||||
engine.createTable("Food", v);
|
engine.createTable("Food", v);
|
||||||
Relation temp = engine.deleteCmd(engine.getTableFromName("Food"), "Breakfast", "Pancakes");
|
engine.deleteCmd("Food", "Breakfast", "Pancakes");
|
||||||
temp.display();
|
engine.getTableFromName("Food").display();
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue