Skip to content

Commit 0bae629

Browse files
committed
fixes #928
1 parent 6264801 commit 0bae629

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ Also I would like to know about needed examples or documentation stuff.
6666

6767
## Extensions in the latest SNAPSHOT version 3.2
6868

69+
* allow **ON** as a value in a set statement (`SET myvalue = ON`)
70+
* support for **ALTER TABLE ONLY mytable ... **
6971

7072
## Extensions of JSqlParser releases
7173

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
import java.util.ArrayList;
1313
import java.util.Iterator;
1414
import java.util.List;
15-
1615
import net.sf.jsqlparser.schema.Table;
1716
import net.sf.jsqlparser.statement.Statement;
1817
import net.sf.jsqlparser.statement.StatementVisitor;
1918

2019
public class Alter implements Statement {
2120

2221
private Table table;
22+
private boolean useOnly = false;
2323

2424
private List<AlterExpression> alterExpressions;
2525

@@ -31,6 +31,14 @@ public void setTable(Table table) {
3131
this.table = table;
3232
}
3333

34+
public boolean isUseOnly() {
35+
return useOnly;
36+
}
37+
38+
public void setUseOnly(boolean useOnly) {
39+
this.useOnly = useOnly;
40+
}
41+
3442
public void addAlterExpression(AlterExpression alterExpression) {
3543
if (alterExpressions == null) {
3644
alterExpressions = new ArrayList<AlterExpression>();
@@ -55,7 +63,11 @@ public void accept(StatementVisitor statementVisitor) {
5563
public String toString() {
5664

5765
StringBuilder b = new StringBuilder();
58-
b.append("ALTER TABLE ").append(table.getFullyQualifiedName()).append(" ");
66+
b.append("ALTER TABLE ");
67+
if (useOnly) {
68+
b.append("ONLY ");
69+
}
70+
b.append(table.getFullyQualifiedName()).append(" ");
5971

6072
Iterator<AlterExpression> altIter = alterExpressions.iterator();
6173

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4378,7 +4378,7 @@ Alter AlterTable():
43784378

43794379
}
43804380
{
4381-
<K_ALTER> <K_TABLE> table=Table() { alter.setTable(table); }
4381+
<K_ALTER> <K_TABLE> [ <K_ONLY> { alter.setUseOnly(true); } ] table=Table() { alter.setTable(table); }
43824382
( alterExp=AlterExpression() { alter.addAlterExpression(alterExp); }
43834383
("," alterExp=AlterExpression() { alter.addAlterExpression(alterExp); } )*
43844384
)

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,4 +388,9 @@ public void testIssue259() throws JSQLParserException {
388388
public void testIssue633_2() throws JSQLParserException {
389389
assertSqlCanBeParsedAndDeparsed("CREATE INDEX idx_american_football_action_plays_1 ON american_football_action_plays USING btree (play_type)");
390390
}
391+
392+
@Test
393+
public void testAlterOnlyIssue928() throws JSQLParserException {
394+
assertSqlCanBeParsedAndDeparsed("ALTER TABLE ONLY categories ADD CONSTRAINT pk_categories PRIMARY KEY (category_id)");
395+
}
391396
}

0 commit comments

Comments
 (0)