new framework
This commit is contained in:
commit
dc3bbcba37
6 changed files with 63 additions and 95 deletions
|
@ -14,7 +14,6 @@ class Attribute {
|
|||
int size;
|
||||
|
||||
public:
|
||||
|
||||
vector<string> values;
|
||||
|
||||
Attribute(string n, string t, bool k){
|
||||
|
@ -44,15 +43,15 @@ public:
|
|||
{
|
||||
cout<<"Atribute name:\t"<<name<<"\n";
|
||||
cout<<"Elements: ";
|
||||
|
||||
for (int i = 0; i < values.size(); ++i)
|
||||
{
|
||||
cout<<values[i]<<" ";
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
vector<string> getElements(){
|
||||
return values;
|
||||
int getSize()
|
||||
{
|
||||
return values.size();
|
||||
}
|
||||
*/
|
||||
};
|
||||
|
|
57
DBEngine.cpp
57
DBEngine.cpp
|
@ -1,57 +0,0 @@
|
|||
#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;
|
||||
}
|
29
DBEngine.h
29
DBEngine.h
|
@ -3,18 +3,35 @@
|
|||
#include <vector>
|
||||
#include "Relation.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
//still in progress
|
||||
class DBEngine {
|
||||
vector<Relation> tables;
|
||||
vector<Relation> tables;
|
||||
int size;
|
||||
|
||||
public:
|
||||
DBEngine();
|
||||
|
||||
void addRelation(Relation r) {
|
||||
DBEngine(){
|
||||
size = 0;
|
||||
}
|
||||
|
||||
void createTable(string n, vector<Attribute> a) {
|
||||
Relation r(n, a);
|
||||
tables.push_back(r);
|
||||
}
|
||||
|
||||
void createTable(Relation r) {
|
||||
tables.push_back(r);
|
||||
}
|
||||
|
||||
void showTable() {}
|
||||
void saveToFile() { /*???*/ }
|
||||
void insertTuple() {}
|
||||
void deleteTuple() {}
|
||||
void selectTuples() {}
|
||||
void project() {}
|
||||
void product() {}
|
||||
void unionComp() {}
|
||||
|
||||
|
||||
vector<Relation> getRelations() {
|
||||
return tables;
|
||||
}
|
||||
|
|
21
Relation.h
21
Relation.h
|
@ -2,9 +2,7 @@
|
|||
#include <vector>
|
||||
#include "Attribute.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
//NOT DONE
|
||||
//Functional
|
||||
class Relation {
|
||||
string name; //The title the user gives it
|
||||
vector<Attribute> att; //A vector of the columns
|
||||
|
@ -18,7 +16,7 @@ public:
|
|||
att = a;
|
||||
}
|
||||
|
||||
void addTuple(vector< string > tuple) {
|
||||
void addTuple(vector<string> tuple) {
|
||||
//Loop through the attribute columns
|
||||
for(int i = 0; i < att.size(); i++) {
|
||||
|
||||
|
@ -39,11 +37,24 @@ public:
|
|||
cout << "The table name is: " << name << endl;
|
||||
}
|
||||
|
||||
vector< Attribute > getAttributes(){
|
||||
vector<Attribute> getAttributes() {
|
||||
return att;
|
||||
}
|
||||
|
||||
int getSize() {
|
||||
return att.size();
|
||||
}
|
||||
|
||||
void display() {
|
||||
cout<<"\n\nDisplay of relation--------------------------------"<<endl;
|
||||
cout<<"Relation name: "<<name<<endl;
|
||||
for (int i = 0; i < att.size(); ++i)
|
||||
{
|
||||
|
||||
cout<<"\nAttribute name: "<<att[i].getName()<<": ";
|
||||
|
||||
att[i].display();
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
BIN
a.out
BIN
a.out
Binary file not shown.
42
test.cpp
42
test.cpp
|
@ -1,30 +1,28 @@
|
|||
#include <iostream>
|
||||
//#include "DBEngine.h"
|
||||
#include <vector>
|
||||
#include "Attribute.h"
|
||||
|
||||
using namespace std;
|
||||
#include "DBEngine.h"
|
||||
|
||||
//still in progress
|
||||
int main() {
|
||||
Attribute atributo("shamWow", "VARCHAR(10)", false);
|
||||
DBEngine engine;
|
||||
|
||||
Attribute att1("shamWow", "VARCHAR(10)", true);
|
||||
att1.addRow("rag");
|
||||
att1.addRow("sponge");
|
||||
att1.addRow("wooow");
|
||||
att1.addRow("cloth");
|
||||
att1.display();
|
||||
|
||||
atributo.addRow("rag");
|
||||
atributo.addRow("sponge");
|
||||
atributo.addRow("wooow");
|
||||
atributo.addRow("cloth");
|
||||
Attribute att2("doom", "VARCHAR(20)", false);
|
||||
att2.addRow("zombieman");
|
||||
att2.addRow("revenant");
|
||||
att2.addRow("imp");
|
||||
att2.addRow("archvile");
|
||||
att2.display();
|
||||
|
||||
atributo.display();
|
||||
vector<Attribute> vec;
|
||||
vec.push_back(att1);
|
||||
vec.push_back(att2);
|
||||
|
||||
Attribute atributo2("doom", "VARCHAR(20)", false);
|
||||
|
||||
atributo2.addRow("zombieman");
|
||||
atributo2.addRow("revenant");
|
||||
atributo2.addRow("imp");
|
||||
atributo2.addRow("archvile");
|
||||
|
||||
atributo2.display();
|
||||
|
||||
string line1 = "Table_1";
|
||||
|
||||
//Relation r(line1, my_attributes);
|
||||
engine.createTable("table1", vec);
|
||||
}
|
||||
|
|
Reference in a new issue