INSERT command works with VALUES FROM RELATION ...
This commit is contained in:
parent
d56a2ee90e
commit
8d86aec4e0
3 changed files with 14 additions and 2 deletions
14
Parser.cpp
14
Parser.cpp
|
@ -71,6 +71,7 @@ tuple<vector<string>, Relation> expression(vector<string> input, DBEngine &engin
|
|||
input.erase(input.begin());
|
||||
get<0>(t) = input;
|
||||
get<1>(t) = rfinal;
|
||||
//cout << rfinal.getSize() << endl;
|
||||
return t;
|
||||
}
|
||||
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));
|
||||
//get<0>(t) = input;
|
||||
get<1>(t) = rfinal;
|
||||
//cout << rfinal.getSize() << endl;
|
||||
return t;
|
||||
}
|
||||
}
|
||||
|
@ -611,8 +613,16 @@ vector<string> insertCMD(vector<string> input, DBEngine &engine)
|
|||
input.erase(input.begin());
|
||||
|
||||
tuple<vector<string>, Relation> t = expression(input, engine);
|
||||
|
||||
engine.createTable(get<1>(t));
|
||||
vector<Attribute> a = get<1>(t).getAttributes();
|
||||
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);
|
||||
|
||||
|
|
|
@ -82,6 +82,8 @@ void Relation::display(){
|
|||
}
|
||||
|
||||
void Relation::insertTuple(vector<string> tuple){
|
||||
cout << name << " " << size << endl;
|
||||
cout << tuple.size() << endl;
|
||||
if (tuple.size() != this->size) {
|
||||
cout << "Failure to insert: the sizes do not match.";
|
||||
}
|
||||
|
|
BIN
test
BIN
test
Binary file not shown.
Reference in a new issue