File tree Expand file tree Collapse file tree 3 files changed +42
-1
lines changed
java/net/sf/jsqlparser/statement/alter
jjtree/net/sf/jsqlparser/parser
test/java/net/sf/jsqlparser/test/alter Expand file tree Collapse file tree 3 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -51,6 +51,26 @@ public void setOnDeleteCascade(boolean onDeleteCascade) {
5151 this .onDeleteCascade = onDeleteCascade ;
5252 }
5353
54+ private boolean onDeleteRestrict ;
55+
56+ public boolean isOnDeleteRestrict () {
57+ return onDeleteRestrict ;
58+ }
59+
60+ public void setOnDeleteRestrict (boolean onDeleteRestrict ) {
61+ this .onDeleteRestrict = onDeleteRestrict ;
62+ }
63+
64+ private boolean onDeleteSetNull ;
65+
66+ public boolean isOnDeleteSetNull () {
67+ return onDeleteSetNull ;
68+ }
69+
70+ public void setOnDeleteSetNull (boolean onDeleteSetNull ) {
71+ this .onDeleteSetNull = onDeleteSetNull ;
72+ }
73+
5474 private List <String > fkColumns ;
5575
5676 public List <String > getFkColumns () {
@@ -148,6 +168,10 @@ public String toString() {
148168 b .append ("FOREIGN KEY (" ).append (PlainSelect .getStringList (fkColumns )).append (") REFERENCES " ).append (fkSourceTable ).append (" (" ).append (PlainSelect .getStringList (fkSourceColumns )).append (")" );
149169 if (isOnDeleteCascade ()) {
150170 b .append (" ON DELETE CASCADE" );
171+ } else if (isOnDeleteRestrict ()) {
172+ b .append (" ON DELETE RESTRICT" );
173+ } else if (isOnDeleteSetNull ()) {
174+ b .append (" ON DELETE SET NULL" );
151175 }
152176 }
153177 return b .toString ();
Original file line number Diff line number Diff line change @@ -226,6 +226,7 @@ TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */
226226| <K_MERGE: "MERGE">
227227| <K_MATCHED: "MATCHED">
228228| <K_CASCADE: "CASCADE">
229+ | <K_RESTRICT: "RESTRICT">
229230}
230231
231232TOKEN : /* Numeric Constants */
@@ -2771,7 +2772,11 @@ Alter Alter():
27712772 ( <K_FOREIGN> <K_KEY> columnNames=ColumnsNamesList() { alter.setFkColumns(columnNames); }
27722773 <K_REFERENCES> tk=<S_IDENTIFIER> columnNames=ColumnsNamesList()
27732774 { alter.setFkSourceTable(tk.image); alter.setFkSourceColumns(columnNames); }
2774- [<K_ON> <K_DELETE> <K_CASCADE> { alter.setOnDeleteCascade(true); } ] )
2775+ [<K_ON> <K_DELETE>
2776+ (<K_CASCADE> { alter.setOnDeleteCascade(true); }
2777+ | <K_RESTRICT> { alter.setOnDeleteRestrict(true); }
2778+ | <K_SET> <K_NULL> { alter.setOnDeleteSetNull(true); } ) ]
2779+ )
27752780 )
27762781
27772782 {
Original file line number Diff line number Diff line change @@ -34,4 +34,16 @@ public void testAlterTableUniqueKey() throws JSQLParserException {
3434 public void testAlterTableForgeignKey () throws JSQLParserException {
3535 assertSqlCanBeParsedAndDeparsed ("ALTER TABLE test ADD FOREIGN KEY (user_id) REFERENCES ra_user (id) ON DELETE CASCADE" );
3636 }
37+
38+ public void testAlterTableForgeignKey2 () throws JSQLParserException {
39+ assertSqlCanBeParsedAndDeparsed ("ALTER TABLE test ADD FOREIGN KEY (user_id) REFERENCES ra_user (id)" );
40+ }
41+
42+ public void testAlterTableForgeignKey3 () throws JSQLParserException {
43+ assertSqlCanBeParsedAndDeparsed ("ALTER TABLE test ADD FOREIGN KEY (user_id) REFERENCES ra_user (id) ON DELETE RESTRICT" );
44+ }
45+
46+ public void testAlterTableForgeignKey4 () throws JSQLParserException {
47+ assertSqlCanBeParsedAndDeparsed ("ALTER TABLE test ADD FOREIGN KEY (user_id) REFERENCES ra_user (id) ON DELETE SET NULL" );
48+ }
3749}
You can’t perform that action at this time.
0 commit comments