File tree Expand file tree Collapse file tree 3 files changed +20
-1
lines changed
java/net/sf/jsqlparser/statement/create/schema
jjtree/net/sf/jsqlparser/parser
test/java/net/sf/jsqlparser/statement/create/schema Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ public class CreateSchema implements Statement {
24
24
private String schemaName ;
25
25
private List <String > schemaPath ;
26
26
private List <Statement > statements = new ArrayList <>();
27
+ private boolean hasIfNotExists = false ;
27
28
28
29
@ Override
29
30
public <T , S > T accept (StatementVisitor <T > statementVisitor , S context ) {
@@ -103,8 +104,20 @@ public List<Statement> getStatements() {
103
104
return statements ;
104
105
}
105
106
107
+ public boolean hasIfNotExists () {
108
+ return hasIfNotExists ;
109
+ }
110
+
111
+ public CreateSchema setIfNotExists (boolean hasIfNotExists ) {
112
+ this .hasIfNotExists = hasIfNotExists ;
113
+ return this ;
114
+ }
115
+
106
116
public String toString () {
107
117
String sql = "CREATE SCHEMA" ;
118
+ if (hasIfNotExists ) {
119
+ sql += " IF NOT EXISTS" ;
120
+ }
108
121
if (schemaName != null ) {
109
122
sql += " " + schemaName ;
110
123
}
Original file line number Diff line number Diff line change @@ -5946,7 +5946,7 @@ CreateSchema CreateSchema():
5946
5946
List<Statement> statements = new ArrayList<Statement>();
5947
5947
}
5948
5948
{
5949
- <K_SCHEMA>
5949
+ <K_SCHEMA> [ <K_IF> <K_NOT> <K_EXISTS> { schema.setIfNotExists(true); } ]
5950
5950
[ ( tk=<S_IDENTIFIER> | tk=<S_QUOTED_IDENTIFIER>) { schema.setSchemaName(tk.image); } ]
5951
5951
[ <K_AUTHORIZATION>
5952
5952
(tk=<S_IDENTIFIER> | tk=<S_QUOTED_IDENTIFIER>) { schema.setAuthorization(tk.image); }
Original file line number Diff line number Diff line change @@ -34,4 +34,10 @@ public void testSimpleCreateWithAuth() throws JSQLParserException {
34
34
assertDeparse (new CreateSchema ().withSchemaName ("myschema" ).withAuthorization ("myauth" ),
35
35
statement );
36
36
}
37
+
38
+ @ Test
39
+ void testIfNotExistsIssue2061 () throws JSQLParserException {
40
+ String sqlStr = "CREATE SCHEMA IF NOT EXISTS sales_kpi" ;
41
+ assertSqlCanBeParsedAndDeparsed (sqlStr );
42
+ }
37
43
}
You can’t perform that action at this time.
0 commit comments