Skip to content

Commit 1d1b625

Browse files
committed
fixes #838
1 parent 7567d25 commit 1d1b625

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

src/main/java/net/sf/jsqlparser/statement/create/view/CreateView.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class CreateView implements Statement {
2525
private boolean materialized = false;
2626
private ForceOption force = ForceOption.NONE;
2727
private TemporaryOption temp = TemporaryOption.NONE;
28+
private boolean withReadOnly = false;
2829

2930
@Override
3031
public void accept(StatementVisitor statementVisitor) {
@@ -90,6 +91,14 @@ public void setTemporary(TemporaryOption temp) {
9091
this.temp = temp;
9192
}
9293

94+
public boolean isWithReadOnly() {
95+
return withReadOnly;
96+
}
97+
98+
public void setWithReadOnly(boolean withReadOnly) {
99+
this.withReadOnly = withReadOnly;
100+
}
101+
93102
@Override
94103
public String toString() {
95104
StringBuilder sql = new StringBuilder("CREATE ");
@@ -104,11 +113,11 @@ public String toString() {
104113
sql.append("NO FORCE ");
105114
break;
106115
}
107-
116+
108117
if (temp != TemporaryOption.NONE) {
109118
sql.append(temp.name()).append(" ");
110119
}
111-
120+
112121
if (isMaterialized()) {
113122
sql.append("MATERIALIZED ");
114123
}
@@ -118,6 +127,9 @@ public String toString() {
118127
sql.append(PlainSelect.getStringList(columnNames, true, true));
119128
}
120129
sql.append(" AS ").append(select);
130+
if (isWithReadOnly()) {
131+
sql.append(" WITH READ ONLY");
132+
}
121133
return sql.toString();
122134
}
123135
}

src/main/java/net/sf/jsqlparser/util/deparser/CreateViewDeParser.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public void deParse(CreateView createView) {
7676
buffer.append(" ");
7777
}
7878
createView.getSelect().getSelectBody().accept(selectVisitor);
79+
if (createView.isWithReadOnly()) {
80+
buffer.append(" WITH READ ONLY");
81+
}
7982
}
8083

8184
public StringBuilder getBuffer() {

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */
243243
| <K_PRIMARY:"PRIMARY">
244244
| <K_PRIOR:"PRIOR">
245245
| <K_RANGE: "RANGE">
246+
| <K_READ: "READ" >
246247
| <K_RECURSIVE:"RECURSIVE">
247248
| <K_REFERENCES:"REFERENCES">
248249
| <K_REGEXP: "REGEXP">
@@ -680,10 +681,10 @@ Update Update():
680681
]
681682

682683
{
683-
update.setColumns(columns);
684-
update.setExpressions(expList);
685-
update.setTable(table);
686-
update.setStartJoins(startJoins);
684+
update.setColumns(columns);
685+
update.setExpressions(expList);
686+
update.setTable(table);
687+
update.setStartJoins(startJoins);
687688
update.setFromItem(fromItem);
688689
update.setJoins(joins);
689690
update.setSelect(select);
@@ -1115,6 +1116,7 @@ String RelObjectNameWithoutValue() :
11151116
| tk=<K_TEMP> | tk=<K_TEMPORARY> | tk=<K_TYPE> | tk=<K_ISNULL>
11161117
| tk=<K_ZONE> | tk=<K_COLUMNS> | tk=<K_DESCRIBE> | tk=<K_FN> | tk=<K_PATH>
11171118
| tk=<K_DATE_LITERAL> | tk=<K_NEXTVAL> | tk=<K_TRUE> | tk=<K_FALSE> | tk=<K_DUPLICATE>
1119+
| tk=<K_READ>
11181120
/* | tk=<K_PLACING> | tk=<K_BOTH> | tk=<K_LEADING> | tk=<K_TRAILING> */
11191121
)
11201122

@@ -3785,6 +3787,7 @@ CreateView CreateView():
37853787
[ columnNames = ColumnsNamesList() { createView.setColumnNames(columnNames); } ]
37863788
<K_AS>
37873789
select=Select() { createView.setSelect(select); }
3790+
[ <K_WITH> <K_READ> <K_ONLY> { createView.setWithReadOnly(true); } ]
37883791
{ return createView; }
37893792
}
37903793

src/test/java/net/sf/jsqlparser/statement/create/CreateViewTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,8 @@ public void testCreateTemporaryViewIssue604_2() throws JSQLParserException {
103103
public void testCreateTemporaryViewIssue665() throws JSQLParserException {
104104
assertSqlCanBeParsedAndDeparsed("CREATE VIEW foo(\"BAR\") AS WITH temp AS (SELECT temp_bar FROM foobar) SELECT bar FROM temp");
105105
}
106+
107+
public void testCreateWithReadOnlyViewIssue838() throws JSQLParserException {
108+
assertSqlCanBeParsedAndDeparsed("CREATE VIEW v14(c1, c2) AS SELECT c1, C2 FROM t1 WITH READ ONLY");
109+
}
106110
}

0 commit comments

Comments
 (0)