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 <vector>
using namespace std;
//Funtional, might need more functionality
//template<typename T>
class Attribute {
//a named column of a relation
string name;
bool isKey;
int size;
public:
vector<string> values;
void initializeAttribute(string n, vector<string> a){
name = n;
values = a;
}
string getName(){
return name;
}
Attribute(){ }
void display()
{
cout<<"Atribute name:\t"<<name<<"\n";
cout<<"Elements: ";
for (int i = 0; i < values.size(); ++i)
{
cout<<values[i]<<" ";
}
}
/*
vector<string> getElements(){
return values;
}
*/
};
#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;
string type;
bool key;
int size;
public:
vector<string> values;
Attribute(string n, string t, bool k){
name = n;
type = t;
key = k;
size = 0;
}
void addRow(string v) {
values.push_back(v);
}
string getName(){
return name;
}
string getType(){
return type;
}
bool isKey(){
return key;
}
void display()
{
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 "Relation.h"
using namespace std;
class DBEngine {
//member variables
//NOT DONE
//vector<Relation> tables;
//still in progress
class DBEngine {
vector<Relation> tables;
int size;
public:
DBEngine();
void createCmd();
//void openCmd();
void saveCmd();
void showCmd();
void insertQuery();
void deleteQuery();
void selectQuery();
void projectQuery();
void productQuery();
bool unionComp();
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() { /*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 <vector>
#include "Attribute.h"
using namespace std;
//NOT DONE
class Relation {
//a table with rows and columns
string name; //The title the user gives it
vector< Attribute > att; //A vector of the columns
public:
Relation();
//constructor
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++) {
//Loop through the elements in the i'th column
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]);
}
}
}
void displayTableName() {
cout << "The table name is: " << name << endl;
}
vector< Attribute > getAttributes(){
return att;
}
int getSize() {
return att.size();
}
};
#include <iostream>
#include <vector>
#include "Attribute.h"
//Functional
class Relation {
string name; //The title the user gives it
vector<Attribute> att; //A vector of the columns
public:
Relation();
//constructor
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++) {
//Loop through the elements in the i'th column
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].addRow(tuple[i]);
}
}
}
string getTableName() {
return name;
}
void displayTableName() {
cout << "The table name is: " << name << endl;
}
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 Executable file

Binary file not shown.

View file

@ -1,67 +1,30 @@
/*
#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 "Attribute.h"
#include "DBEngine.h"
using namespace std;
int main() {
/*
//still in progress
int main() {
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);
}