more testing
This commit is contained in:
parent
fc0f899568
commit
38a4fdefe3
6 changed files with 75 additions and 25 deletions
|
@ -23,6 +23,7 @@ public:
|
|||
|
||||
void addRow(string v) {
|
||||
values.push_back(v);
|
||||
size++;
|
||||
}
|
||||
|
||||
vector<string> getValues() { return values; }
|
||||
|
|
27
DBEngine.h
27
DBEngine.h
|
@ -18,9 +18,9 @@ public:
|
|||
tables.push_back(r);
|
||||
}
|
||||
|
||||
void createTable(Relation r) {
|
||||
tables.push_back(r);
|
||||
}
|
||||
void createTable(Relation r) { tables.push_back(r); }
|
||||
vector<Relation> getRelations() { return tables; }
|
||||
void showTable(Relation r) { r.display(); }
|
||||
|
||||
Relation getTableFromName(string n) {
|
||||
//will return first occurence
|
||||
|
@ -31,23 +31,24 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
void showTables(Relation r) {
|
||||
r.display();
|
||||
void saveToFile(vector<string> cmds) {
|
||||
ofstream file;
|
||||
file.open("savefile.txt");
|
||||
|
||||
for(int i = 0; i < cmds.size(); ++i){
|
||||
file << cmds[i] << endl;
|
||||
}
|
||||
|
||||
file.close();
|
||||
}
|
||||
|
||||
void saveToFile() { /*Becca*/ }
|
||||
void insertTuple() { /*DONE*/ }
|
||||
void deleteTuple() { /*DONE*/ }
|
||||
void selectTuples() { /*William*/ }
|
||||
void project() { /*DONE*/ }
|
||||
void selectTuples() { /*DONE*/ }
|
||||
void project(Relation r, string n) { r.projectQuery(n); }
|
||||
void product() { /*Brandon*/ }
|
||||
|
||||
bool unionComp(Relation r1, Relation r2) {
|
||||
return ((r1.getSize() == r2.getSize()) && (r1.getDomains() == r2.getDomains()));
|
||||
}
|
||||
|
||||
|
||||
vector<Relation> getRelations() {
|
||||
return tables;
|
||||
}
|
||||
};
|
||||
|
|
45
OUTPUT.txt
Executable file
45
OUTPUT.txt
Executable file
|
@ -0,0 +1,45 @@
|
|||
Assuming previously defined Attribute, compiled in a vector known as 'vec' and with subsequent numbers added
|
||||
|
||||
To create a table:
|
||||
|
||||
engine.createTable("table1", vec);
|
||||
|
||||
This creates a Relation object with the appropriate Attribute objects. It displays nothing.
|
||||
|
||||
To display the table:
|
||||
|
||||
engine.showTables(engine.getTableFromName("table1"));
|
||||
|
||||
This results in such output:
|
||||
|
||||
Display of relation--------------------------------
|
||||
Relation name: table1
|
||||
|
||||
Attribute name: name
|
||||
Elements: Fry Bender Leela Zoidberg
|
||||
Attribute name: age
|
||||
Elements: 22 5 22 50
|
||||
|
||||
With table3 having an equal domain to table1, this:
|
||||
|
||||
cout << engine.unionComp(engine.getTableFromName("table1"), engine.getTableFromName("table3"));
|
||||
|
||||
|
||||
This will display:
|
||||
|
||||
1
|
||||
|
||||
To project a table's column:
|
||||
|
||||
engine.project((engine.getTableFromName("table1")), "name");
|
||||
|
||||
|
||||
This will display:
|
||||
|
||||
-----------Initiated Query Projection---------
|
||||
Column Title: name
|
||||
Fry
|
||||
Bender
|
||||
Leela
|
||||
Zoidberg
|
||||
|
|
@ -59,11 +59,11 @@ public:
|
|||
return att;
|
||||
}
|
||||
|
||||
//assumes that all attribute titles are unique
|
||||
void projectQuery(string input) {
|
||||
cout << "-----------Initiated Query Projection---------" << endl;
|
||||
for(int i = 0; i < att.size(); i++) {
|
||||
if(att[i].getName() == input) {
|
||||
|
||||
cout << "Column Title: " << input << endl;
|
||||
for(int j = 0; j < att[i].getSize(); j++) {
|
||||
cout << att[i].getValues()[j] << endl;
|
||||
|
@ -77,15 +77,12 @@ public:
|
|||
}
|
||||
|
||||
void display() {
|
||||
cout<<"\n\nDisplay of relation--------------------------------"<<endl;
|
||||
cout<<"\nDisplay of relation--------------------------------"<<endl;
|
||||
cout<<"Relation name: "<<name<<endl;
|
||||
for (int i = 0; i < size; ++i)
|
||||
{
|
||||
|
||||
cout<<"\nAttribute name: "<<att[i].getName()<<": ";
|
||||
|
||||
cout<<"\n";
|
||||
att[i].display();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
BIN
a.out
BIN
a.out
Binary file not shown.
16
test.cpp
16
test.cpp
|
@ -41,9 +41,9 @@ int main() {
|
|||
vec2.push_back(att4);
|
||||
|
||||
//beginning testing of core DB functions
|
||||
engine.createTable("table1", vec);
|
||||
engine.createTable("table2", vec2);
|
||||
engine.showTables(engine.getTableFromName("table1"));
|
||||
engine.createTable("table1", vec2);
|
||||
engine.createTable("table2", vec);
|
||||
engine.showTable(engine.getTableFromName("table1"));
|
||||
|
||||
Attribute att5("name", "VARCHAR(20)", true);
|
||||
att5.addRow("Yrf");
|
||||
|
@ -63,8 +63,14 @@ int main() {
|
|||
|
||||
engine.createTable("table3", vec3);
|
||||
|
||||
cout << "a";
|
||||
cout << "\n";
|
||||
cout << engine.unionComp(engine.getTableFromName("table1"), engine.getTableFromName("table2"));
|
||||
cout << engine.unionComp(engine.getTableFromName("table2"), engine.getTableFromName("table3"));
|
||||
cout << engine.unionComp(engine.getTableFromName("table1"), engine.getTableFromName("table3"));
|
||||
cout << "\n";
|
||||
|
||||
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");
|
||||
}
|
||||
|
|
Reference in a new issue