use this frameworkgit rm DBEngine.cpp
This commit is contained in:
commit
5509e64f00
6 changed files with 172 additions and 246 deletions
32
Attribute.h
32
Attribute.h
|
@ -9,39 +9,49 @@ using namespace std;
|
||||||
class Attribute {
|
class Attribute {
|
||||||
//a named column of a relation
|
//a named column of a relation
|
||||||
string name;
|
string name;
|
||||||
|
string type;
|
||||||
bool isKey;
|
bool key;
|
||||||
int size;
|
int size;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
vector<string> values;
|
vector<string> values;
|
||||||
|
|
||||||
void initializeAttribute(string n, vector<string> a){
|
Attribute(string n, string t, bool k){
|
||||||
|
|
||||||
name = n;
|
name = n;
|
||||||
values = a;
|
type = t;
|
||||||
|
key = k;
|
||||||
|
size = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void addRow(string v) {
|
||||||
|
values.push_back(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
string getName(){
|
string getName(){
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
Attribute(){ }
|
string getType(){
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isKey(){
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
void display()
|
void display()
|
||||||
{
|
{
|
||||||
cout<<"Atribute name:\t"<<name<<"\n";
|
cout<<"Atribute name:\t"<<name<<"\n";
|
||||||
cout<<"Elements: ";
|
cout<<"Elements: ";
|
||||||
|
|
||||||
for (int i = 0; i < values.size(); ++i)
|
for (int i = 0; i < values.size(); ++i)
|
||||||
{
|
{
|
||||||
cout<<values[i]<<" ";
|
cout<<values[i]<<" ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
int getSize()
|
||||||
vector<string> getElements(){
|
{
|
||||||
return values;
|
return values.size();
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
};
|
};
|
||||||
|
|
73
DBEngine.cpp
73
DBEngine.cpp
|
@ -1,73 +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)
|
|
||||||
/*
|
|
||||||
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;
|
|
||||||
}
|
|
45
DBEngine.h
45
DBEngine.h
|
@ -3,23 +3,36 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "Relation.h"
|
#include "Relation.h"
|
||||||
|
|
||||||
using namespace std;
|
//still in progress
|
||||||
|
|
||||||
class DBEngine {
|
class DBEngine {
|
||||||
//member variables
|
vector<Relation> tables;
|
||||||
//NOT DONE
|
int size;
|
||||||
//vector<Relation> tables;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DBEngine();
|
DBEngine(){
|
||||||
void createCmd();
|
size = 0;
|
||||||
//void openCmd();
|
}
|
||||||
void saveCmd();
|
|
||||||
void showCmd();
|
void createTable(string n, vector<Attribute> a) {
|
||||||
void insertQuery();
|
Relation r(n, a);
|
||||||
void deleteQuery();
|
tables.push_back(r);
|
||||||
void selectQuery();
|
}
|
||||||
void projectQuery();
|
|
||||||
void productQuery();
|
void createTable(Relation r) {
|
||||||
bool unionComp();
|
tables.push_back(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
void showTable() { /*Becca*/ }
|
||||||
|
void saveToFile() { /*Becca*/ }
|
||||||
|
void insertTuple() { /*William*/ }
|
||||||
|
void deleteTuple() { /*William*/ }
|
||||||
|
void selectTuples() { /*Becca*/ }
|
||||||
|
void project() { /*Brandon*/ }
|
||||||
|
void product() { /*Brandon*/ }
|
||||||
|
void unionComp() { /*William*/ }
|
||||||
|
|
||||||
|
|
||||||
|
vector<Relation> getRelations() {
|
||||||
|
return tables;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
25
Relation.h
25
Relation.h
|
@ -2,11 +2,8 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "Attribute.h"
|
#include "Attribute.h"
|
||||||
|
|
||||||
using namespace std;
|
//Functional
|
||||||
|
|
||||||
//NOT DONE
|
|
||||||
class Relation {
|
class Relation {
|
||||||
//a table with rows and columns
|
|
||||||
string name; //The title the user gives it
|
string name; //The title the user gives it
|
||||||
vector<Attribute> att; //A vector of the columns
|
vector<Attribute> att; //A vector of the columns
|
||||||
|
|
||||||
|
@ -20,7 +17,6 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void addTuple(vector<string> tuple) {
|
void addTuple(vector<string> tuple) {
|
||||||
|
|
||||||
//Loop through the attribute columns
|
//Loop through the attribute columns
|
||||||
for(int i = 0; i < att.size(); i++) {
|
for(int i = 0; i < att.size(); i++) {
|
||||||
|
|
||||||
|
@ -28,11 +24,15 @@ public:
|
||||||
for(int j = 0; j < att[i].values.size(); j++){
|
for(int j = 0; j < att[i].values.size(); j++){
|
||||||
|
|
||||||
//In this column, at this element's spot, assign an element from the tuple vector to this spot
|
//In this column, at this element's spot, assign an element from the tuple vector to this spot
|
||||||
(att[i].values[j]).assign(tuple[i]);
|
att[i].addRow(tuple[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string getTableName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
void displayTableName() {
|
void displayTableName() {
|
||||||
cout << "The table name is: " << name << endl;
|
cout << "The table name is: " << name << endl;
|
||||||
}
|
}
|
||||||
|
@ -44,4 +44,17 @@ public:
|
||||||
int getSize() {
|
int getSize() {
|
||||||
return att.size();
|
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
Executable file
BIN
a.out
Executable file
Binary file not shown.
73
test.cpp
73
test.cpp
|
@ -1,67 +1,30 @@
|
||||||
/*
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
#include "DBEngine.h"
|
#include "DBEngine.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
//still in progress
|
||||||
int main() {
|
int main() {
|
||||||
|
|
||||||
|
|
||||||
//DBEngine engine;
|
|
||||||
vector<string> my_vector = {"Name", "Grade", "Happiness"};
|
|
||||||
string at1 = "Name", at2 = "Grade", at3 = "Happiness";
|
|
||||||
|
|
||||||
|
|
||||||
Attribute<string> attribute_1(at1);//, attribute_2(at2), attribute_3(at3);
|
|
||||||
|
|
||||||
|
|
||||||
//Relation r(line1, my_attributes);
|
|
||||||
|
|
||||||
//r.displayTableName();
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
//#include "DBEngine.h"
|
|
||||||
#include <vector>
|
|
||||||
#include "Attribute.h"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
|
|
||||||
/*
|
|
||||||
DBEngine engine;
|
DBEngine engine;
|
||||||
Relation r;
|
|
||||||
Attribute<int> a;
|
|
||||||
*/
|
|
||||||
|
|
||||||
vector<string> shamWow;
|
Attribute att1("shamWow", "VARCHAR(10)", true);
|
||||||
shamWow.push_back("rag");
|
att1.addRow("rag");
|
||||||
shamWow.push_back("sponge");
|
att1.addRow("sponge");
|
||||||
shamWow.push_back("wooow");
|
att1.addRow("wooow");
|
||||||
shamWow.push_back("cloth");
|
att1.addRow("cloth");
|
||||||
|
att1.display();
|
||||||
|
|
||||||
Attribute atributo;
|
Attribute att2("doom", "VARCHAR(20)", false);
|
||||||
atributo.initializeAttribute("atributo",shamWow);
|
att2.addRow("zombieman");
|
||||||
atributo.display();
|
att2.addRow("revenant");
|
||||||
|
att2.addRow("imp");
|
||||||
|
att2.addRow("archvile");
|
||||||
|
att2.display();
|
||||||
|
|
||||||
vector<string> doom;
|
vector<Attribute> vec;
|
||||||
doom.push_back("zombieman");
|
vec.push_back(att1);
|
||||||
doom.push_back("revenant");
|
vec.push_back(att2);
|
||||||
doom.push_back("imp");
|
|
||||||
doom.push_back("archvile");
|
|
||||||
|
|
||||||
Attribute atributo2;
|
engine.createTable("table1", vec);
|
||||||
atributo2.initializeAttribute("attribute_2", doom);
|
|
||||||
atributo2.display();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
string line1 = "Table_1";
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Relation r(line1, my_attributes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue