Skip to content

Commit 0164bff

Browse files
committed
Merge origin/master
Conflicts: src/test/java/net/sf/jsqlparser/test/select/SelectTest.java
2 parents d3d66f8 + 0d1d1c0 commit 0164bff

File tree

16 files changed

+320
-22
lines changed

16 files changed

+320
-22
lines changed

README.md

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

4343
## Extensions in the latest SNAPSHOT version 0.9.6
4444

45+
* support for **UPDATE RETURNING**
46+
* support for scalar time function, like **CURRENT_TIMESTAMP**
4547
* support for **LEFT SEMI JOIN**
4648
* improved **top** expression
4749

nbactions.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,12 @@
1212
<skipTests>true</skipTests>
1313
</properties>
1414
</action>
15+
<action>
16+
<actionName>CUSTOM-clean deploy</actionName>
17+
<displayName>clean deploy</displayName>
18+
<goals>
19+
<goal>clean</goal>
20+
<goal>deploy</goal>
21+
</goals>
22+
</action>
1523
</actions>

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,5 +164,7 @@ public interface ExpressionVisitor {
164164
void visit(RowConstructor rowConstructor);
165165

166166
void visit(OracleHint hint);
167-
167+
168+
void visit(TimeKeyExpression timeKeyExpression);
169+
168170
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,5 +455,10 @@ public void visit(HexValue hexValue) {
455455
public void visit(OracleHint hint) {
456456

457457
}
458-
458+
459+
@Override
460+
public void visit(TimeKeyExpression timeKeyExpression) {
461+
462+
}
463+
459464
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2016 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;
23+
24+
public class TimeKeyExpression implements Expression {
25+
26+
private String stringValue;
27+
28+
public TimeKeyExpression(final String value) {
29+
this.stringValue = value;
30+
}
31+
32+
@Override
33+
public void accept(ExpressionVisitor expressionVisitor) {
34+
expressionVisitor.visit(this);
35+
}
36+
37+
public String getStringValue() {
38+
return stringValue;
39+
}
40+
41+
public void setStringValue(String string) {
42+
stringValue = string;
43+
}
44+
45+
@Override
46+
public String toString() {
47+
return getStringValue();
48+
}
49+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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.statement.create.table;
23+
24+
import net.sf.jsqlparser.expression.Expression;
25+
import net.sf.jsqlparser.schema.Table;
26+
27+
/**
28+
* Table Check Constraint
29+
* Eg. ' CONSTRAINT less_than_ten CHECK (count < 10) '
30+
* @author mw
31+
*/
32+
public class CheckConstraint extends NamedConstraint {
33+
private Table table;
34+
private Expression expression;
35+
36+
37+
public Table getTable() {
38+
return table;
39+
}
40+
41+
public void setTable(Table table) {
42+
this.table = table;
43+
}
44+
45+
public Expression getExpression() {
46+
return expression;
47+
}
48+
49+
public void setExpression(Expression expression) {
50+
this.expression = expression;
51+
}
52+
53+
@Override
54+
public String toString() {
55+
return "CONSTRAINT " + getName() + " CHECK (" + expression + ")";
56+
}
57+
}

src/main/java/net/sf/jsqlparser/statement/update/Update.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import net.sf.jsqlparser.statement.select.Select;
3535
import net.sf.jsqlparser.statement.select.OrderByElement;
3636
import net.sf.jsqlparser.statement.select.Limit;
37+
import net.sf.jsqlparser.statement.select.SelectExpressionItem;
3738

3839
/**
3940
* The update statement.
@@ -51,6 +52,8 @@ public class Update implements Statement {
5152
private boolean useSelect = false;
5253
private List<OrderByElement> orderByElements;
5354
private Limit limit;
55+
private boolean returningAllColumns = false;
56+
private List<SelectExpressionItem> returningExpressionList = null;
5457

5558
@Override
5659
public void accept(StatementVisitor statementVisitor) {
@@ -157,6 +160,22 @@ public Limit getLimit() {
157160
return limit;
158161
}
159162

163+
public boolean isReturningAllColumns() {
164+
return returningAllColumns;
165+
}
166+
167+
public void setReturningAllColumns(boolean returningAllColumns) {
168+
this.returningAllColumns = returningAllColumns;
169+
}
170+
171+
public List<SelectExpressionItem> getReturningExpressionList() {
172+
return returningExpressionList;
173+
}
174+
175+
public void setReturningExpressionList(List<SelectExpressionItem> returningExpressionList) {
176+
this.returningExpressionList = returningExpressionList;
177+
}
178+
160179
@Override
161180
public String toString() {
162181
StringBuilder b = new StringBuilder("UPDATE ");
@@ -210,6 +229,13 @@ public String toString() {
210229
if (limit != null) {
211230
b.append(limit);
212231
}
232+
233+
if (isReturningAllColumns()) {
234+
b.append(" RETURNING *");
235+
} else if (getReturningExpressionList() != null) {
236+
b.append(" RETURNING ").append(PlainSelect.getStringList(getReturningExpressionList(), true, false));
237+
}
238+
213239
return b.toString();
214240
}
215241
}

src/main/java/net/sf/jsqlparser/util/TablesNamesFinder.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
public class TablesNamesFinder implements SelectVisitor, FromItemVisitor, ExpressionVisitor, ItemsListVisitor, SelectItemVisitor, StatementVisitor {
5757

5858
private static final String NOT_SUPPORTED_YET = "Not supported yet.";
59-
private List<String> tables;
59+
private List<String> tables;
6060
/**
6161
* There are special names, that are not table names but are parsed as
6262
* tables. These names are collected here and are not included in the tables
@@ -228,6 +228,10 @@ public void visit(EqualsTo equalsTo) {
228228

229229
@Override
230230
public void visit(Function function) {
231+
ExpressionList exprList = function.getParameters();
232+
if (exprList != null) {
233+
visit(exprList);
234+
}
231235
}
232236

233237
@Override
@@ -326,7 +330,6 @@ public void visit(ExpressionList expressionList) {
326330
for (Expression expression : expressionList.getExpressions()) {
327331
expression.accept(this);
328332
}
329-
330333
}
331334

332335
@Override
@@ -576,17 +579,17 @@ public void visit(Replace replace) {
576579

577580
@Override
578581
public void visit(Drop drop) {
579-
throw new UnsupportedOperationException(NOT_SUPPORTED_YET);
582+
throw new UnsupportedOperationException(NOT_SUPPORTED_YET);
580583
}
581584

582585
@Override
583586
public void visit(Truncate truncate) {
584-
throw new UnsupportedOperationException(NOT_SUPPORTED_YET);
587+
throw new UnsupportedOperationException(NOT_SUPPORTED_YET);
585588
}
586589

587590
@Override
588591
public void visit(CreateIndex createIndex) {
589-
throw new UnsupportedOperationException(NOT_SUPPORTED_YET);
592+
throw new UnsupportedOperationException(NOT_SUPPORTED_YET);
590593
}
591594

592595
@Override
@@ -599,12 +602,12 @@ public void visit(CreateTable create) {
599602

600603
@Override
601604
public void visit(CreateView createView) {
602-
throw new UnsupportedOperationException(NOT_SUPPORTED_YET);
605+
throw new UnsupportedOperationException(NOT_SUPPORTED_YET);
603606
}
604607

605608
@Override
606609
public void visit(Alter alter) {
607-
throw new UnsupportedOperationException(NOT_SUPPORTED_YET);
610+
throw new UnsupportedOperationException(NOT_SUPPORTED_YET);
608611
}
609612

610613
@Override
@@ -619,7 +622,7 @@ public void visit(Execute execute) {
619622

620623
@Override
621624
public void visit(SetStatement set) {
622-
throw new UnsupportedOperationException(NOT_SUPPORTED_YET);
625+
throw new UnsupportedOperationException(NOT_SUPPORTED_YET);
623626
}
624627

625628
@Override
@@ -649,7 +652,10 @@ public void visit(TableFunction valuesList) {
649652

650653
@Override
651654
public void visit(AlterView alterView) {
652-
throw new UnsupportedOperationException(NOT_SUPPORTED_YET);
655+
throw new UnsupportedOperationException(NOT_SUPPORTED_YET);
653656
}
654657

658+
@Override
659+
public void visit(TimeKeyExpression timeKeyExpression) {
660+
}
655661
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,5 +575,10 @@ public void visit(RowConstructor rowConstructor) {
575575
public void visit(OracleHint hint) {
576576
buffer.append(hint.toString());
577577
}
578-
578+
579+
@Override
580+
public void visit(TimeKeyExpression timeKeyExpression) {
581+
buffer.append(timeKeyExpression.toString());
582+
}
583+
579584
}

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
*/
2222
package net.sf.jsqlparser.util.deparser;
2323

24+
import java.util.Iterator;
25+
2426
import net.sf.jsqlparser.expression.Expression;
2527
import net.sf.jsqlparser.expression.ExpressionVisitor;
2628
import net.sf.jsqlparser.schema.Column;
@@ -31,7 +33,7 @@
3133
import net.sf.jsqlparser.statement.select.SelectVisitor;
3234
import net.sf.jsqlparser.statement.select.OrderByVisitor;
3335
import net.sf.jsqlparser.statement.select.OrderByElement;
34-
36+
import net.sf.jsqlparser.statement.select.SelectExpressionItem;
3537
/**
3638
* A class to de-parse (that is, tranform from JSqlParser hierarchy into a
3739
* string) an {@link net.sf.jsqlparser.statement.update.Update}
@@ -125,6 +127,17 @@ public void deParse(Update update) {
125127
new LimitDeparser(buffer).deParse(update.getLimit());
126128
}
127129

130+
if (update.isReturningAllColumns()) {
131+
buffer.append(" RETURNING *");
132+
} else if (update.getReturningExpressionList() != null) {
133+
buffer.append(" RETURNING ");
134+
for (Iterator<SelectExpressionItem> iter = update.getReturningExpressionList().iterator(); iter.hasNext();) {
135+
buffer.append(iter.next().toString());
136+
if (iter.hasNext()) {
137+
buffer.append(", ");
138+
}
139+
}
140+
}
128141
}
129142

130143
public ExpressionVisitor getExpressionVisitor() {

0 commit comments

Comments
 (0)