Skip to content

Commit 677d360

Browse files
committed
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.
1 parent d73fbfc commit 677d360

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/sqlitetypes.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ void CreateTableWalker::parsecolumn(Table* table, antlr::RefAST c)
929929
QString check;
930930
QString collation;
931931
sqlb::PrimaryKeyConstraint* primaryKey = nullptr;
932-
sqlb::ForeignKeyClause* foreignKey = nullptr;
932+
QVector<sqlb::ForeignKeyClause*> foreignKeys;
933933

934934
colname = columnname(c);
935935
c = c->getNextSibling(); //type?
@@ -1028,7 +1028,7 @@ void CreateTableWalker::parsecolumn(Table* table, antlr::RefAST c)
10281028
{
10291029
con = con->getNextSibling(); // REFERENCES
10301030

1031-
foreignKey = new ForeignKeyClause;
1031+
sqlb::ForeignKeyClause* foreignKey = new ForeignKeyClause;
10321032
foreignKey->setTable(identifier(con));
10331033
foreignKey->setName(constraint_name);
10341034
con = con->getNextSibling(); // identifier
@@ -1050,6 +1050,7 @@ void CreateTableWalker::parsecolumn(Table* table, antlr::RefAST c)
10501050
}
10511051

10521052
foreignKey->setConstraint(concatTextAST(con, true));
1053+
foreignKeys.push_back(foreignKey);
10531054
}
10541055
break;
10551056
case sqlite3TokenTypes::COLLATE:
@@ -1073,8 +1074,8 @@ void CreateTableWalker::parsecolumn(Table* table, antlr::RefAST c)
10731074
f->setAutoIncrement(autoincrement);
10741075
table->addField(f);
10751076

1076-
if(foreignKey)
1077-
table->addConstraint({f}, ConstraintPtr(foreignKey));
1077+
foreach(sqlb::ForeignKeyClause* fk, foreignKeys)
1078+
table->addConstraint({f}, ConstraintPtr(fk));
10781079
if(primaryKey)
10791080
{
10801081
FieldVector v;

0 commit comments

Comments
 (0)