grammar: Add support for parsing multiple FKs in column constraints

This adds support for multiple foreign keys in a column constraint.
Example:

CREATE TABLE t1(a int, b int);
CREATE TABLE t2(a int, b int);
CREATE TABLE test(
    x int REFERENCES t1(a) REFERENCES t2(a),	-- This is now supported
    y int
);

Multiple foreign keys if they are a table constraint were already
supported before.
This commit is contained in:
Martin Kleusberg
2017-09-15 11:00:25 +02:00
parent d73fbfc156
commit 677d36074a

View File

@@ -929,7 +929,7 @@ void CreateTableWalker::parsecolumn(Table* table, antlr::RefAST c)
QString check;
QString collation;
sqlb::PrimaryKeyConstraint* primaryKey = nullptr;
sqlb::ForeignKeyClause* foreignKey = nullptr;
QVector<sqlb::ForeignKeyClause*> foreignKeys;
colname = columnname(c);
c = c->getNextSibling(); //type?
@@ -1028,7 +1028,7 @@ void CreateTableWalker::parsecolumn(Table* table, antlr::RefAST c)
{
con = con->getNextSibling(); // REFERENCES
foreignKey = new ForeignKeyClause;
sqlb::ForeignKeyClause* foreignKey = new ForeignKeyClause;
foreignKey->setTable(identifier(con));
foreignKey->setName(constraint_name);
con = con->getNextSibling(); // identifier
@@ -1050,6 +1050,7 @@ void CreateTableWalker::parsecolumn(Table* table, antlr::RefAST c)
}
foreignKey->setConstraint(concatTextAST(con, true));
foreignKeys.push_back(foreignKey);
}
break;
case sqlite3TokenTypes::COLLATE:
@@ -1073,8 +1074,8 @@ void CreateTableWalker::parsecolumn(Table* table, antlr::RefAST c)
f->setAutoIncrement(autoincrement);
table->addField(f);
if(foreignKey)
table->addConstraint({f}, ConstraintPtr(foreignKey));
foreach(sqlb::ForeignKeyClause* fk, foreignKeys)
table->addConstraint({f}, ConstraintPtr(fk));
if(primaryKey)
{
FieldVector v;