diff --git a/Attribute.h b/Attribute.h index 4b60d4d..c38f0df 100755 --- a/Attribute.h +++ b/Attribute.h @@ -23,6 +23,7 @@ public: void addRow(string v) { values.push_back(v); + size++; } vector getValues() { return values; } diff --git a/DBEngine.h b/DBEngine.h index ecb9590..c720c03 100755 --- a/DBEngine.h +++ b/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 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 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 getRelations() { - return tables; - } }; diff --git a/OUTPUT.txt b/OUTPUT.txt new file mode 100755 index 0000000..526f77f --- /dev/null +++ b/OUTPUT.txt @@ -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 + diff --git a/Relation.h b/Relation.h index 525a0d9..40084c8 100755 --- a/Relation.h +++ b/Relation.h @@ -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--------------------------------"< cmds; + cmds.push_back("CREATE TABLE animals (name VARCHAR(20), kind VARCHAR(8), years INTEGER) PRIMARY KEY (name, kind);"); + cmds.push_back("SHOW animals"); }