updating structure
This commit is contained in:
parent
a449b76e21
commit
0e99c2e305
2 changed files with 0 additions and 150 deletions
127
db_engine.cpp
127
db_engine.cpp
|
@ -1,127 +0,0 @@
|
||||||
#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;
|
|
||||||
}
|
|
23
db_engine.h
23
db_engine.h
|
@ -1,23 +0,0 @@
|
||||||
#include <fstream>
|
|
||||||
#include <iostream>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
class db_engine {
|
|
||||||
vector<string> cmdList;
|
|
||||||
//vector<vector<string>> table;
|
|
||||||
|
|
||||||
public:
|
|
||||||
db_engine();
|
|
||||||
void createCmd(string tableName, vector<string> attributes, vector<string> pkeys);
|
|
||||||
//void openCmd();
|
|
||||||
void saveCmd();
|
|
||||||
void showCmd(string tableName);
|
|
||||||
void insertQuery(string tableName, vector<string> t);
|
|
||||||
void deleteQuery();
|
|
||||||
void selectQuery();
|
|
||||||
void projectQuery();
|
|
||||||
void productQuery();
|
|
||||||
bool unionComp();
|
|
||||||
};
|
|
Reference in a new issue