This repository has been archived on 2025-04-11. You can view files and clone it, but cannot push or open issues or pull requests.
dmspine64backup/db_engine.cpp
2015-09-15 10:21:16 -05:00

127 lines
2.6 KiB
C++
Executable file

#include "db_engine.h"
using namespace std;
db_engine::db_engine(){
//
}
//create a new table in memory
//creates a vector
//DONE
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 = "";
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 += ");";
cmdList.push_back(output);
}
//open a txt file, parse SQL script, load data in table
//void db_engine::openCmd(){
//
//}
//should write cmdList to a .txt file
//DONE
void db_engine::saveCmd(){
ofstream dbCmdFile;
dbCmdFile.open("dbCmds.txt", ios_base::app);
vector<string>::iterator it = cmdList.begin();
while (it != cmdList.end()){
dbCmdFile << *it << "\n";
++it;
}
cmdList.clear();
}
//display the database
//DONE
void db_engine::showCmd(string tableName){
cmdList.push_back("SHOW " + tableName + "");
}
//add a tuple to a table in the memory
//maybe make a table object?
//BECCA
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 + ");");
}
//remove a tuple from a table in the memory
//BECCA
void db_engine::deleteQuery(){
//
}
//search and return one more tuples from a table in the memory
//WILLIAM
void db_engine::selectQuery(){
//
}
//return a subset of attributes (columns)
//BRANDON
void db_engine::projectQuery(){
//
}
//each row in the first table is paired with all the rows in the second table
//BRANDON
void db_engine::productQuery(){
//
}
//true if relations have the same # of attributes and each attribute must be from the same domain
//WILLIAM
bool db_engine::unionComp(){
return false;
}