use this frameworkgit rm DBEngine.cpp

This commit is contained in:
Rebecca Schofield 2015-09-15 21:36:52 -05:00
commit 5509e64f00
6 changed files with 172 additions and 246 deletions

View file

@ -1,47 +1,57 @@
#include <iostream> #include <iostream>
#include <vector> #include <vector>
using namespace std; using namespace std;
//Funtional, might need more functionality //Funtional, might need more functionality
//template<typename T> //template<typename T>
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;
Attribute(string n, string t, bool k){
void initializeAttribute(string n, vector<string> a){ name = n;
type = t;
name = n; key = k;
values = a; size = 0;
} }
string getName(){ void addRow(string v) {
return name; values.push_back(v);
} }
Attribute(){ } string getName(){
return name;
void display() }
{
cout<<"Atribute name:\t"<<name<<"\n"; string getType(){
cout<<"Elements: "; return type;
for (int i = 0; i < values.size(); ++i) }
{
cout<<values[i]<<" "; bool isKey(){
} return key;
} }
/* void display()
vector<string> getElements(){ {
return values; cout<<"Atribute name:\t"<<name<<"\n";
} cout<<"Elements: ";
*/
}; for (int i = 0; i < values.size(); ++i)
{
cout<<values[i]<<" ";
}
}
int getSize()
{
return values.size();
}
};

View file

@ -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;
}

View file

@ -3,23 +3,36 @@
#include <vector> #include <vector>
#include "Relation.h" #include "Relation.h"
using namespace std; //still in progress
class DBEngine {
class DBEngine { vector<Relation> tables;
//member variables int size;
//NOT DONE
//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;
}
}; };

View file

@ -1,47 +1,60 @@
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include "Attribute.h" #include "Attribute.h"
using namespace std; //Functional
class Relation {
//NOT DONE string name; //The title the user gives it
class Relation { vector<Attribute> att; //A vector of the columns
//a table with rows and columns
string name; //The title the user gives it public:
vector< Attribute > att; //A vector of the columns Relation();
public: //constructor
Relation(); Relation(string n, vector<Attribute> a) {
name = n;
//constructor att = a;
Relation(string n, vector< Attribute > a) { }
name = n;
att = a; void addTuple(vector<string> tuple) {
} //Loop through the attribute columns
for(int i = 0; i < att.size(); i++) {
void addTuple(vector< string > tuple) {
//Loop through the elements in the i'th column
//Loop through the attribute columns for(int j = 0; j < att[i].values.size(); j++){
for(int i = 0; i < att.size(); i++) {
//In this column, at this element's spot, assign an element from the tuple vector to this spot
//Loop through the elements in the i'th column att[i].addRow(tuple[i]);
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 }
(att[i].values[j]).assign(tuple[i]);
} string getTableName() {
} return name;
} }
void displayTableName() { void displayTableName() {
cout << "The table name is: " << name << endl; cout << "The table name is: " << name << endl;
} }
vector< Attribute > getAttributes(){ vector<Attribute> getAttributes() {
return att; return att;
} }
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

Binary file not shown.

View file

@ -1,67 +1,30 @@
/*
#include <iostream> #include <iostream>
#include "DBEngine.h"
using namespace std;
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 <vector>
#include "Attribute.h" #include "DBEngine.h"
using namespace std; using namespace std;
int main() { //still in progress
int main() {
/*
DBEngine engine; DBEngine engine;
Relation r;
Attribute<int> a;
*/
vector<string> shamWow;
shamWow.push_back("rag");
shamWow.push_back("sponge");
shamWow.push_back("wooow");
shamWow.push_back("cloth");
Attribute atributo;
atributo.initializeAttribute("atributo",shamWow);
atributo.display();
vector<string> doom;
doom.push_back("zombieman");
doom.push_back("revenant");
doom.push_back("imp");
doom.push_back("archvile");
Attribute atributo2;
atributo2.initializeAttribute("attribute_2", doom);
atributo2.display();
string line1 = "Table_1";
//Relation r(line1, my_attributes);
}
Attribute att1("shamWow", "VARCHAR(10)", true);
att1.addRow("rag");
att1.addRow("sponge");
att1.addRow("wooow");
att1.addRow("cloth");
att1.display();
Attribute att2("doom", "VARCHAR(20)", false);
att2.addRow("zombieman");
att2.addRow("revenant");
att2.addRow("imp");
att2.addRow("archvile");
att2.display();
vector<Attribute> vec;
vec.push_back(att1);
vec.push_back(att2);
engine.createTable("table1", vec);
}