Merge branch 'beccadev'
This commit is contained in:
commit
efd560a10e
6 changed files with 68 additions and 11 deletions
23
DBEngine.cpp
23
DBEngine.cpp
|
@ -286,7 +286,7 @@ Relation DBEngine::crossProduct(Relation r1, Relation r2){
|
|||
return new_r;
|
||||
}
|
||||
|
||||
Relation DBEngine::updateCmd(Relation r, string attNameSet, string attSet, string attNameWhere, string attWhere){
|
||||
/*Relation DBEngine::updateCmd(Relation r, string attNameSet, string attSet, string attNameWhere, string attWhere){
|
||||
//brute forcing this, sorry universe
|
||||
//add error matching!!
|
||||
vector<int> inds;
|
||||
|
@ -313,9 +313,18 @@ Relation DBEngine::updateCmd(Relation r, string attNameSet, string attSet, strin
|
|||
|
||||
r.setAttributes(atts);
|
||||
return r;
|
||||
}*/
|
||||
|
||||
void DBEngine::updateCmd(string relationName, string attNameSet, string attSet, string attNameWhere, string attWhere){
|
||||
for(int i = 0; i < tables.size(); i++){
|
||||
if (tables[i].getTableName() == relationName){
|
||||
tables[i].updateCmd(attNameSet, attSet, attNameWhere, attWhere);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Relation DBEngine::deleteCmd(Relation r, string attName, string att){
|
||||
/*Relation DBEngine::deleteCmd(Relation r, string attName, string att){
|
||||
for (int i = 0; i < r.getSize(); ++i){
|
||||
if (r[i].getName() == attName){
|
||||
for (int j = 0; j < r[i].getSize(); ++j){
|
||||
|
@ -326,6 +335,14 @@ Relation DBEngine::deleteCmd(Relation r, string attName, string att){
|
|||
}
|
||||
}
|
||||
|
||||
//r.setAttributes(atts);
|
||||
return r;
|
||||
}*/
|
||||
|
||||
void DBEngine::deleteCmd(string relationName, string attName, string att){
|
||||
for(int i = 0; i < tables.size(); i++){
|
||||
if (tables[i].getTableName() == relationName){
|
||||
tables[i].deleteCmd(attName, att);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,8 @@ public:
|
|||
Relation setUnion(Relation r1, Relation r2);
|
||||
Relation setDiff(Relation r1, Relation r2);
|
||||
Relation crossProduct(Relation r1, Relation r2);
|
||||
Relation updateCmd(Relation r, string attNameSet, string attSet, string attNameWhere, string attWhere);
|
||||
Relation deleteCmd(Relation r, string attName, string att);
|
||||
//Relation updateCmd(Relation r, string attNameSet, string attSet, string attNameWhere, string attWhere);
|
||||
void updateCmd(string relationName, string attNameSet, string attSet, string attNameWhere, string attWhere);
|
||||
//Relation deleteCmd(Relation r, string attName, string att);
|
||||
void deleteCmd(string relationName, string attName, string att);
|
||||
};
|
||||
|
|
36
Relation.cpp
36
Relation.cpp
|
@ -156,4 +156,40 @@ void Relation::removeFromTuple(int rindex, int aindex)
|
|||
{
|
||||
att[rindex].removeCell(aindex);
|
||||
}
|
||||
}
|
||||
|
||||
void Relation::updateCmd(string attNameSet, string attSet, string attNameWhere, string attWhere){
|
||||
vector<int> inds;
|
||||
|
||||
for (int i = 0; i < att.size(); ++i){
|
||||
if (att[i].getName() == attNameWhere){
|
||||
for (int j = 0; j < att[i].getSize(); ++j){
|
||||
if (att[i][j] == attWhere){
|
||||
inds.push_back(j);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < att.size(); ++i){
|
||||
if (att[i].getName() == attNameSet){
|
||||
for (int j = 0; j < inds.size(); ++j){
|
||||
att[i].setValue(attSet, inds[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void Relation::deleteCmd(string attName, string s){
|
||||
for (int i = 0; i < att.size(); ++i){
|
||||
if (att[i].getName() == attName){
|
||||
for (int j = 0; j < att[i].getSize(); ++j){
|
||||
if (att[i][j] == s){
|
||||
removeTuple(j);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -28,4 +28,6 @@ public:
|
|||
void insertFromRelation(Relation r);
|
||||
void removeTuple(int index);
|
||||
void removeFromTuple(int rindex, int aindex);
|
||||
void updateCmd(string attNameSet, string attSet, string attNameWhere, string attWhere);
|
||||
void deleteCmd(string attName, string s);
|
||||
};
|
BIN
a.out
BIN
a.out
Binary file not shown.
12
test.cpp
12
test.cpp
|
@ -1,14 +1,14 @@
|
|||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "Parser.h"
|
||||
#include "Parser.h"
|
||||
//#include "Condition.h"
|
||||
#include "DBEngine.h"
|
||||
//#include "user.h"
|
||||
//#include "user.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main () {
|
||||
DBEngine engine;
|
||||
int main () {
|
||||
DBEngine engine;
|
||||
|
||||
Attribute att1("Breakfast", "VARCHAR(20)", true);
|
||||
Attribute att2("Lunch", "VARCHAR(20)", false);
|
||||
|
@ -33,6 +33,6 @@ int main () {
|
|||
v.push_back(att3);
|
||||
|
||||
engine.createTable("Food", v);
|
||||
Relation temp = engine.deleteCmd(engine.getTableFromName("Food"), "Breakfast", "Pancakes");
|
||||
temp.display();
|
||||
engine.updateCmd("Food", "Dinner", "SUCCESS", "Breakfast", "Pancakes");
|
||||
engine.getTableFromName("Food").display();
|
||||
}
|
||||
|
|
Reference in a new issue