This commit is contained in:
Rebecca Schofield 2015-09-15 23:38:44 -05:00
parent 1902e6f3d5
commit ed1a6fa879
6 changed files with 33 additions and 17 deletions

View file

@ -46,10 +46,5 @@ public:
{ {
cout<<values[i]<<" "; cout<<values[i]<<" ";
} }
}
void erase(int position)
{
values.erase(values.begin()+ position);
} }
}; };

View file

@ -33,7 +33,7 @@ public:
void saveToFile(vector<string> cmds) { void saveToFile(vector<string> cmds) {
ofstream file; ofstream file;
file.open("savefile.txt"); file.open("savefile.db");
for(int i = 0; i < cmds.size(); ++i){ for(int i = 0; i < cmds.size(); ++i){
file << cmds[i] << endl; file << cmds[i] << endl;
@ -42,10 +42,19 @@ public:
file.close(); file.close();
} }
void insertTuple() { /*DONE*/ } void insertTuple(Relation r, vector<string> t) { r.addTuple(t); }
void deleteTuple() { /*DONE*/ }
void selectTuples() { /*DONE*/ } //need to add find by name
void deleteTuple(Relation r, int n) {
cout << "a";
r.removeTuple(n); }
void selectTuples() {
//
}
void project(Relation r, string n) { r.projectQuery(n); } void project(Relation r, string n) { r.projectQuery(n); }
void product() { /*Brandon*/ } void product() { /*Brandon*/ }
bool unionComp(Relation r1, Relation r2) { bool unionComp(Relation r1, Relation r2) {

View file

@ -31,7 +31,7 @@ public:
} }
} }
void removeTuple(int tupleNum) { void removeTuple(int tupleNum) {
if (tupleNum > att[0].getSize() || tupleNum < 0) if (tupleNum > att[0].getSize() || tupleNum < 0)
{ {
cout<<"ERROR! index out of bound"<<endl; cout<<"ERROR! index out of bound"<<endl;
@ -39,10 +39,11 @@ public:
else else
{ {
cout << "a" + att.size();
for(int i = 0; i < att.size(); ++i) //for all the attributes for(int i = 0; i < att.size(); ++i) //for all the attributes
{ {
att[i].erase(tupleNum); cout << "SSSSSSSSSSSSSSSSSSSSSSSSSS" + tupleNum;
att[i].getValues().erase(att[i].getValues().begin()+ tupleNum);
} }
} }
} }

BIN
a.out

Binary file not shown.

View file

@ -44,6 +44,7 @@ int main() {
engine.createTable("table1", vec2); engine.createTable("table1", vec2);
engine.createTable("table2", vec); engine.createTable("table2", vec);
engine.showTable(engine.getTableFromName("table1")); engine.showTable(engine.getTableFromName("table1"));
cout << "\n\n";
Attribute att5("name", "VARCHAR(20)", true); Attribute att5("name", "VARCHAR(20)", true);
att5.addRow("Yrf"); att5.addRow("Yrf");
@ -63,16 +64,26 @@ int main() {
engine.createTable("table3", vec3); engine.createTable("table3", vec3);
cout << "\n"; //cout << "\n";
cout << engine.unionComp(engine.getTableFromName("table1"), engine.getTableFromName("table2")); //cout << engine.unionComp(engine.getTableFromName("table1"), engine.getTableFromName("table2"));
cout << engine.unionComp(engine.getTableFromName("table1"), engine.getTableFromName("table3")); //cout << engine.unionComp(engine.getTableFromName("table1"), engine.getTableFromName("table3"));
cout << "\n"; //cout << "\n";
engine.project((engine.getTableFromName("table1")), "name"); //engine.project((engine.getTableFromName("table1")), "name");
vector<string> cmds; vector<string> cmds;
cmds.push_back("CREATE TABLE animals (name VARCHAR(20), kind VARCHAR(8), years INTEGER) PRIMARY KEY (name, kind);"); cmds.push_back("CREATE TABLE animals (name VARCHAR(20), kind VARCHAR(8), years INTEGER) PRIMARY KEY (name, kind);");
cmds.push_back("SHOW animals;"); cmds.push_back("SHOW animals;");
engine.saveToFile(cmds); engine.saveToFile(cmds);
vector<string> t;
t.push_back("Professor");
t.push_back("180");
//engine.insertTuple((engine.getTableFromName("table1")), t);
engine.deleteTuple((engine.getTableFromName("table1")), 2);
cout << "\n\n";
engine.showTable((engine.getTableFromName("table1")));
} }