Skip to content

Commit 5d90186

Browse files
cmoinewumpz
authored andcommitted
Fix #407 by enhancing grammar (#410)
* Fix #407 by enhancing grammar * Change LF and tabs
1 parent dd1b334 commit 5d90186

File tree

7 files changed

+1681
-1448
lines changed

7 files changed

+1681
-1448
lines changed

src/main/java/net/sf/jsqlparser/statement/alter/AlterExpression.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
package net.sf.jsqlparser.statement.alter;
2323

2424

25-
import net.sf.jsqlparser.statement.create.table.ColDataType;
26-
import net.sf.jsqlparser.statement.create.table.Index;
27-
import net.sf.jsqlparser.statement.select.PlainSelect;
28-
2925
import java.util.ArrayList;
3026
import java.util.Collections;
3127
import java.util.List;
3228

29+
import net.sf.jsqlparser.statement.create.table.ColDataType;
30+
import net.sf.jsqlparser.statement.create.table.Index;
31+
import net.sf.jsqlparser.statement.select.PlainSelect;
32+
3333
/**
3434
*
3535
* @author toben & wrobstory
@@ -53,6 +53,8 @@ public class AlterExpression {
5353
private List<String> fkColumns;
5454
private String fkSourceTable;
5555
private List<String> fkSourceColumns;
56+
57+
private List<ConstraintState> constraints;
5658

5759
public AlterOperation getOperation() {
5860
return operation;
@@ -173,6 +175,14 @@ public void setIndex(Index index) {
173175
this.index = index;
174176
}
175177

178+
public List<ConstraintState> getConstraints() {
179+
return constraints;
180+
}
181+
182+
public void setConstraints(List<ConstraintState> constraints) {
183+
this.constraints = constraints;
184+
}
185+
176186
@Override
177187
public String toString() {
178188

@@ -193,7 +203,9 @@ public String toString() {
193203
} else if (constraintName != null) {
194204
b.append("CONSTRAINT ").append(constraintName);
195205
} else if (pkColumns != null) {
196-
b.append("PRIMARY KEY (").append(PlainSelect.getStringList(pkColumns)).append(")");
206+
b.append("PRIMARY KEY (").append(PlainSelect.getStringList(pkColumns)).append(')');
207+
if(getConstraints()!=null && !getConstraints().isEmpty())
208+
b.append(' ').append(PlainSelect.getStringList(constraints, false, false));
197209
} else if (ukColumns != null) {
198210
b.append("UNIQUE KEY ").append(ukName).append(" (").append(PlainSelect.getStringList(ukColumns)).append(")");
199211
} else if (fkColumns != null) {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2017 JSQLParser
6+
* %%
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation, either version 2.1 of the
10+
* License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Lesser Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Lesser Public
18+
* License along with this program. If not, see
19+
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
20+
* #L%
21+
*/
22+
package net.sf.jsqlparser.statement.alter;
23+
24+
/**
25+
* Based on https://docs.oracle.com/cd/B28359_01/server.111/b28286/clauses002.htm#i1002273
26+
*
27+
* @author Christophe Moine
28+
*/
29+
public interface ConstraintState {
30+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2017 JSQLParser
6+
* %%
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation, either version 2.1 of the
10+
* License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Lesser Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Lesser Public
18+
* License along with this program. If not, see
19+
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
20+
* #L%
21+
*/
22+
package net.sf.jsqlparser.statement.alter;
23+
24+
public class DeferrableConstraint implements ConstraintState {
25+
private boolean not;
26+
27+
public DeferrableConstraint(boolean not) {
28+
this.not = not;
29+
}
30+
31+
public boolean isNot() {
32+
return not;
33+
}
34+
35+
public void setNot(boolean not) {
36+
this.not = not;
37+
}
38+
39+
@Override
40+
public String toString() {
41+
StringBuilder b = new StringBuilder();
42+
if(not) {
43+
b.append("NOT ");
44+
}
45+
b.append("DEFERRABLE");
46+
return b.toString();
47+
}
48+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2017 JSQLParser
6+
* %%
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation, either version 2.1 of the
10+
* License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Lesser Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Lesser Public
18+
* License along with this program. If not, see
19+
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
20+
* #L%
21+
*/
22+
package net.sf.jsqlparser.statement.alter;
23+
24+
public class EnableConstraint implements ConstraintState {
25+
private boolean disable;
26+
27+
public EnableConstraint(boolean disable) {
28+
this.disable = disable;
29+
}
30+
31+
public boolean isDisable() {
32+
return disable;
33+
}
34+
35+
public void setDisable(boolean disable) {
36+
this.disable = disable;
37+
}
38+
39+
@Override
40+
public String toString() {
41+
return disable ? "DISABLE" : "ENABLE";
42+
}
43+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2017 JSQLParser
6+
* %%
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation, either version 2.1 of the
10+
* License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Lesser Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Lesser Public
18+
* License along with this program. If not, see
19+
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
20+
* #L%
21+
*/
22+
package net.sf.jsqlparser.statement.alter;
23+
24+
public class ValidateConstraint implements ConstraintState {
25+
private boolean not;
26+
27+
public ValidateConstraint(boolean not) {
28+
this.not = not;
29+
}
30+
31+
public boolean isNot() {
32+
return not;
33+
}
34+
35+
public void setNot(boolean not) {
36+
this.not = not;
37+
}
38+
39+
@Override
40+
public String toString() {
41+
return not ? "NOVALIDATE" : "VALIDATE";
42+
}
43+
}

0 commit comments

Comments
 (0)