fixed rename
This commit is contained in:
parent
b6af7f18c8
commit
1492321b9b
8 changed files with 29 additions and 27 deletions
|
@ -45,10 +45,6 @@ bool Attribute::isKey(){
|
|||
return key;
|
||||
}
|
||||
|
||||
void Attribute::rename(string s){
|
||||
name = s;
|
||||
}
|
||||
|
||||
//may need to change primary key implementation
|
||||
int Attribute::getSize(){
|
||||
return size;
|
||||
|
|
|
@ -21,6 +21,5 @@ public:
|
|||
string getType();
|
||||
bool isKey();
|
||||
int getSize();
|
||||
void rename(string s);
|
||||
void display();
|
||||
};
|
|
@ -28,7 +28,7 @@ vector<Relation> DBEngine::getRelations(){
|
|||
return tables;
|
||||
}
|
||||
|
||||
Relation DBEngine::getTableFromName(string n){
|
||||
Relation& DBEngine::getTableFromName(string n){
|
||||
//will return first occurence
|
||||
for(int i = 0; i < tables.size(); i++){
|
||||
if (tables[i].getTableName() == n){
|
||||
|
@ -61,7 +61,7 @@ Relation DBEngine::projection(vector<string> input, Relation r){
|
|||
}
|
||||
|
||||
//ASAP: TEST ALL OF THIS
|
||||
void rename(Relation r, vector<string> oldnames, vector<string> newnames){
|
||||
void DBEngine::rename(Relation& r, vector<string> oldnames, vector<string> newnames){
|
||||
if (oldnames.size() != newnames.size()) {
|
||||
cout << "Failure to rename: number of attributes do not match.";
|
||||
return;
|
||||
|
@ -73,11 +73,8 @@ void rename(Relation r, vector<string> oldnames, vector<string> newnames){
|
|||
}
|
||||
|
||||
else {
|
||||
Attribute temp;
|
||||
|
||||
for(int i = 0; i < oldnames.size(); ++i){
|
||||
temp = r.getAttributeByName(oldnames[i]);
|
||||
temp.setName(newnames[i]);
|
||||
r.renameAttribute(oldnames[i], newnames[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,13 +15,13 @@ public:
|
|||
void createTable(Relation r);
|
||||
vector<Relation> getRelations();
|
||||
//void showTable(Relation r);
|
||||
Relation getTableFromName(string n);
|
||||
Relation& getTableFromName(string n);
|
||||
void saveToFile(vector<string> cmds);
|
||||
|
||||
//operations
|
||||
//Relation selection();
|
||||
Relation projection(vector<string> input, Relation r);
|
||||
void rename(Relation r, vector<string> oldnames, vector<string> newnames);
|
||||
void rename(Relation& r, vector<string> oldnames, vector<string> newnames);
|
||||
//void setUnion();
|
||||
//void setDiff();
|
||||
//void crossProduct();
|
||||
|
|
|
@ -29,7 +29,7 @@ vector<string> Relation::getAttributeNames(){
|
|||
return temp;
|
||||
}
|
||||
|
||||
Attribute Relation::getAttributeByName(string s) {
|
||||
Attribute& Relation::getAttributeByName(string s) {
|
||||
for(int i = 0; i < size; ++i){
|
||||
if (att[i].getName() == s) {
|
||||
return att[i];
|
||||
|
@ -39,6 +39,10 @@ Attribute Relation::getAttributeByName(string s) {
|
|||
cout << "Failure to return: the requested attribute does not exist.";
|
||||
}
|
||||
|
||||
void Relation::renameAttribute(string oldstr, string newstr){
|
||||
this->getAttributeByName(oldstr).setName(newstr);
|
||||
}
|
||||
|
||||
int Relation::getSize(){
|
||||
return size;
|
||||
}
|
||||
|
|
|
@ -13,7 +13,8 @@ public:
|
|||
string getTableName();
|
||||
vector<Attribute> getAttributes();
|
||||
vector<string> getAttributeNames();
|
||||
Attribute getAttributeByName(string s);
|
||||
Attribute& getAttributeByName(string s);
|
||||
void renameAttribute(string oldstr, string newstr);
|
||||
int getSize();
|
||||
void display();
|
||||
void insertTuple(vector<string> tuple); //we are assuming they are in order
|
||||
|
|
BIN
a.out
BIN
a.out
Binary file not shown.
29
test.cpp
29
test.cpp
|
@ -26,26 +26,31 @@ int main() {
|
|||
v.push_back(att2);
|
||||
v.push_back(att3);
|
||||
|
||||
Relation r("Food", v);
|
||||
//Relation r("Food", v);
|
||||
//r.renameAttribute("Breakfast", "BFST");
|
||||
//r.display();
|
||||
|
||||
engine.createTable("Food", v);
|
||||
|
||||
vector<string> tuple;
|
||||
tuple.push_back("Omelette");
|
||||
tuple.push_back("Fried Rice");
|
||||
tuple.push_back("Grouper");
|
||||
|
||||
r.insertTuple(tuple);
|
||||
r.display();
|
||||
engine.getTableFromName("Food").insertTuple(tuple);
|
||||
|
||||
vector<string> o;
|
||||
vector<string> n;
|
||||
vector<string> old;
|
||||
vector<string> newa;
|
||||
|
||||
o.push_back("Breakfast");
|
||||
o.push_back("Lunch");
|
||||
o.push_back("Dinner");
|
||||
old.push_back("Breakfast");
|
||||
old.push_back("Lunch");
|
||||
old.push_back("Dinner");
|
||||
|
||||
n.push_back("Tsafkaerb");
|
||||
n.push_back("Hcnul");
|
||||
n.push_back("Rennid");
|
||||
newa.push_back("Tsafkaerb");
|
||||
newa.push_back("Hcnul");
|
||||
newa.push_back("Rennid");
|
||||
|
||||
//engine.rename(r, o, n);
|
||||
engine.rename(engine.getTableFromName("Food"), old, newa);
|
||||
engine.getTableFromName("Food").display();
|
||||
cout << "finished";
|
||||
}
|
Reference in a new issue