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.
2525
2626## Extensions in the latest SNAPSHOT version 0.9.2
2727
28+ * first support for * FOR UPDATE*
29+
30+ ``` sql
31+ SELECT * FROM user_table FOR UPDATE
32+ ```
33+
2834``` sql
2935UPDATE mytable SET (col) = (SELECT a FROM mytable2)
3036```
Original file line number Diff line number Diff line change @@ -50,6 +50,7 @@ public class PlainSelect implements SelectBody {
5050 private Top top ;
5151 private OracleHierarchicalExpression oracleHierarchical = null ;
5252 private boolean oracleSiblings = false ;
53+ private boolean forUpdate = false ;
5354
5455 /**
5556 * The {@link FromItem} in this query
@@ -205,6 +206,14 @@ public void setOracleSiblings(boolean oracleSiblings) {
205206 this .oracleSiblings = oracleSiblings ;
206207 }
207208
209+ public boolean isForUpdate () {
210+ return forUpdate ;
211+ }
212+
213+ public void setForUpdate (boolean forUpdate ) {
214+ this .forUpdate = forUpdate ;
215+ }
216+
208217 @ Override
209218 public String toString () {
210219 StringBuilder sql = new StringBuilder ("SELECT " );
@@ -260,6 +269,9 @@ public String toString() {
260269 if (fetch != null ) {
261270 sql .append (fetch );
262271 }
272+ if (isForUpdate ()) {
273+ sql .append (" FOR UPDATE" );
274+ }
263275 }
264276 return sql .toString ();
265277 }
Original file line number Diff line number Diff line change @@ -140,6 +140,9 @@ public void visit(PlainSelect plainSelect) {
140140 if (plainSelect .getFetch () != null ) {
141141 deparseFetch (plainSelect .getFetch ());
142142 }
143+ if (plainSelect .isForUpdate ()) {
144+ buffer .append (" FOR UPDATE" );
145+ }
143146
144147 }
145148
Original file line number Diff line number Diff line change @@ -624,6 +624,8 @@ PlainSelect PlainSelect():
624624 [LOOKAHEAD(<K_OFFSET>) offset = Offset() { plainSelect.setOffset(offset); } ]
625625 [LOOKAHEAD(<K_FETCH>) fetch = Fetch() { plainSelect.setFetch(fetch); } ]
626626
627+ [ <K_FOR> <K_UPDATE> { plainSelect.setForUpdate(true); } ]
628+
627629 {
628630 plainSelect.setSelectItems(selectItems);
629631 plainSelect.setFromItem(fromItem);
Original file line number Diff line number Diff line change @@ -1616,4 +1616,9 @@ public void testJsonExpression() throws JSQLParserException {
16161616 public void testSelectInto1 () throws JSQLParserException {
16171617 assertSqlCanBeParsedAndDeparsed ("SELECT * INTO user_copy FROM user" );
16181618 }
1619+
1620+ public void testSelectForUpdate () throws JSQLParserException {
1621+ assertSqlCanBeParsedAndDeparsed ("SELECT * FROM user_table FOR UPDATE" );
1622+ }
1623+
16191624}
You can’t perform that action at this time.
0 commit comments