Skip to content

Commit c89139c

Browse files
committed
fixes #604
1 parent 6527662 commit c89139c

File tree

5 files changed

+92
-3
lines changed

5 files changed

+92
-3
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public class CreateView implements Statement {
3939
private List<String> columnNames = null;
4040
private boolean materialized = false;
4141
private ForceOption force = ForceOption.NONE;
42+
private TemporaryOption temp = TemporaryOption.NONE;
4243

4344
@Override
4445
public void accept(StatementVisitor statementVisitor) {
@@ -107,6 +108,14 @@ public void setForce(ForceOption force) {
107108
this.force = force;
108109
}
109110

111+
public TemporaryOption getTemporary() {
112+
return temp;
113+
}
114+
115+
public void setTemporary(TemporaryOption temp) {
116+
this.temp = temp;
117+
}
118+
110119
@Override
111120
public String toString() {
112121
StringBuilder sql = new StringBuilder("CREATE ");
@@ -121,6 +130,11 @@ public String toString() {
121130
sql.append("NO FORCE ");
122131
break;
123132
}
133+
134+
if (temp != TemporaryOption.NONE) {
135+
sql.append(temp.name()).append(" ");
136+
}
137+
124138
if (isMaterialized()) {
125139
sql.append("MATERIALIZED ");
126140
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2018 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+
/*
23+
* Copyright (C) 2018 JSQLParser.
24+
*
25+
* This library is free software; you can redistribute it and/or
26+
* modify it under the terms of the GNU Lesser General Public
27+
* License as published by the Free Software Foundation; either
28+
* version 2.1 of the License, or (at your option) any later version.
29+
*
30+
* This library is distributed in the hope that it will be useful,
31+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
32+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
33+
* Lesser General Public License for more details.
34+
*
35+
* You should have received a copy of the GNU Lesser General Public
36+
* License along with this library; if not, write to the Free Software
37+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
38+
* MA 02110-1301 USA
39+
*/
40+
package net.sf.jsqlparser.statement.create.view;
41+
42+
/**
43+
*
44+
* @author Tobias Warneke ([email protected])
45+
*/
46+
public enum TemporaryOption {
47+
NONE,
48+
49+
TEMP,
50+
51+
TEMPORARY
52+
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
package net.sf.jsqlparser.util.deparser;
2323

2424
import net.sf.jsqlparser.statement.create.view.CreateView;
25+
import net.sf.jsqlparser.statement.create.view.TemporaryOption;
2526
import net.sf.jsqlparser.statement.select.PlainSelect;
2627
import net.sf.jsqlparser.statement.select.SelectVisitor;
2728

@@ -32,7 +33,7 @@
3233
public class CreateViewDeParser {
3334

3435
private StringBuilder buffer;
35-
private SelectVisitor selectVisitor;
36+
private final SelectVisitor selectVisitor;
3637

3738
/**
3839
* @param buffer the buffer that will be filled with the select
@@ -64,6 +65,9 @@ public void deParse(CreateView createView) {
6465
buffer.append("NO FORCE ");
6566
break;
6667
}
68+
if (createView.getTemporary() != TemporaryOption.NONE) {
69+
buffer.append(createView.getTemporary().name()).append(" ");
70+
}
6771
if (createView.isMaterialized()) {
6872
buffer.append("MATERIALIZED ");
6973
}

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */
264264
| <K_TABLE:"TABLE">
265265
| <K_TABLESPACE : "TABLESPACE">
266266
| <K_THEN:"THEN">
267+
| <K_TEMP:"TEMP">
268+
| <K_TEMPORARY:"TEMPORARY">
267269
| <K_TIME_KEY_EXPR : ( "CURRENT_TIMESTAMP" | "CURRENT_TIME" | "CURRENT_DATE" ) ( "()" )?>
268270
| <K_TOP:"TOP">
269271
| <K_TRUNCATE:"TRUNCATE">
@@ -386,10 +388,10 @@ Statement SingleStatement() :
386388
LOOKAHEAD(CreateIndex())
387389
stm = CreateIndex()
388390
|
389-
LOOKAHEAD(2)
391+
LOOKAHEAD(CreateTable())
390392
stm = CreateTable()
391393
|
392-
LOOKAHEAD(2)
394+
LOOKAHEAD(CreateView())
393395
stm = CreateView()
394396
|
395397
stm = AlterView()
@@ -963,6 +965,7 @@ String RelObjectNameWithoutValue() :
963965
| tk=<K_SEPARATOR> | tk=<K_NO> | tk=<K_ACTION> | tk=<K_CASCADE> | tk=<K_END>
964966
| tk=<K_TABLE> | tk=<K_DATETIMELITERAL> | tk=<K_COMMIT> | tk=<K_PRECISION>
965967
| tk=<K_INSERT> | tk=<K_INDEX> | tk=<K_PRIMARY> | tk=<K_ENABLE>
968+
| tk=<K_TEMP> | tk=<K_TEMPORARY>
966969
)
967970

968971
{ return tk.image; }
@@ -3206,6 +3209,10 @@ CreateView CreateView():
32063209
<K_NO> <K_FORCE> { createView.setForce(ForceOption.NO_FORCE); }
32073210
| <K_FORCE> { createView.setForce(ForceOption.FORCE); }
32083211
]
3212+
[
3213+
<K_TEMP> { createView.setTemporary(TemporaryOption.TEMP); }
3214+
| <K_TEMPORARY> { createView.setTemporary(TemporaryOption.TEMPORARY); }
3215+
]
32093216
[ <K_MATERIALIZED> { createView.setMaterialized(true);} ]
32103217
<K_VIEW> view=Table() { createView.setView(view); }
32113218
[ columnNames = ColumnsNamesList() { createView.setColumnNames(columnNames); } ]
@@ -3300,6 +3307,10 @@ List<String> CreateParameter():
33003307
tk=<K_EXCLUDE> { param.add(tk.image); }
33013308
|
33023309
tk=<K_WHERE> { param.add(tk.image); }
3310+
|
3311+
tk=<K_TEMP> { param.add(tk.image); }
3312+
|
3313+
tk=<K_TEMPORARY> { param.add(tk.image); }
33033314

33043315
)
33053316
{return param;}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,12 @@ public void testCreateForceView2() throws JSQLParserException {
8484
public void testCreateForceView3() throws JSQLParserException {
8585
assertSqlCanBeParsedAndDeparsed("CREATE OR REPLACE NO FORCE VIEW view1 AS SELECT a, b FROM testtab");
8686
}
87+
88+
public void testCreateTemporaryViewIssue604() throws JSQLParserException {
89+
assertSqlCanBeParsedAndDeparsed("CREATE TEMPORARY VIEW myview AS SELECT * FROM mytable");
90+
}
91+
92+
public void testCreateTemporaryViewIssue604_2() throws JSQLParserException {
93+
assertSqlCanBeParsedAndDeparsed("CREATE TEMP VIEW myview AS SELECT * FROM mytable");
94+
}
8795
}

0 commit comments

Comments
 (0)