remove tuple implemented
This commit is contained in:
parent
091f084b45
commit
db4396b952
7 changed files with 39 additions and 7 deletions
|
@ -21,6 +21,11 @@ void Attribute::addCell(string v){
|
||||||
size++;
|
size++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Attribute::removeCell(int index){
|
||||||
|
values.erase(values.begin() + index);
|
||||||
|
size--;
|
||||||
|
}
|
||||||
|
|
||||||
string Attribute::operator[](int i){
|
string Attribute::operator[](int i){
|
||||||
return values[i];
|
return values[i];
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ public:
|
||||||
Attribute();
|
Attribute();
|
||||||
Attribute(string n, string t, bool k);
|
Attribute(string n, string t, bool k);
|
||||||
void addCell(string v);
|
void addCell(string v);
|
||||||
|
void removeCell(int index);
|
||||||
string operator[](int i);
|
string operator[](int i);
|
||||||
vector<string> getValues();
|
vector<string> getValues();
|
||||||
string getName();
|
string getName();
|
||||||
|
|
18
DBEngine.cpp
18
DBEngine.cpp
|
@ -87,8 +87,22 @@ void DBEngine::rename(Relation& r, vector<string> oldnames, vector<string> newna
|
||||||
|
|
||||||
Relation DBEngine::setUnion(Relation r1, Relation r2){
|
Relation DBEngine::setUnion(Relation r1, Relation r2){
|
||||||
if (r1.getAttributeNames() != r2.getAttributeNames()){
|
if (r1.getAttributeNames() != r2.getAttributeNames()){
|
||||||
cout << "Failure to union: the relations are not union-compatible";
|
vector<string> v1 = r1.getAttributeNames();
|
||||||
return;
|
vector<string> v2 = r2.getAttributeNames();
|
||||||
|
|
||||||
|
for (int i = 0; i < v1.size(); ++i){
|
||||||
|
cout << v1[i] << " ";
|
||||||
|
}
|
||||||
|
cout << "\n";
|
||||||
|
|
||||||
|
for (int i = 0; i < v2.size(); ++i){
|
||||||
|
cout << v2[i] << " ";
|
||||||
|
}
|
||||||
|
cout << "\n";
|
||||||
|
|
||||||
|
|
||||||
|
cout << "Failure to union: the relations are not union-compatible.\nreturning the first relation.\n";
|
||||||
|
return r1;
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
|
|
12
Relation.cpp
12
Relation.cpp
|
@ -110,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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,5 +23,5 @@ public:
|
||||||
void display();
|
void display();
|
||||||
void insertTuple(vector<string> tuple); //assuming they are in order
|
void insertTuple(vector<string> tuple); //assuming they are in order
|
||||||
void insertFromRelation(Relation r);
|
void insertFromRelation(Relation r);
|
||||||
//void removeTuple();
|
void removeTuple(int index);
|
||||||
};
|
};
|
BIN
a.out
Executable file
BIN
a.out
Executable file
Binary file not shown.
8
test.cpp
8
test.cpp
|
@ -29,9 +29,9 @@ int main() {
|
||||||
|
|
||||||
engine.createTable("Food", v);
|
engine.createTable("Food", v);
|
||||||
|
|
||||||
Attribute att4("SecondBreakfast", "VARCHAR(20)", true);
|
Attribute att4("Breakfast", "VARCHAR(20)", true);
|
||||||
Attribute att5("SecondLunch", "VARCHAR(20)", false);
|
Attribute att5("Lunch", "VARCHAR(20)", false);
|
||||||
Attribute att6("SecondDinner", "VARCHAR(20)", false);
|
Attribute att6("Dinner", "VARCHAR(20)", false);
|
||||||
|
|
||||||
att4.addCell("Pancakes");
|
att4.addCell("Pancakes");
|
||||||
att4.addCell("Bacon");
|
att4.addCell("Bacon");
|
||||||
|
@ -50,5 +50,5 @@ int main() {
|
||||||
|
|
||||||
engine.createTable("MoarFood", v2);
|
engine.createTable("MoarFood", v2);
|
||||||
|
|
||||||
//engine.setUnion(engine.getTableFromName("Food"), engine.getTableFromName("MoarFood")).display();
|
engine.setUnion(engine.getTableFromName("Food"), engine.getTableFromName("MoarFood")).display();
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue