Skip to content

Commit d79b44d

Browse files
committed
fixes #981
1 parent 08b9477 commit d79b44d

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4420,6 +4420,10 @@ AlterExpression AlterExpression():
44204420
fkIndex.setReferencedColumnNames(columnNames);
44214421
alterExp.setIndex(fkIndex);
44224422
}
4423+
[<K_ON> <K_DELETE>
4424+
(<K_CASCADE> { fkIndex.setOnDeleteReferenceOption("CASCADE"); }
4425+
| <K_RESTRICT> { fkIndex.setOnDeleteReferenceOption("RESTRICT"); }
4426+
| <K_SET> <K_NULL> { fkIndex.setOnDeleteReferenceOption("SET NULL"); } ) ]
44234427
constraints=AlterExpressionConstraintState() { alterExp.setConstraints(constraints); }
44244428
)
44254429
|

src/test/java/net/sf/jsqlparser/statement/alter/AlterTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,4 +414,19 @@ public void testAlterTableRenameColumn() throws JSQLParserException {
414414
assertEquals(expression.getColOldName(), "\"test_column\"");
415415
assertEquals(expression.getColumnName(), "\"test_c\"");
416416
}
417+
418+
@Test
419+
public void testAlterTableForeignKeyIssue981() throws JSQLParserException {
420+
assertSqlCanBeParsedAndDeparsed(
421+
"ALTER TABLE atconfigpro " +
422+
"ADD CONSTRAINT atconfigpro_atconfignow_id_foreign FOREIGN KEY (atconfignow_id) REFERENCES atconfignow(id) ON DELETE CASCADE, " +
423+
"ADD CONSTRAINT atconfigpro_attariff_id_foreign FOREIGN KEY (attariff_id) REFERENCES attariff(id) ON DELETE CASCADE");
424+
}
425+
426+
@Test
427+
public void testAlterTableForeignKeyIssue981_2() throws JSQLParserException {
428+
assertSqlCanBeParsedAndDeparsed(
429+
"ALTER TABLE atconfigpro " +
430+
"ADD CONSTRAINT atconfigpro_atconfignow_id_foreign FOREIGN KEY (atconfignow_id) REFERENCES atconfignow(id) ON DELETE CASCADE");
431+
}
417432
}

0 commit comments

Comments
 (0)