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;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Attribute::rename(string s){
|
|
||||||
name = s;
|
|
||||||
}
|
|
||||||
|
|
||||||
//may need to change primary key implementation
|
//may need to change primary key implementation
|
||||||
int Attribute::getSize(){
|
int Attribute::getSize(){
|
||||||
return size;
|
return size;
|
||||||
|
|
|
@ -21,6 +21,5 @@ public:
|
||||||
string getType();
|
string getType();
|
||||||
bool isKey();
|
bool isKey();
|
||||||
int getSize();
|
int getSize();
|
||||||
void rename(string s);
|
|
||||||
void display();
|
void display();
|
||||||
};
|
};
|
|
@ -28,7 +28,7 @@ vector<Relation> DBEngine::getRelations(){
|
||||||
return tables;
|
return tables;
|
||||||
}
|
}
|
||||||
|
|
||||||
Relation DBEngine::getTableFromName(string n){
|
Relation& DBEngine::getTableFromName(string n){
|
||||||
//will return first occurence
|
//will return first occurence
|
||||||
for(int i = 0; i < tables.size(); i++){
|
for(int i = 0; i < tables.size(); i++){
|
||||||
if (tables[i].getTableName() == n){
|
if (tables[i].getTableName() == n){
|
||||||
|
@ -61,7 +61,7 @@ Relation DBEngine::projection(vector<string> input, Relation r){
|
||||||
}
|
}
|
||||||
|
|
||||||
//ASAP: TEST ALL OF THIS
|
//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()) {
|
if (oldnames.size() != newnames.size()) {
|
||||||
cout << "Failure to rename: number of attributes do not match.";
|
cout << "Failure to rename: number of attributes do not match.";
|
||||||
return;
|
return;
|
||||||
|
@ -73,11 +73,8 @@ void rename(Relation r, vector<string> oldnames, vector<string> newnames){
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
Attribute temp;
|
|
||||||
|
|
||||||
for(int i = 0; i < oldnames.size(); ++i){
|
for(int i = 0; i < oldnames.size(); ++i){
|
||||||
temp = r.getAttributeByName(oldnames[i]);
|
r.renameAttribute(oldnames[i], newnames[i]);
|
||||||
temp.setName(newnames[i]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,13 +15,13 @@ public:
|
||||||
void createTable(Relation r);
|
void createTable(Relation r);
|
||||||
vector<Relation> getRelations();
|
vector<Relation> getRelations();
|
||||||
//void showTable(Relation r);
|
//void showTable(Relation r);
|
||||||
Relation getTableFromName(string n);
|
Relation& getTableFromName(string n);
|
||||||
void saveToFile(vector<string> cmds);
|
void saveToFile(vector<string> cmds);
|
||||||
|
|
||||||
//operations
|
//operations
|
||||||
//Relation selection();
|
//Relation selection();
|
||||||
Relation projection(vector<string> input, Relation r);
|
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 setUnion();
|
||||||
//void setDiff();
|
//void setDiff();
|
||||||
//void crossProduct();
|
//void crossProduct();
|
||||||
|
|
|
@ -29,7 +29,7 @@ vector<string> Relation::getAttributeNames(){
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
Attribute Relation::getAttributeByName(string s) {
|
Attribute& Relation::getAttributeByName(string s) {
|
||||||
for(int i = 0; i < size; ++i){
|
for(int i = 0; i < size; ++i){
|
||||||
if (att[i].getName() == s) {
|
if (att[i].getName() == s) {
|
||||||
return att[i];
|
return att[i];
|
||||||
|
@ -39,6 +39,10 @@ Attribute Relation::getAttributeByName(string s) {
|
||||||
cout << "Failure to return: the requested attribute does not exist.";
|
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(){
|
int Relation::getSize(){
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,8 @@ public:
|
||||||
string getTableName();
|
string getTableName();
|
||||||
vector<Attribute> getAttributes();
|
vector<Attribute> getAttributes();
|
||||||
vector<string> getAttributeNames();
|
vector<string> getAttributeNames();
|
||||||
Attribute getAttributeByName(string s);
|
Attribute& getAttributeByName(string s);
|
||||||
|
void renameAttribute(string oldstr, string newstr);
|
||||||
int getSize();
|
int getSize();
|
||||||
void display();
|
void display();
|
||||||
void insertTuple(vector<string> tuple); //we are assuming they are in order
|
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(att2);
|
||||||
v.push_back(att3);
|
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;
|
vector<string> tuple;
|
||||||
tuple.push_back("Omelette");
|
tuple.push_back("Omelette");
|
||||||
tuple.push_back("Fried Rice");
|
tuple.push_back("Fried Rice");
|
||||||
tuple.push_back("Grouper");
|
tuple.push_back("Grouper");
|
||||||
|
|
||||||
r.insertTuple(tuple);
|
engine.getTableFromName("Food").insertTuple(tuple);
|
||||||
r.display();
|
|
||||||
|
|
||||||
vector<string> o;
|
vector<string> old;
|
||||||
vector<string> n;
|
vector<string> newa;
|
||||||
|
|
||||||
o.push_back("Breakfast");
|
old.push_back("Breakfast");
|
||||||
o.push_back("Lunch");
|
old.push_back("Lunch");
|
||||||
o.push_back("Dinner");
|
old.push_back("Dinner");
|
||||||
|
|
||||||
n.push_back("Tsafkaerb");
|
newa.push_back("Tsafkaerb");
|
||||||
n.push_back("Hcnul");
|
newa.push_back("Hcnul");
|
||||||
n.push_back("Rennid");
|
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