diff --git a/Attribute.h b/Attribute.h index c38f0df..fb3fd48 100755 --- a/Attribute.h +++ b/Attribute.h @@ -26,6 +26,11 @@ public: size++; } + string getElementAt(int pos) + { + return values[pos]; + } + vector getValues() { return values; } string getName(){ return name; } string getType(){ return type; } diff --git a/OUTPUT.txt b/OUTPUT.txt index 526f77f..c79684b 100755 --- a/OUTPUT.txt +++ b/OUTPUT.txt @@ -4,12 +4,14 @@ 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-------------------------------- @@ -20,6 +22,7 @@ This results in such output: 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")); @@ -29,6 +32,7 @@ This will display: 1 + To project a table's column: engine.project((engine.getTableFromName("table1")), "name"); @@ -43,3 +47,22 @@ This will display: Leela Zoidberg + +With an arbitrary vector of strings as cmds (until we are able to parse effectively): + + engine.saveToFile(cmds); + + +This will result in a text file with the contents: + + CREATE TABLE animals (name VARCHAR(20), kind VARCHAR(8), years INTEGER) PRIMARY KEY (name, kind); + +SHOW animals; + +//insert + +//delete + +//select + +//product \ No newline at end of file diff --git a/Relation.h b/Relation.h index 40084c8..f8e7a49 100755 --- a/Relation.h +++ b/Relation.h @@ -47,6 +47,26 @@ public: } } + vector findTuple(string attributeType, string type) + { + vector tupleSlot; // tuples that have the attribute in question + for (int i = 0; i < att.size(); ++i)// find attribute in question + { + if(att[i].getName() == attributeType) + { + for (int j = 0; j < att[i].getSize(); ++j)//search through all the values of the attribute column + { + if (att[i].getElementAt(j) == type) + { + tupleSlot.push_back(j); + } + } + + } + } + return tupleSlot; + } + string getTableName() { return name; } diff --git a/a.out b/a.out index eb1cbf7..6c65e5b 100755 Binary files a/a.out and b/a.out differ diff --git a/savefile.txt b/savefile.txt new file mode 100644 index 0000000..e5ca19f --- /dev/null +++ b/savefile.txt @@ -0,0 +1,2 @@ +CREATE TABLE animals (name VARCHAR(20), kind VARCHAR(8), years INTEGER) PRIMARY KEY (name, kind); +SHOW animals; diff --git a/test.cpp b/test.cpp index 3e02259..1b99116 100755 --- a/test.cpp +++ b/test.cpp @@ -72,5 +72,7 @@ int main() { vector cmds; 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); }