diff --git a/Attribute.h b/Attribute.h index 08e12c9..9d8587b 100755 --- a/Attribute.h +++ b/Attribute.h @@ -1,47 +1,57 @@ -#include -#include - -using namespace std; - -//Funtional, might need more functionality - -//template -class Attribute { - //a named column of a relation - string name; - - bool isKey; - int size; - -public: - - vector values; - - void initializeAttribute(string n, vector a){ - - name = n; - values = a; - } - - string getName(){ - return name; - } - - Attribute(){ } - - void display() - { - cout<<"Atribute name:\t"< getElements(){ - return values; - } - */ -}; +#include +#include + +using namespace std; + +//Funtional, might need more functionality + +//template +class Attribute { + //a named column of a relation + string name; + string type; + bool key; + int size; + +public: + vector values; + + Attribute(string n, string t, bool k){ + name = n; + type = t; + key = k; + size = 0; + } + + void addRow(string v) { + values.push_back(v); + } + + string getName(){ + return name; + } + + string getType(){ + return type; + } + + bool isKey(){ + return key; + } + + void display() + { + cout<<"Atribute name:\t"< DBEngine::projectQuery(Relation table, string query){ - - /* - So basically this is what's going on: - - Take the table to iterate through, this is the relation (input 1) - - Take a string that will be used for the program to search for in the attributes (input 2) - - Iterate through each attribute until the attribute (string) matches the input query - - For every iterator, have a counter that counts how many attributes are skipped over in the vector until the attribute is found - - This counter will be used to iterate through each vector (row) in the list, skip over that many attributes, and push that into a result vector - - Once all vector's elements at the specified attribute are pushed back, return the result vector - - - for(int i = 0; i < table.getSize(); i++) { - - - } - -} -*/ -//each row in the first table is paired with all the rows in the second table -void DBEngine::productQuery(){ - // -} - -//true if relations have the same # of attributes and each attribute must be from the same domain -bool DBEngine::unionComp(){ - return false; -} diff --git a/DBEngine.h b/DBEngine.h index 9ec458b..ed5de9c 100755 --- a/DBEngine.h +++ b/DBEngine.h @@ -3,23 +3,36 @@ #include #include "Relation.h" -using namespace std; - -class DBEngine { - //member variables - //NOT DONE - //vector tables; +//still in progress +class DBEngine { + vector tables; + int size; public: - DBEngine(); - void createCmd(); - //void openCmd(); - void saveCmd(); - void showCmd(); - void insertQuery(); - void deleteQuery(); - void selectQuery(); - void projectQuery(); - void productQuery(); - bool unionComp(); + DBEngine(){ + size = 0; + } + + void createTable(string n, vector a) { + Relation r(n, a); + tables.push_back(r); + } + + void createTable(Relation r) { + tables.push_back(r); + } + + void showTable() { /*Becca*/ } + void saveToFile() { /*Becca*/ } + void insertTuple() { /*William*/ } + void deleteTuple() { /*William*/ } + void selectTuples() { /*Becca*/ } + void project() { /*Brandon*/ } + void product() { /*Brandon*/ } + void unionComp() { /*William*/ } + + + vector getRelations() { + return tables; + } }; diff --git a/Relation.h b/Relation.h index 8aadaf7..b27f6fc 100755 --- a/Relation.h +++ b/Relation.h @@ -1,47 +1,60 @@ -#include -#include -#include "Attribute.h" - -using namespace std; - -//NOT DONE -class Relation { - //a table with rows and columns - string name; //The title the user gives it - vector< Attribute > att; //A vector of the columns - -public: - Relation(); - - //constructor - Relation(string n, vector< Attribute > a) { - name = n; - att = a; - } - - void addTuple(vector< string > tuple) { - - //Loop through the attribute columns - for(int i = 0; i < att.size(); i++) { - - //Loop through the elements in the i'th column - for(int j = 0; j < att[i].values.size(); j++){ - - //In this column, at this element's spot, assign an element from the tuple vector to this spot - (att[i].values[j]).assign(tuple[i]); - } - } - } - - void displayTableName() { - cout << "The table name is: " << name << endl; - } - - vector< Attribute > getAttributes(){ - return att; - } - - int getSize() { - return att.size(); - } -}; +#include +#include +#include "Attribute.h" + +//Functional +class Relation { + string name; //The title the user gives it + vector att; //A vector of the columns + +public: + Relation(); + + //constructor + Relation(string n, vector a) { + name = n; + att = a; + } + + void addTuple(vector tuple) { + //Loop through the attribute columns + for(int i = 0; i < att.size(); i++) { + + //Loop through the elements in the i'th column + for(int j = 0; j < att[i].values.size(); j++){ + + //In this column, at this element's spot, assign an element from the tuple vector to this spot + att[i].addRow(tuple[i]); + } + } + } + + string getTableName() { + return name; + } + + void displayTableName() { + cout << "The table name is: " << name << endl; + } + + vector getAttributes() { + return att; + } + + int getSize() { + return att.size(); + } + + void display() { + cout<<"\n\nDisplay of relation--------------------------------"< -#include "DBEngine.h" - -using namespace std; - -int main() { - - - //DBEngine engine; - vector my_vector = {"Name", "Grade", "Happiness"}; - string at1 = "Name", at2 = "Grade", at3 = "Happiness"; - - - Attribute attribute_1(at1);//, attribute_2(at2), attribute_3(at3); - - - //Relation r(line1, my_attributes); - - //r.displayTableName(); -*/ - -#include -//#include "DBEngine.h" #include -#include "Attribute.h" - +#include "DBEngine.h" + using namespace std; - -int main() { - - /* + +//still in progress +int main() { DBEngine engine; - Relation r; - Attribute a; - */ - - vector shamWow; - shamWow.push_back("rag"); - shamWow.push_back("sponge"); - shamWow.push_back("wooow"); - shamWow.push_back("cloth"); - - Attribute atributo; - atributo.initializeAttribute("atributo",shamWow); - atributo.display(); - - vector doom; - doom.push_back("zombieman"); - doom.push_back("revenant"); - doom.push_back("imp"); - doom.push_back("archvile"); - - Attribute atributo2; - atributo2.initializeAttribute("attribute_2", doom); - atributo2.display(); - - - - - string line1 = "Table_1"; - - - - //Relation r(line1, my_attributes); -} + Attribute att1("shamWow", "VARCHAR(10)", true); + att1.addRow("rag"); + att1.addRow("sponge"); + att1.addRow("wooow"); + att1.addRow("cloth"); + att1.display(); + + Attribute att2("doom", "VARCHAR(20)", false); + att2.addRow("zombieman"); + att2.addRow("revenant"); + att2.addRow("imp"); + att2.addRow("archvile"); + att2.display(); + + vector vec; + vec.push_back(att1); + vec.push_back(att2); + + engine.createTable("table1", vec); +}