delete working
This commit is contained in:
parent
4515a7073b
commit
25ce3c7248
6 changed files with 36 additions and 9 deletions
12
DBEngine.cpp
12
DBEngine.cpp
|
@ -315,7 +315,7 @@ Relation DBEngine::updateCmd(Relation r, string attNameSet, string attSet, strin
|
|||
return r;
|
||||
}
|
||||
|
||||
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 +326,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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,5 +32,6 @@ public:
|
|||
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 deleteCmd(Relation r, string attName, string att);
|
||||
void deleteCmd(string relationName, string attName, string att);
|
||||
};
|
||||
|
|
16
Relation.cpp
16
Relation.cpp
|
@ -156,4 +156,20 @@ void Relation::removeFromTuple(int rindex, int aindex)
|
|||
{
|
||||
att[rindex].removeCell(aindex);
|
||||
}
|
||||
}
|
||||
|
||||
void Relation::updateCmd(){
|
||||
//
|
||||
}
|
||||
|
||||
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();
|
||||
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.deleteCmd("Food", "Breakfast", "Pancakes");
|
||||
engine.getTableFromName("Food").display();
|
||||
}
|
||||
|
|
Reference in a new issue