Skip to content

Commit 572a6c6

Browse files
committed
Merge origin/master
2 parents f06b197 + 58d3965 commit 572a6c6

24 files changed

+606
-54
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ Look here for more information and examples: https://github.com/JSQLParser/JSqlP
1717

1818
JSqlParser is dual licensed under **LGPL V2.1** and **Apache Software License, Version 2.0**.
1919

20+
## Discussion
21+
22+
Please provide feedback on https://github.com/JSQLParser/JSqlParser/issues/677, about removing bracket identifier quotation to support array processing.
2023

2124
## News
2225
* Released version **1.3** of JSqlParser
@@ -51,6 +54,7 @@ Also I would like to know about needed examples or documentation stuff.
5154

5255
## Extensions in the latest SNAPSHOT version 1.4
5356

57+
* support of **substring(col from 2), position('test' in col), ..** and more (pull request #702)
5458
* support of db2 **VALUES** syntax (issue #561)
5559

5660
## Extensions of JSqlParser releases

src/main/java/net/sf/jsqlparser/expression/ExpressionVisitorAdapter.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,14 @@ public void visit(ExpressionList expressionList) {
346346
}
347347
}
348348

349+
@Override
350+
public void visit(NamedExpressionList namedExpressionList) {
351+
for (Expression expr : namedExpressionList.getExpressions()) {
352+
expr.accept(this);
353+
}
354+
}
355+
356+
349357
@Override
350358
public void visit(MultiExpressionList multiExprList) {
351359
for (ExpressionList list : multiExprList.getExprList()) {

src/main/java/net/sf/jsqlparser/expression/Function.java

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
package net.sf.jsqlparser.expression;
2323

2424
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
25+
import net.sf.jsqlparser.expression.operators.relational.NamedExpressionList;
2526
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
2627

2728
/**
@@ -31,6 +32,7 @@ public class Function extends ASTNodeAccessImpl implements Expression {
3132

3233
private String name;
3334
private ExpressionList parameters;
35+
private NamedExpressionList namedParameters;
3436
private boolean allColumns = false;
3537
private boolean distinct = false;
3638
private boolean isEscaped = false;
@@ -95,6 +97,20 @@ public void setParameters(ExpressionList list) {
9597
parameters = list;
9698
}
9799

100+
/**
101+
* the parameters might be named parameters, e.g. substring('foobar' from 2 for 3)
102+
*
103+
* @return the list of named parameters of the function (if any, else null)
104+
*/
105+
106+
public NamedExpressionList getNamedParameters() {
107+
return namedParameters;
108+
}
109+
110+
public void setNamedParameters(NamedExpressionList list) {
111+
namedParameters = list;
112+
}
113+
98114
/**
99115
* Return true if it's in the form "{fn function_body() }"
100116
*
@@ -128,12 +144,16 @@ public void setKeep(KeepExpression keep) {
128144
public String toString() {
129145
String params;
130146

131-
if (parameters != null) {
132-
params = parameters.toString();
133-
if (isDistinct()) {
134-
params = params.replaceFirst("\\(", "(DISTINCT ");
135-
} else if (isAllColumns()) {
136-
params = params.replaceFirst("\\(", "(ALL ");
147+
if (parameters != null || namedParameters != null) {
148+
if(parameters != null){
149+
params = parameters.toString();
150+
if (isDistinct()) {
151+
params = params.replaceFirst("\\(", "(DISTINCT ");
152+
} else if (isAllColumns()) {
153+
params = params.replaceFirst("\\(", "(ALL ");
154+
}
155+
} else{
156+
params = namedParameters.toString();
137157
}
138158
} else if (isAllColumns()) {
139159
params = "(*)";

src/main/java/net/sf/jsqlparser/expression/operators/relational/ItemsListVisitor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,7 @@ public interface ItemsListVisitor {
2929

3030
void visit(ExpressionList expressionList);
3131

32+
void visit(NamedExpressionList namedExpressionList);
33+
3234
void visit(MultiExpressionList multiExprList);
3335
}

src/main/java/net/sf/jsqlparser/expression/operators/relational/ItemsListVisitorAdapter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ public void visit(SubSelect subSelect) {
3030

3131
}
3232

33+
@Override
34+
public void visit(NamedExpressionList namedExpressionList) {
35+
36+
}
37+
3338
@Override
3439
public void visit(ExpressionList expressionList) {
3540

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2013 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.expression.operators.relational;
23+
24+
import java.util.Arrays;
25+
import java.util.List;
26+
27+
import net.sf.jsqlparser.expression.Expression;
28+
29+
/**
30+
* A list of named expressions, as in
31+
* as in select substr('xyzzy' from 2 for 3)
32+
*/
33+
public class NamedExpressionList implements ItemsList {
34+
35+
private List<Expression> expressions;
36+
private List<String> names;
37+
38+
public NamedExpressionList() {
39+
}
40+
41+
public NamedExpressionList(List<Expression> expressions) {
42+
this.expressions = expressions;
43+
}
44+
45+
public NamedExpressionList(Expression ... expressions) {
46+
this.expressions = Arrays.asList(expressions);
47+
}
48+
49+
public List<Expression> getExpressions() {
50+
return expressions;
51+
}
52+
53+
public List<String> getNames() {
54+
return names;
55+
}
56+
57+
58+
public void setExpressions(List<Expression> list) {
59+
expressions = list;
60+
}
61+
62+
public void setNames(List<String> list) {
63+
names = list;
64+
}
65+
66+
67+
@Override
68+
public void accept(ItemsListVisitor itemsListVisitor) {
69+
itemsListVisitor.visit(this);
70+
}
71+
72+
@Override
73+
public String toString() {
74+
75+
StringBuilder ret = new StringBuilder();
76+
ret.append("(");
77+
for(int i=0; i<expressions.size(); i++){
78+
if(i>0){
79+
ret.append(" ");
80+
}
81+
if(! names.get(i).equals("")){
82+
ret.append(names.get(i)).append(" ").append(expressions.get(i));
83+
}else{
84+
ret.append(expressions.get(i));
85+
}
86+
}
87+
ret.append(")");
88+
89+
return ret.toString();
90+
}
91+
}

src/main/java/net/sf/jsqlparser/statement/StatementVisitor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
package net.sf.jsqlparser.statement;
2323

2424
import net.sf.jsqlparser.statement.alter.Alter;
25+
import net.sf.jsqlparser.statement.comment.Comment;
2526
import net.sf.jsqlparser.statement.create.index.CreateIndex;
2627
import net.sf.jsqlparser.statement.create.table.CreateTable;
2728
import net.sf.jsqlparser.statement.create.view.AlterView;
@@ -40,6 +41,8 @@
4041

4142
public interface StatementVisitor {
4243

44+
void visit(Comment comment);
45+
4346
void visit(Commit commit);
4447

4548
void visit(Delete delete);

src/main/java/net/sf/jsqlparser/statement/StatementVisitorAdapter.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
package net.sf.jsqlparser.statement;
2323

2424
import net.sf.jsqlparser.statement.alter.Alter;
25+
import net.sf.jsqlparser.statement.comment.Comment;
2526
import net.sf.jsqlparser.statement.create.index.CreateIndex;
2627
import net.sf.jsqlparser.statement.create.table.CreateTable;
2728
import net.sf.jsqlparser.statement.create.view.AlterView;
@@ -40,6 +41,11 @@
4041

4142
public class StatementVisitorAdapter implements StatementVisitor {
4243

44+
@Override
45+
public void visit(Comment comment) {
46+
47+
}
48+
4349
@Override
4450
public void visit(Commit commit) {
4551

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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.comment;
23+
24+
import net.sf.jsqlparser.expression.StringValue;
25+
import net.sf.jsqlparser.schema.Column;
26+
import net.sf.jsqlparser.schema.Table;
27+
import net.sf.jsqlparser.statement.Statement;
28+
import net.sf.jsqlparser.statement.StatementVisitor;
29+
30+
public class Comment implements Statement {
31+
32+
private Table table;
33+
private Column column;
34+
private StringValue comment;
35+
36+
@Override
37+
public void accept(StatementVisitor statementVisitor) {
38+
statementVisitor.visit(this);
39+
}
40+
41+
public Table getTable() {
42+
return table;
43+
}
44+
45+
public void setTable(Table table) {
46+
this.table = table;
47+
}
48+
49+
public Column getColumn() {
50+
return column;
51+
}
52+
53+
public void setColumn(Column column) {
54+
this.column = column;
55+
}
56+
57+
public StringValue getComment() {
58+
return comment;
59+
}
60+
61+
public void setComment(StringValue comment) {
62+
this.comment = comment;
63+
}
64+
65+
@Override
66+
public String toString() {
67+
String sql = "COMMENT ON ";
68+
if (table != null) {
69+
sql += "TABLE " + table + " ";
70+
} else if (column != null) {
71+
sql += "COLUMN " + column + " ";
72+
}
73+
sql += "IS " + comment;
74+
return sql;
75+
}
76+
}

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class AlterView implements Statement {
3535

3636
private Table view;
3737
private SelectBody selectBody;
38+
private boolean useReplace = false;
3839
private List<String> columnNames = null;
3940

4041
@Override
@@ -74,9 +75,23 @@ public void setColumnNames(List<String> columnNames) {
7475
this.columnNames = columnNames;
7576
}
7677

78+
public boolean isUseReplace() {
79+
return useReplace;
80+
}
81+
82+
public void setUseReplace(boolean useReplace) {
83+
this.useReplace = useReplace;
84+
}
85+
86+
7787
@Override
7888
public String toString() {
79-
StringBuilder sql = new StringBuilder("ALTER ");
89+
StringBuilder sql;
90+
if(useReplace){
91+
sql = new StringBuilder("REPLACE ");
92+
}else{
93+
sql = new StringBuilder("ALTER ");
94+
}
8095
sql.append("VIEW ");
8196
sql.append(view);
8297
if (columnNames != null) {

0 commit comments

Comments
 (0)