updating structure
This commit is contained in:
parent
30f3484e98
commit
a449b76e21
5 changed files with 139 additions and 20 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;
|
||||||
|
}
|
25
DBEngine.h
Executable file
25
DBEngine.h
Executable file
|
@ -0,0 +1,25 @@
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
#include "Relation.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class DBEngine {
|
||||||
|
//member variables
|
||||||
|
//NOT DONE
|
||||||
|
//vector<Relation> tables;
|
||||||
|
|
||||||
|
public:
|
||||||
|
DBEngine();
|
||||||
|
void createCmd();
|
||||||
|
//void openCmd();
|
||||||
|
void saveCmd();
|
||||||
|
void showCmd();
|
||||||
|
void insertQuery();
|
||||||
|
void deleteQuery();
|
||||||
|
void selectQuery();
|
||||||
|
void projectQuery();
|
||||||
|
void productQuery();
|
||||||
|
bool unionComp();
|
||||||
|
};
|
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);
|
||||||
|
};
|
24
test.cpp
24
test.cpp
|
@ -1,26 +1,10 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "db_engine.h"
|
#include "DBEngine.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
db_engine engine;
|
DBEngine engine;
|
||||||
|
Relation r;
|
||||||
vector<string> attributes;
|
Attribute<int> a;
|
||||||
vector<string> pkeys;
|
|
||||||
//we need a better way to do this
|
|
||||||
//going for function right now
|
|
||||||
attributes.push_back("username VARCHAR(20)");
|
|
||||||
attributes.push_back("password VARCHAR(20)");
|
|
||||||
pkeys.push_back("password");
|
|
||||||
|
|
||||||
engine.createCmd("users", attributes, pkeys);
|
|
||||||
|
|
||||||
vector<string> tuple;
|
|
||||||
tuple.push_back("csce315");
|
|
||||||
tuple.push_back("12345");
|
|
||||||
|
|
||||||
engine.insertQuery("users", tuple);
|
|
||||||
|
|
||||||
engine.saveCmd();
|
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue