INSERT command works with VALUES FROM RELATION ...

This commit is contained in:
Alexander Huddleston 2015-09-29 15:21:51 -05:00
parent d56a2ee90e
commit 8d86aec4e0
3 changed files with 14 additions and 2 deletions

View file

@ -71,6 +71,7 @@ tuple<vector<string>, Relation> expression(vector<string> input, DBEngine &engin
input.erase(input.begin()); input.erase(input.begin());
get<0>(t) = input; get<0>(t) = input;
get<1>(t) = rfinal; get<1>(t) = rfinal;
//cout << rfinal.getSize() << endl;
return t; return t;
} }
else if(input[0] == "(") else if(input[0] == "(")
@ -79,6 +80,7 @@ tuple<vector<string>, Relation> expression(vector<string> input, DBEngine &engin
rfinal = engine.projection(temp, get<1>(t)); rfinal = engine.projection(temp, get<1>(t));
//get<0>(t) = input; //get<0>(t) = input;
get<1>(t) = rfinal; get<1>(t) = rfinal;
//cout << rfinal.getSize() << endl;
return t; return t;
} }
} }
@ -611,8 +613,16 @@ vector<string> insertCMD(vector<string> input, DBEngine &engine)
input.erase(input.begin()); input.erase(input.begin());
tuple<vector<string>, Relation> t = expression(input, engine); tuple<vector<string>, Relation> t = expression(input, engine);
vector<Attribute> a = get<1>(t).getAttributes();
engine.createTable(get<1>(t)); for(int y = 0; y < a[0].getSize(); ++y)
{
for(int x = 0; x < a.size(); ++x)
{
s.push_back(a[x].getValues()[y]);
engine.insertValues(r.getTableName(), s);
s.clear();
}
}
input = get<0>(t); input = get<0>(t);

View file

@ -82,6 +82,8 @@ void Relation::display(){
} }
void Relation::insertTuple(vector<string> tuple){ void Relation::insertTuple(vector<string> tuple){
cout << name << " " << size << endl;
cout << tuple.size() << endl;
if (tuple.size() != this->size) { if (tuple.size() != this->size) {
cout << "Failure to insert: the sizes do not match."; cout << "Failure to insert: the sizes do not match.";
} }

BIN
test

Binary file not shown.