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-14 18:34:55 -05:00

101 lines
2 KiB
C++
Executable file

#include "db_engine.h"
using namespace std;
db_engine::db_engine(){
//
}
//create a new table in memory
//creates a vector
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
//void db_engine::openCmd(){
//
//}
//should write cmdList to a .txt file
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
void db_engine::showCmd(string tableName){
cmdList.push_back("SHOW " + 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
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;
}