diff --git a/a.out b/a.out new file mode 100755 index 0000000..16a80ad Binary files /dev/null and b/a.out differ diff --git a/db_engine.cpp b/db_engine.cpp index 10abbbf..c4df4ba 100755 --- a/db_engine.cpp +++ b/db_engine.cpp @@ -1,13 +1,49 @@ #include "db_engine.h" +using namespace std; + db_engine::db_engine(){ // } //create a new table in memory //creates a vector -void db_engine::createCmd(){ - // +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 @@ -17,10 +53,10 @@ void db_engine::createCmd(){ //should write cmdList to a .txt file void db_engine::saveCmd(){ - std::ofstream dbCmdFile; - dbCmdFile.open("dbCmds.txt", std::ios_base::app); + ofstream dbCmdFile; + dbCmdFile.open("dbCmds.txt", ios_base::app); - std::vector::iterator it = cmdList.begin(); + vector::iterator it = cmdList.begin(); while (it != cmdList.end()){ dbCmdFile << *it << "\n"; ++it; @@ -30,13 +66,13 @@ void db_engine::saveCmd(){ } //display the table currently stored in memory -void db_engine::showCmd(){ - // +void db_engine::showCmd(string tableName){ + cmdList.push_back("CREATE TABLE " + tableName + ""); } //add a tuple to a table in the memory void db_engine::insertQuery(){ - // + //table.push_back(); } //remove a tuple from a table in the memory diff --git a/db_engine.h b/db_engine.h index ba2ea28..e7192d7 100755 --- a/db_engine.h +++ b/db_engine.h @@ -2,15 +2,18 @@ #include #include +using namespace std; + class db_engine { - std::vector cmdList; + 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(); diff --git a/test.cpp b/test.cpp index 37541d8..a5a6be7 100755 --- a/test.cpp +++ b/test.cpp @@ -1,8 +1,15 @@ #include #include "db_engine.h" +using namespace std; + int main() { db_engine engine; - engine.saveCmd(); - std::cout << "succesfully traversed the code!"; + + vector attributes; + vector pkeys; + attributes.push_back("username VARCHAR(20)"); + attributes.push_back("password VARCHAR(20)"); + pkeys.push_back("password"); + engine.createCmd("users", attributes, pkeys); } \ No newline at end of file