message
This commit is contained in:
parent
1902e6f3d5
commit
ed1a6fa879
6 changed files with 33 additions and 17 deletions
|
@ -46,10 +46,5 @@ public:
|
|||
{
|
||||
cout<<values[i]<<" ";
|
||||
}
|
||||
}
|
||||
|
||||
void erase(int position)
|
||||
{
|
||||
values.erase(values.begin()+ position);
|
||||
}
|
||||
};
|
||||
|
|
17
DBEngine.h
17
DBEngine.h
|
@ -33,7 +33,7 @@ public:
|
|||
|
||||
void saveToFile(vector<string> cmds) {
|
||||
ofstream file;
|
||||
file.open("savefile.txt");
|
||||
file.open("savefile.db");
|
||||
|
||||
for(int i = 0; i < cmds.size(); ++i){
|
||||
file << cmds[i] << endl;
|
||||
|
@ -42,10 +42,19 @@ public:
|
|||
file.close();
|
||||
}
|
||||
|
||||
void insertTuple() { /*DONE*/ }
|
||||
void deleteTuple() { /*DONE*/ }
|
||||
void selectTuples() { /*DONE*/ }
|
||||
void insertTuple(Relation r, vector<string> t) { r.addTuple(t); }
|
||||
|
||||
//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 product() { /*Brandon*/ }
|
||||
|
||||
bool unionComp(Relation r1, Relation r2) {
|
||||
|
|
|
@ -31,7 +31,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
void removeTuple(int tupleNum) {
|
||||
void removeTuple(int tupleNum) {
|
||||
if (tupleNum > att[0].getSize() || tupleNum < 0)
|
||||
{
|
||||
cout<<"ERROR! index out of bound"<<endl;
|
||||
|
@ -39,10 +39,11 @@ public:
|
|||
|
||||
else
|
||||
{
|
||||
|
||||
cout << "a" + att.size();
|
||||
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
BIN
a.out
Binary file not shown.
21
test.cpp
21
test.cpp
|
@ -44,6 +44,7 @@ int main() {
|
|||
engine.createTable("table1", vec2);
|
||||
engine.createTable("table2", vec);
|
||||
engine.showTable(engine.getTableFromName("table1"));
|
||||
cout << "\n\n";
|
||||
|
||||
Attribute att5("name", "VARCHAR(20)", true);
|
||||
att5.addRow("Yrf");
|
||||
|
@ -63,16 +64,26 @@ int main() {
|
|||
|
||||
engine.createTable("table3", vec3);
|
||||
|
||||
cout << "\n";
|
||||
cout << engine.unionComp(engine.getTableFromName("table1"), engine.getTableFromName("table2"));
|
||||
cout << engine.unionComp(engine.getTableFromName("table1"), engine.getTableFromName("table3"));
|
||||
cout << "\n";
|
||||
//cout << "\n";
|
||||
//cout << engine.unionComp(engine.getTableFromName("table1"), engine.getTableFromName("table2"));
|
||||
//cout << engine.unionComp(engine.getTableFromName("table1"), engine.getTableFromName("table3"));
|
||||
//cout << "\n";
|
||||
|
||||
engine.project((engine.getTableFromName("table1")), "name");
|
||||
//engine.project((engine.getTableFromName("table1")), "name");
|
||||
|
||||
vector<string> cmds;
|
||||
cmds.push_back("CREATE TABLE animals (name VARCHAR(20), kind VARCHAR(8), years INTEGER) PRIMARY KEY (name, kind);");
|
||||
cmds.push_back("SHOW animals;");
|
||||
|
||||
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")));
|
||||
}
|
||||
|
|
Reference in a new issue