2015-09-14 15:24:54 -05:00
|
|
|
#include "db_engine.h"
|
2015-09-14 15:22:14 -05:00
|
|
|
|
2015-09-14 18:31:05 -05:00
|
|
|
using namespace std;
|
|
|
|
|
2015-09-14 15:22:14 -05:00
|
|
|
db_engine::db_engine(){
|
2015-09-14 17:03:23 -05:00
|
|
|
//
|
2015-09-14 15:22:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//create a new table in memory
|
2015-09-14 16:25:22 -05:00
|
|
|
//creates a vector
|
2015-09-14 18:39:04 -05:00
|
|
|
//DONE
|
2015-09-14 18:31:05 -05:00
|
|
|
void db_engine::createCmd(string tableName, vector<string> attributes, vector<string> pkeys){
|
2015-09-15 10:21:16 -05:00
|
|
|
//creates the proper command and adds it to the cmdList
|
|
|
|
//make this better, we need a heterogenous container
|
2015-09-14 18:31:05 -05:00
|
|
|
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 += ");";
|
|
|
|
|
2015-09-15 10:21:16 -05:00
|
|
|
cmdList.push_back(output);
|
2015-09-14 15:22:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//open a txt file, parse SQL script, load data in table
|
|
|
|
//void db_engine::openCmd(){
|
|
|
|
//
|
|
|
|
//}
|
|
|
|
|
2015-09-14 16:46:49 -05:00
|
|
|
//should write cmdList to a .txt file
|
2015-09-14 18:39:04 -05:00
|
|
|
//DONE
|
2015-09-14 15:22:14 -05:00
|
|
|
void db_engine::saveCmd(){
|
2015-09-14 18:31:05 -05:00
|
|
|
ofstream dbCmdFile;
|
|
|
|
dbCmdFile.open("dbCmds.txt", ios_base::app);
|
2015-09-14 16:46:49 -05:00
|
|
|
|
2015-09-14 18:31:05 -05:00
|
|
|
vector<string>::iterator it = cmdList.begin();
|
2015-09-14 16:46:49 -05:00
|
|
|
while (it != cmdList.end()){
|
|
|
|
dbCmdFile << *it << "\n";
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmdList.clear();
|
2015-09-14 15:22:14 -05:00
|
|
|
}
|
|
|
|
|
2015-09-14 18:34:55 -05:00
|
|
|
//display the database
|
2015-09-14 18:39:04 -05:00
|
|
|
//DONE
|
2015-09-14 18:31:05 -05:00
|
|
|
void db_engine::showCmd(string tableName){
|
2015-09-14 18:34:55 -05:00
|
|
|
cmdList.push_back("SHOW " + tableName + "");
|
2015-09-14 15:22:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//add a tuple to a table in the memory
|
2015-09-15 10:21:16 -05:00
|
|
|
//maybe make a table object?
|
2015-09-14 18:39:04 -05:00
|
|
|
//BECCA
|
2015-09-15 10:21:16 -05:00
|
|
|
void db_engine::insertQuery(string tableName, vector<string> t){
|
|
|
|
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 + ");");
|
2015-09-14 15:22:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//remove a tuple from a table in the memory
|
2015-09-14 18:39:04 -05:00
|
|
|
//BECCA
|
2015-09-14 15:22:14 -05:00
|
|
|
void db_engine::deleteQuery(){
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
//search and return one more tuples from a table in the memory
|
2015-09-14 18:39:04 -05:00
|
|
|
//WILLIAM
|
2015-09-14 15:22:14 -05:00
|
|
|
void db_engine::selectQuery(){
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
//return a subset of attributes (columns)
|
2015-09-14 18:39:04 -05:00
|
|
|
//BRANDON
|
2015-09-14 15:22:14 -05:00
|
|
|
void db_engine::projectQuery(){
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
//each row in the first table is paired with all the rows in the second table
|
2015-09-14 18:39:04 -05:00
|
|
|
//BRANDON
|
2015-09-14 15:22:14 -05:00
|
|
|
void db_engine::productQuery(){
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
//true if relations have the same # of attributes and each attribute must be from the same domain
|
2015-09-14 18:39:04 -05:00
|
|
|
//WILLIAM
|
2015-09-14 15:22:14 -05:00
|
|
|
bool db_engine::unionComp(){
|
|
|
|
return false;
|
|
|
|
}
|