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; -}