From a966090eeacde14b65aeba447a13551df317eecf Mon Sep 17 00:00:00 2001 From: Brandon Jackson <1drummer@att.net> Date: Tue, 15 Sep 2015 02:57:09 -0500 Subject: [PATCH 1/7] Update db_engine.cpp --- db_engine.cpp | 110 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 99 insertions(+), 11 deletions(-) diff --git a/db_engine.cpp b/db_engine.cpp index 30fa0b7..b88d9d4 100755 --- a/db_engine.cpp +++ b/db_engine.cpp @@ -1,12 +1,50 @@ #include "db_engine.h" +using namespace std; + db_engine::db_engine(){ // } //create a new table in memory -db_engine::createCmd(){ - //// +//creates a vector +//DONE +void db_engine::createCmd(string tableName, vector attributes, vector pkeys){ + string output = ""; + output += "CREATE TABLE " + tableName + " ("; + + vector::iterator it = attributes.begin(); + while (it != attributes.end()){ + if (it == attributes.begin()) + if ((it + 1) != attributes.end()) + output += *it + ","; + else + output += *it; + else + output+= " " + *it; + + ++it; + } + + output += ") PRIMARY KEY ("; + + vector::iterator it2 = pkeys.begin(); + while (it2 != pkeys.end()){ + if (it2 == pkeys.begin()) + if ((it2 + 1) != pkeys.end()) + output += *it2 + ","; + else + output += *it2; + else + output+= " " + *it2; + + ++it2; + } + + output += ");"; + + cout << output; + //cmdList.push_back(output); } //open a txt file, parse SQL script, load data in table @@ -14,42 +52,92 @@ db_engine::createCmd(){ // //} -//save all the commands to the db text file +//should write cmdList to a .txt file +//DONE void db_engine::saveCmd(){ - // + ofstream dbCmdFile; + dbCmdFile.open("dbCmds.txt", ios_base::app); + + vector::iterator it = cmdList.begin(); + while (it != cmdList.end()){ + dbCmdFile << *it << "\n"; + ++it; + } + + cmdList.clear(); } -//display the table currently stored in memory -void db_engine::showCmd(){ - // +//display the database +//DONE +void db_engine::showCmd(string tableName){ + cmdList.push_back("SHOW " + tableName + ""); } //add a tuple to a table in the memory +//BECCA void db_engine::insertQuery(){ - // + //table.push_back(); } //remove a tuple from a table in the memory +//BECCA void db_engine::deleteQuery(){ // } //search and return one more tuples from a table in the memory +//WILLIAM void db_engine::selectQuery(){ // } //return a subset of attributes (columns) -void db_engine::projectQuery(){ - // +//BRANDON +vector db_engine::projectQuery(vector< vector > table, vector attributes, string query){ + /* + So basically this is what's going on: + - Take the table to iterate through, this is the 2D vector (input 1) + - Take the vector of attributes that pertains to the respective table (input 2) + - Take a string that will be used for the program to search for in the attributes (input 3) + - In the attributes vector, 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 + */ + int counter = 0; //counter for iterating through the attributes, initialized at 0 for reasons + vector result; + + //Loop through the vector until we have found a string in it that matches the query + for(int i=0; i < attributes.size(); i++){ + counter++; + if(attributes[i] == query) + break; + else + continue; + } + + //So let's say we have a 2-D Vector (the table) that contains all of the rows, we iterate through each row + std::vector< std::vector >::const_iterator row; + std::vector::const_iterator col; + + for (row = table.begin(); row != table.end(); ++row) { + //Instead of col != row->end() we have it counter, in order for the program to access the correct data under the correct attribute + for (col = row->begin(); col != counter; col++) { + result.push_back(col); //Now we store that row's attribute into the result vector + } + } + + return result; } //each row in the first table is paired with all the rows in the second table -void db_engine::productQuery(){ +//BRANDON +vector< vector > db_engine::productQuery(vector< vector > table_1, vector< vector > table_2){ // } //true if relations have the same # of attributes and each attribute must be from the same domain +//WILLIAM bool db_engine::unionComp(){ return false; } From 68263bd0131327022c7ecb655a976cecddbada0a Mon Sep 17 00:00:00 2001 From: Brandon Jackson <1drummer@att.net> Date: Tue, 15 Sep 2015 02:57:33 -0500 Subject: [PATCH 2/7] Update db_engine.h --- db_engine.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/db_engine.h b/db_engine.h index f319f02..05e7b60 100755 --- a/db_engine.h +++ b/db_engine.h @@ -1,12 +1,19 @@ +#include +#include +#include + +using namespace std; + class db_engine { - //member variables + vector cmdList; + //vector> table; public: db_engine(); - void createCmd(); + void createCmd(string tableName, vector attributes, vector pkeys); //void openCmd(); void saveCmd(); - void showCmd(); + void showCmd(string tableName); void insertQuery(); void deleteQuery(); void selectQuery(); From b842955e3e44b707b4b4ca12d6f386a275ba19f9 Mon Sep 17 00:00:00 2001 From: Brandon Jackson <1drummer@att.net> Date: Tue, 15 Sep 2015 20:16:58 -0500 Subject: [PATCH 3/7] Update test.cpp --- test.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/test.cpp b/test.cpp index 491d9f9..0c956a1 100755 --- a/test.cpp +++ b/test.cpp @@ -1,5 +1,67 @@ +/* #include +#include "DBEngine.h" + +using namespace std; int main() { - std::cout << "Hello World!"; -} \ No newline at end of file + + + //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" + +using namespace std; + +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); +} + From 990dfa0056c04acf298b44132f07c87151aa5853 Mon Sep 17 00:00:00 2001 From: Brandon Jackson <1drummer@att.net> Date: Tue, 15 Sep 2015 20:17:21 -0500 Subject: [PATCH 4/7] Create Attribute.h --- Attribute.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Attribute.h diff --git a/Attribute.h b/Attribute.h new file mode 100644 index 0000000..9d53d4c --- /dev/null +++ b/Attribute.h @@ -0,0 +1,47 @@ +#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; + } + */ +}; From b24f5117f4ddfb071097405cbdb7ea16617d2be8 Mon Sep 17 00:00:00 2001 From: Brandon Jackson <1drummer@att.net> Date: Tue, 15 Sep 2015 20:17:52 -0500 Subject: [PATCH 5/7] Create Relation.h --- Relation.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Relation.h diff --git a/Relation.h b/Relation.h new file mode 100644 index 0000000..c41db03 --- /dev/null +++ b/Relation.h @@ -0,0 +1,47 @@ +#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(); + } +}; From f5db5ac3ecb4f238c86edd533aec3640104255ad Mon Sep 17 00:00:00 2001 From: Brandon Jackson <1drummer@att.net> Date: Tue, 15 Sep 2015 20:19:10 -0500 Subject: [PATCH 6/7] Update and rename db_engine.cpp to DBEngine.cpp --- DBEngine.cpp | 73 ++++++++++++++++++++++++++ db_engine.cpp | 143 -------------------------------------------------- 2 files changed, 73 insertions(+), 143 deletions(-) create mode 100755 DBEngine.cpp delete mode 100755 db_engine.cpp diff --git a/DBEngine.cpp b/DBEngine.cpp new file mode 100755 index 0000000..a854dec --- /dev/null +++ b/DBEngine.cpp @@ -0,0 +1,73 @@ +#include "DBEngine.h" + +using namespace std; + +DBEngine::DBEngine(){ + // +} + +//create a new table in memory +void DBEngine::createCmd(){ + // +} + +//open a txt file, parse SQL script, load data in table +//void DBEngine::openCmd(){ + // +//} + +//should write cmdList to a .txt file +void DBEngine::saveCmd(){ + // +} + +//display the database +void DBEngine::showCmd(){ + // +} + +//add a tuple to a table in the memory +void DBEngine::insertQuery(){ + // +} + +//remove a tuple from a table in the memory +void DBEngine::deleteQuery(){ + // +} + +//search and return one more tuples from a table in the memory +void DBEngine::selectQuery(){ + // +} + +//return a subset of attributes (columns) +/* +vector 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/db_engine.cpp b/db_engine.cpp deleted file mode 100755 index b88d9d4..0000000 --- a/db_engine.cpp +++ /dev/null @@ -1,143 +0,0 @@ -#include "db_engine.h" - -using namespace std; - -db_engine::db_engine(){ - // -} - -//create a new table in memory -//creates a vector -//DONE -void db_engine::createCmd(string tableName, vector attributes, vector pkeys){ - string output = ""; - output += "CREATE TABLE " + tableName + " ("; - - vector::iterator it = attributes.begin(); - while (it != attributes.end()){ - if (it == attributes.begin()) - if ((it + 1) != attributes.end()) - output += *it + ","; - else - output += *it; - else - output+= " " + *it; - - ++it; - } - - output += ") PRIMARY KEY ("; - - vector::iterator it2 = pkeys.begin(); - while (it2 != pkeys.end()){ - if (it2 == pkeys.begin()) - if ((it2 + 1) != pkeys.end()) - output += *it2 + ","; - else - output += *it2; - else - output+= " " + *it2; - - ++it2; - } - - output += ");"; - - cout << output; - //cmdList.push_back(output); -} - -//open a txt file, parse SQL script, load data in table -//void db_engine::openCmd(){ - // -//} - -//should write cmdList to a .txt file -//DONE -void db_engine::saveCmd(){ - ofstream dbCmdFile; - dbCmdFile.open("dbCmds.txt", ios_base::app); - - vector::iterator it = cmdList.begin(); - while (it != cmdList.end()){ - dbCmdFile << *it << "\n"; - ++it; - } - - cmdList.clear(); -} - -//display the database -//DONE -void db_engine::showCmd(string tableName){ - cmdList.push_back("SHOW " + tableName + ""); -} - -//add a tuple to a table in the memory -//BECCA -void db_engine::insertQuery(){ - //table.push_back(); -} - -//remove a tuple from a table in the memory -//BECCA -void db_engine::deleteQuery(){ - // -} - -//search and return one more tuples from a table in the memory -//WILLIAM -void db_engine::selectQuery(){ - // -} - -//return a subset of attributes (columns) -//BRANDON -vector db_engine::projectQuery(vector< vector > table, vector attributes, string query){ - /* - So basically this is what's going on: - - Take the table to iterate through, this is the 2D vector (input 1) - - Take the vector of attributes that pertains to the respective table (input 2) - - Take a string that will be used for the program to search for in the attributes (input 3) - - In the attributes vector, 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 - */ - int counter = 0; //counter for iterating through the attributes, initialized at 0 for reasons - vector result; - - //Loop through the vector until we have found a string in it that matches the query - for(int i=0; i < attributes.size(); i++){ - counter++; - if(attributes[i] == query) - break; - else - continue; - } - - //So let's say we have a 2-D Vector (the table) that contains all of the rows, we iterate through each row - std::vector< std::vector >::const_iterator row; - std::vector::const_iterator col; - - for (row = table.begin(); row != table.end(); ++row) { - //Instead of col != row->end() we have it counter, in order for the program to access the correct data under the correct attribute - for (col = row->begin(); col != counter; col++) { - result.push_back(col); //Now we store that row's attribute into the result vector - } - } - - return result; -} - -//each row in the first table is paired with all the rows in the second table -//BRANDON -vector< vector > db_engine::productQuery(vector< vector > table_1, vector< vector > table_2){ - // -} - -//true if relations have the same # of attributes and each attribute must be from the same domain -//WILLIAM -bool db_engine::unionComp(){ - return false; -} From d28e68beb0f54939cd2557505887b8232e7fe0ce Mon Sep 17 00:00:00 2001 From: Brandon Jackson <1drummer@att.net> Date: Tue, 15 Sep 2015 20:19:49 -0500 Subject: [PATCH 7/7] Update and rename db_engine.h to DBEngine.h --- db_engine.h => DBEngine.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) rename db_engine.h => DBEngine.h (52%) diff --git a/db_engine.h b/DBEngine.h similarity index 52% rename from db_engine.h rename to DBEngine.h index 05e7b60..bd807fe 100755 --- a/db_engine.h +++ b/DBEngine.h @@ -1,19 +1,21 @@ #include #include #include +#include "Relation.h" using namespace std; -class db_engine { - vector cmdList; - //vector> table; +class DBEngine { + //member variables + //NOT DONE + //vector tables; public: - db_engine(); - void createCmd(string tableName, vector attributes, vector pkeys); + DBEngine(); + void createCmd(); //void openCmd(); void saveCmd(); - void showCmd(string tableName); + void showCmd(); void insertQuery(); void deleteQuery(); void selectQuery();