File tree Expand file tree Collapse file tree 5 files changed +28
-0
lines changed
javacc/net/sf/jsqlparser/parser
test/java/net/sf/jsqlparser/test/select Expand file tree Collapse file tree 5 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,12 @@ Also I would like to know about needed examples or documentation stuff.
25
25
26
26
## Extensions in the latest SNAPSHOT version 0.9.2
27
27
28
+ * first support for * FOR UPDATE*
29
+
30
+ ``` sql
31
+ SELECT * FROM user_table FOR UPDATE
32
+ ```
33
+
28
34
``` sql
29
35
UPDATE mytable SET (col) = (SELECT a FROM mytable2)
30
36
```
Original file line number Diff line number Diff line change @@ -50,6 +50,7 @@ public class PlainSelect implements SelectBody {
50
50
private Top top ;
51
51
private OracleHierarchicalExpression oracleHierarchical = null ;
52
52
private boolean oracleSiblings = false ;
53
+ private boolean forUpdate = false ;
53
54
54
55
/**
55
56
* The {@link FromItem} in this query
@@ -205,6 +206,14 @@ public void setOracleSiblings(boolean oracleSiblings) {
205
206
this .oracleSiblings = oracleSiblings ;
206
207
}
207
208
209
+ public boolean isForUpdate () {
210
+ return forUpdate ;
211
+ }
212
+
213
+ public void setForUpdate (boolean forUpdate ) {
214
+ this .forUpdate = forUpdate ;
215
+ }
216
+
208
217
@ Override
209
218
public String toString () {
210
219
StringBuilder sql = new StringBuilder ("SELECT " );
@@ -260,6 +269,9 @@ public String toString() {
260
269
if (fetch != null ) {
261
270
sql .append (fetch );
262
271
}
272
+ if (isForUpdate ()) {
273
+ sql .append (" FOR UPDATE" );
274
+ }
263
275
}
264
276
return sql .toString ();
265
277
}
Original file line number Diff line number Diff line change @@ -140,6 +140,9 @@ public void visit(PlainSelect plainSelect) {
140
140
if (plainSelect .getFetch () != null ) {
141
141
deparseFetch (plainSelect .getFetch ());
142
142
}
143
+ if (plainSelect .isForUpdate ()) {
144
+ buffer .append (" FOR UPDATE" );
145
+ }
143
146
144
147
}
145
148
Original file line number Diff line number Diff line change @@ -624,6 +624,8 @@ PlainSelect PlainSelect():
624
624
[LOOKAHEAD(<K_OFFSET>) offset = Offset() { plainSelect.setOffset(offset); } ]
625
625
[LOOKAHEAD(<K_FETCH>) fetch = Fetch() { plainSelect.setFetch(fetch); } ]
626
626
627
+ [ <K_FOR> <K_UPDATE> { plainSelect.setForUpdate(true); } ]
628
+
627
629
{
628
630
plainSelect.setSelectItems(selectItems);
629
631
plainSelect.setFromItem(fromItem);
Original file line number Diff line number Diff line change @@ -1616,4 +1616,9 @@ public void testJsonExpression() throws JSQLParserException {
1616
1616
public void testSelectInto1 () throws JSQLParserException {
1617
1617
assertSqlCanBeParsedAndDeparsed ("SELECT * INTO user_copy FROM user" );
1618
1618
}
1619
+
1620
+ public void testSelectForUpdate () throws JSQLParserException {
1621
+ assertSqlCanBeParsedAndDeparsed ("SELECT * FROM user_table FOR UPDATE" );
1622
+ }
1623
+
1619
1624
}
You can’t perform that action at this time.
0 commit comments