This commit is contained in:
Becca 2015-09-15 10:21:16 -05:00
parent 7fe87111fc
commit c23f25b20a
5 changed files with 37 additions and 7 deletions

BIN
a.out

Binary file not shown.

2
dbCmds.txt Normal file
View file

@ -0,0 +1,2 @@
CREATE TABLE users (username VARCHAR(20), password VARCHAR(20)) PRIMARY KEY (password);
INSERT INTO users VALUES FROM (csce315, 12345);

View file

@ -10,6 +10,8 @@ db_engine::db_engine(){
//creates a vector //creates a vector
//DONE //DONE
void db_engine::createCmd(string tableName, vector<string> attributes, vector<string> pkeys){ void db_engine::createCmd(string tableName, vector<string> attributes, vector<string> pkeys){
//creates the proper command and adds it to the cmdList
//make this better, we need a heterogenous container
string output = ""; string output = "";
output += "CREATE TABLE " + tableName + " ("; output += "CREATE TABLE " + tableName + " (";
@ -43,8 +45,7 @@ void db_engine::createCmd(string tableName, vector<string> attributes, vector<st
output += ");"; output += ");";
cout << output; cmdList.push_back(output);
//cmdList.push_back(output);
} }
//open a txt file, parse SQL script, load data in table //open a txt file, parse SQL script, load data in table
@ -74,9 +75,25 @@ void db_engine::showCmd(string tableName){
} }
//add a tuple to a table in the memory //add a tuple to a table in the memory
//maybe make a table object?
//BECCA //BECCA
void db_engine::insertQuery(){ void db_engine::insertQuery(string tableName, vector<string> t){
//table.push_back(); string output = "INSERT INTO " + tableName + " VALUES FROM (";
vector<string>::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 //remove a tuple from a table in the memory

View file

@ -14,7 +14,7 @@ public:
//void openCmd(); //void openCmd();
void saveCmd(); void saveCmd();
void showCmd(string tableName); void showCmd(string tableName);
void insertQuery(); void insertQuery(string tableName, vector<string> t);
void deleteQuery(); void deleteQuery();
void selectQuery(); void selectQuery();
void projectQuery(); void projectQuery();

View file

@ -8,8 +8,19 @@ int main() {
vector<string> attributes; vector<string> attributes;
vector<string> pkeys; vector<string> pkeys;
//we need a better way to do this
//going for function right now
attributes.push_back("username VARCHAR(20)"); attributes.push_back("username VARCHAR(20)");
attributes.push_back("password VARCHAR(20)"); attributes.push_back("password VARCHAR(20)");
pkeys.push_back("password"); pkeys.push_back("password");
engine.createCmd("users", attributes, pkeys); engine.createCmd("users", attributes, pkeys);
vector<string> tuple;
tuple.push_back("csce315");
tuple.push_back("12345");
engine.insertQuery("users", tuple);
engine.saveCmd();
} }