Update and rename db_engine.cpp to DBEngine.cpp
This commit is contained in:
parent
b24f5117f4
commit
f5db5ac3ec
2 changed files with 73 additions and 143 deletions
73
DBEngine.cpp
Executable file
73
DBEngine.cpp
Executable file
|
@ -0,0 +1,73 @@
|
|||
#include "DBEngine.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
DBEngine::DBEngine(){
|
||||
//
|
||||
}
|
||||
|
||||
//create a new table in memory
|
||||
void DBEngine::createCmd(){
|
||||
//
|
||||
}
|
||||
|
||||
//open a txt file, parse SQL script, load data in table
|
||||
//void DBEngine::openCmd(){
|
||||
//
|
||||
//}
|
||||
|
||||
//should write cmdList to a .txt file
|
||||
void DBEngine::saveCmd(){
|
||||
//
|
||||
}
|
||||
|
||||
//display the database
|
||||
void DBEngine::showCmd(){
|
||||
//
|
||||
}
|
||||
|
||||
//add a tuple to a table in the memory
|
||||
void DBEngine::insertQuery(){
|
||||
//
|
||||
}
|
||||
|
||||
//remove a tuple from a table in the memory
|
||||
void DBEngine::deleteQuery(){
|
||||
//
|
||||
}
|
||||
|
||||
//search and return one more tuples from a table in the memory
|
||||
void DBEngine::selectQuery(){
|
||||
//
|
||||
}
|
||||
|
||||
//return a subset of attributes (columns)
|
||||
/*
|
||||
vector<string> DBEngine::projectQuery(Relation table, string query){
|
||||
|
||||
/*
|
||||
So basically this is what's going on:
|
||||
- Take the table to iterate through, this is the relation (input 1)
|
||||
- Take a string that will be used for the program to search for in the attributes (input 2)
|
||||
- Iterate through each attribute until the attribute (string) matches the input query
|
||||
- For every iterator, have a counter that counts how many attributes are skipped over in the vector until the attribute is found
|
||||
- This counter will be used to iterate through each vector (row) in the list, skip over that many attributes, and push that into a result vector
|
||||
- Once all vector's elements at the specified attribute are pushed back, return the result vector
|
||||
|
||||
|
||||
for(int i = 0; i < table.getSize(); i++) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
//each row in the first table is paired with all the rows in the second table
|
||||
void DBEngine::productQuery(){
|
||||
//
|
||||
}
|
||||
|
||||
//true if relations have the same # of attributes and each attribute must be from the same domain
|
||||
bool DBEngine::unionComp(){
|
||||
return false;
|
||||
}
|
143
db_engine.cpp
143
db_engine.cpp
|
@ -1,143 +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){
|
||||
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
|
||||
//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
|
||||
//BECCA
|
||||
void db_engine::insertQuery(){
|
||||
//table.push_back();
|
||||
}
|
||||
|
||||
//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
|
||||
vector<string> db_engine::projectQuery(vector< vector<string> > table, vector<string> attributes, string query){
|
||||
/*
|
||||
So basically this is what's going on:
|
||||
- Take the table to iterate through, this is the 2D vector (input 1)
|
||||
- Take the vector of attributes that pertains to the respective table (input 2)
|
||||
- Take a string that will be used for the program to search for in the attributes (input 3)
|
||||
- In the attributes vector, iterate through each attribute until the attribute (string) matches the input query
|
||||
- For every iterator, have a counter that counts how many attributes are skipped over in the vector until the attribute is found
|
||||
- This counter will be used to iterate through each vector (row) in the list, skip over that many attributes, and push that into a result vector
|
||||
- Once all vector's elements at the specified attribute are pushed back, return the result vector
|
||||
*/
|
||||
int counter = 0; //counter for iterating through the attributes, initialized at 0 for reasons
|
||||
vector<string> result;
|
||||
|
||||
//Loop through the vector until we have found a string in it that matches the query
|
||||
for(int i=0; i < attributes.size(); i++){
|
||||
counter++;
|
||||
if(attributes[i] == query)
|
||||
break;
|
||||
else
|
||||
continue;
|
||||
}
|
||||
|
||||
//So let's say we have a 2-D Vector (the table) that contains all of the rows, we iterate through each row
|
||||
std::vector< std::vector<int> >::const_iterator row;
|
||||
std::vector<int>::const_iterator col;
|
||||
|
||||
for (row = table.begin(); row != table.end(); ++row) {
|
||||
//Instead of col != row->end() we have it counter, in order for the program to access the correct data under the correct attribute
|
||||
for (col = row->begin(); col != counter; col++) {
|
||||
result.push_back(col); //Now we store that row's attribute into the result vector
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//each row in the first table is paired with all the rows in the second table
|
||||
//BRANDON
|
||||
vector< vector<string> > db_engine::productQuery(vector< vector<string> > table_1, vector< vector<string> > table_2){
|
||||
//
|
||||
}
|
||||
|
||||
//true if relations have the same # of attributes and each attribute must be from the same domain
|
||||
//WILLIAM
|
||||
bool db_engine::unionComp(){
|
||||
return false;
|
||||
}
|
Reference in a new issue