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 @@ -53,6 +53,26 @@ public void setOnDeleteCascade(boolean onDeleteCascade) {
53
53
this .onDeleteCascade = onDeleteCascade ;
54
54
}
55
55
56
+ private boolean onDeleteRestrict ;
57
+
58
+ public boolean isOnDeleteRestrict () {
59
+ return onDeleteRestrict ;
60
+ }
61
+
62
+ public void setOnDeleteRestrict (boolean onDeleteRestrict ) {
63
+ this .onDeleteRestrict = onDeleteRestrict ;
64
+ }
65
+
66
+ private boolean onDeleteSetNull ;
67
+
68
+ public boolean isOnDeleteSetNull () {
69
+ return onDeleteSetNull ;
70
+ }
71
+
72
+ public void setOnDeleteSetNull (boolean onDeleteSetNull ) {
73
+ this .onDeleteSetNull = onDeleteSetNull ;
74
+ }
75
+
56
76
private List <String > fkColumns ;
57
77
58
78
public List <String > getFkColumns () {
@@ -159,6 +179,10 @@ public String toString() {
159
179
PlainSelect .getStringList (fkSourceColumns )).append (")" );
160
180
if (isOnDeleteCascade ()) {
161
181
b .append (" ON DELETE CASCADE" );
182
+ } else if (isOnDeleteRestrict ()) {
183
+ b .append (" ON DELETE RESTRICT" );
184
+ } else if (isOnDeleteSetNull ()) {
185
+ b .append (" ON DELETE SET NULL" );
162
186
}
163
187
} else if (fkIndex != null ) {
164
188
b .append (fkIndex );
Original file line number Diff line number Diff line change @@ -226,6 +226,7 @@ TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */
226
226
| <K_MERGE: "MERGE">
227
227
| <K_MATCHED: "MATCHED">
228
228
| <K_CASCADE: "CASCADE">
229
+ | <K_RESTRICT: "RESTRICT">
229
230
}
230
231
231
232
TOKEN : /* Numeric Constants */
@@ -2775,7 +2776,11 @@ Alter Alter():
2775
2776
( <K_FOREIGN> <K_KEY> columnNames=ColumnsNamesList() { alter.setFkColumns(columnNames); }
2776
2777
<K_REFERENCES> tk=<S_IDENTIFIER> columnNames=ColumnsNamesList()
2777
2778
{ alter.setFkSourceTable(tk.image); alter.setFkSourceColumns(columnNames); }
2778
- [<K_ON> <K_DELETE> <K_CASCADE> { alter.setOnDeleteCascade(true); } ] )
2779
+ [<K_ON> <K_DELETE>
2780
+ (<K_CASCADE> { alter.setOnDeleteCascade(true); }
2781
+ | <K_RESTRICT> { alter.setOnDeleteRestrict(true); }
2782
+ | <K_SET> <K_NULL> { alter.setOnDeleteSetNull(true); } ) ]
2783
+ )
2779
2784
|
2780
2785
(
2781
2786
{
Original file line number Diff line number Diff line change @@ -38,4 +38,16 @@ public void testAlterTableForgeignKey() throws JSQLParserException {
38
38
public void testAlterTableAddConstraint () throws JSQLParserException {
39
39
assertSqlCanBeParsedAndDeparsed ("ALTER TABLE RESOURCELINKTYPE ADD CONSTRAINT FK_RESOURCELINKTYPE_PARENTTYPE_PRIMARYKEY FOREIGN KEY (PARENTTYPE_PRIMARYKEY) REFERENCES RESOURCETYPE(PRIMARYKEY)" );
40
40
}
41
+
42
+ public void testAlterTableForgeignKey2 () throws JSQLParserException {
43
+ assertSqlCanBeParsedAndDeparsed ("ALTER TABLE test ADD FOREIGN KEY (user_id) REFERENCES ra_user (id)" );
44
+ }
45
+
46
+ public void testAlterTableForgeignKey3 () throws JSQLParserException {
47
+ assertSqlCanBeParsedAndDeparsed ("ALTER TABLE test ADD FOREIGN KEY (user_id) REFERENCES ra_user (id) ON DELETE RESTRICT" );
48
+ }
49
+
50
+ public void testAlterTableForgeignKey4 () throws JSQLParserException {
51
+ assertSqlCanBeParsedAndDeparsed ("ALTER TABLE test ADD FOREIGN KEY (user_id) REFERENCES ra_user (id) ON DELETE SET NULL" );
52
+ }
41
53
}
You can’t perform that action at this time.
0 commit comments