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:31:05 -05:00
|
|
|
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);
|
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 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
|
|
|
}
|
|
|
|
|
|
|
|
//display the table currently stored in memory
|
2015-09-14 18:31:05 -05:00
|
|
|
void db_engine::showCmd(string tableName){
|
|
|
|
cmdList.push_back("CREATE TABLE " + tableName + "");
|
2015-09-14 15:22:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//add a tuple to a table in the memory
|
|
|
|
void db_engine::insertQuery(){
|
2015-09-14 18:31:05 -05:00
|
|
|
//table.push_back();
|
2015-09-14 15:22:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//remove a tuple from a table in the memory
|
|
|
|
void db_engine::deleteQuery(){
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
//search and return one more tuples from a table in the memory
|
|
|
|
void db_engine::selectQuery(){
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
//return a subset of attributes (columns)
|
|
|
|
void db_engine::projectQuery(){
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
//each row in the first table is paired with all the rows in the second table
|
|
|
|
void db_engine::productQuery(){
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
//true if relations have the same # of attributes and each attribute must be from the same domain
|
|
|
|
bool db_engine::unionComp(){
|
|
|
|
return false;
|
|
|
|
}
|