commit
8a29955094
6 changed files with 125 additions and 73 deletions
37
Attribute.h
Executable file
37
Attribute.h
Executable file
|
@ -0,0 +1,37 @@
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
//Funtional, might need more functionality
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
class Attribute {
|
||||||
|
//a named column of a relation
|
||||||
|
string name;
|
||||||
|
vector<T> values;
|
||||||
|
bool isKey;
|
||||||
|
int size;
|
||||||
|
public:
|
||||||
|
Attribute(){ }
|
||||||
|
|
||||||
|
Attribute(vector<T> v){
|
||||||
|
this.values = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
Attribute(const Attribute<T>& a){
|
||||||
|
this.values = a.getAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
Attribute& operator=(const Attribute<T>& a){
|
||||||
|
this.values = a.getAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
string getName(){
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<T> getAll(){
|
||||||
|
return this.values;
|
||||||
|
}
|
||||||
|
};
|
57
DBEngine.cpp
Executable file
57
DBEngine.cpp
Executable file
|
@ -0,0 +1,57 @@
|
||||||
|
#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)
|
||||||
|
void DBEngine::projectQuery(){
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
//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;
|
||||||
|
}
|
|
@ -1,12 +1,17 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include "Relation.h"
|
||||||
|
|
||||||
class db_engine {
|
using namespace std;
|
||||||
std::vector<std::string> cmdList;
|
|
||||||
|
class DBEngine {
|
||||||
|
//member variables
|
||||||
|
//NOT DONE
|
||||||
|
//vector<Relation> tables;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
db_engine();
|
DBEngine();
|
||||||
void createCmd();
|
void createCmd();
|
||||||
//void openCmd();
|
//void openCmd();
|
||||||
void saveCmd();
|
void saveCmd();
|
16
Relation.h
Executable file
16
Relation.h
Executable file
|
@ -0,0 +1,16 @@
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
#include "Attribute.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
//NOT DONE
|
||||||
|
class Relation {
|
||||||
|
//a table with rows and columns
|
||||||
|
string name;
|
||||||
|
vector< Attribute<T> > att;
|
||||||
|
public:
|
||||||
|
Relation();
|
||||||
|
Relation(vector< Attribute<T> > a) { att = a; }
|
||||||
|
void addTuple(vector< Attribute<T> > tuple);
|
||||||
|
};
|
|
@ -1,65 +0,0 @@
|
||||||
#include "db_engine.h"
|
|
||||||
|
|
||||||
db_engine::db_engine(){
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
//create a new table in memory
|
|
||||||
//creates a vector
|
|
||||||
void db_engine::createCmd(){
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
//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(){
|
|
||||||
std::ofstream dbCmdFile;
|
|
||||||
dbCmdFile.open("dbCmds.txt", std::ios_base::app);
|
|
||||||
|
|
||||||
std::vector<std::string>::iterator it = cmdList.begin();
|
|
||||||
while (it != cmdList.end()){
|
|
||||||
dbCmdFile << *it << "\n";
|
|
||||||
++it;
|
|
||||||
}
|
|
||||||
|
|
||||||
cmdList.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
//display the table currently stored in memory
|
|
||||||
void db_engine::showCmd(){
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
//add a tuple to a table in the memory
|
|
||||||
void db_engine::insertQuery(){
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
//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;
|
|
||||||
}
|
|
12
test.cpp
12
test.cpp
|
@ -1,8 +1,10 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "db_engine.h"
|
#include "DBEngine.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
db_engine engine;
|
DBEngine engine;
|
||||||
engine.saveCmd();
|
Relation r;
|
||||||
std::cout << "succesfully traversed the code!";
|
Attribute<int> a;
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue