got our stuff together

This commit is contained in:
Becca 2015-09-14 18:31:05 -05:00
parent 2b4590ebf4
commit f0d54ab69d
4 changed files with 59 additions and 13 deletions

BIN
a.out Executable file

Binary file not shown.

View file

@ -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<string> attributes, vector<string> pkeys){
string output = "";
output += "CREATE TABLE " + tableName + " (";
vector<string>::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<string>::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<std::string>::iterator it = cmdList.begin();
vector<string>::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

View file

@ -2,15 +2,18 @@
#include <iostream>
#include <vector>
using namespace std;
class db_engine {
std::vector<std::string> cmdList;
vector<string> cmdList;
//vector<vector<string>> table;
public:
db_engine();
void createCmd();
void createCmd(string tableName, vector<string> attributes, vector<string> pkeys);
//void openCmd();
void saveCmd();
void showCmd();
void showCmd(string tableName);
void insertQuery();
void deleteQuery();
void selectQuery();

View file

@ -1,8 +1,15 @@
#include <iostream>
#include "db_engine.h"
using namespace std;
int main() {
db_engine engine;
engine.saveCmd();
std::cout << "succesfully traversed the code!";
vector<string> attributes;
vector<string> pkeys;
attributes.push_back("username VARCHAR(20)");
attributes.push_back("password VARCHAR(20)");
pkeys.push_back("password");
engine.createCmd("users", attributes, pkeys);
}