diff --git a/a.out b/a.out index 16a80ad..0ade4b5 100755 Binary files a/a.out and b/a.out differ diff --git a/dbCmds.txt b/dbCmds.txt new file mode 100644 index 0000000..8aae8f5 --- /dev/null +++ b/dbCmds.txt @@ -0,0 +1,2 @@ +CREATE TABLE users (username VARCHAR(20), password VARCHAR(20)) PRIMARY KEY (password); +INSERT INTO users VALUES FROM (csce315, 12345); diff --git a/db_engine.cpp b/db_engine.cpp index ff96c0c..d4060eb 100755 --- a/db_engine.cpp +++ b/db_engine.cpp @@ -10,6 +10,8 @@ db_engine::db_engine(){ //creates a vector //DONE void db_engine::createCmd(string tableName, vector attributes, vector pkeys){ + //creates the proper command and adds it to the cmdList + //make this better, we need a heterogenous container string output = ""; output += "CREATE TABLE " + tableName + " ("; @@ -43,8 +45,7 @@ void db_engine::createCmd(string tableName, vector attributes, vector t){ + string output = "INSERT INTO " + tableName + " VALUES FROM ("; + + vector::iterator it = t.begin(); + while (it != t.end()){ + if (it == t.begin()) + if ((it + 1) != t.end()) + output += *it + ","; + else + output += *it; + else + output+= " " + *it; + + ++it; + } + + cmdList.push_back(output + ");"); } //remove a tuple from a table in the memory diff --git a/db_engine.h b/db_engine.h index e7192d7..e56f754 100755 --- a/db_engine.h +++ b/db_engine.h @@ -14,7 +14,7 @@ public: //void openCmd(); void saveCmd(); void showCmd(string tableName); - void insertQuery(); + void insertQuery(string tableName, vector t); void deleteQuery(); void selectQuery(); void projectQuery(); diff --git a/test.cpp b/test.cpp index a5a6be7..392549b 100755 --- a/test.cpp +++ b/test.cpp @@ -5,11 +5,22 @@ using namespace std; int main() { db_engine engine; - + vector attributes; vector pkeys; + //we need a better way to do this + //going for function right now 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 + + vector tuple; + tuple.push_back("csce315"); + tuple.push_back("12345"); + + engine.insertQuery("users", tuple); + + engine.saveCmd(); +}