Skip to content

Commit b76baa3

Browse files
committed
solved some oracle test sql parsings
1 parent 46f5197 commit b76baa3

File tree

6 files changed

+27
-4
lines changed

6 files changed

+27
-4
lines changed

src/main/java/net/sf/jsqlparser/statement/select/PlainSelect.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public class PlainSelect implements SelectBody {
5151
private OracleHierarchicalExpression oracleHierarchical = null;
5252
private boolean oracleSiblings = false;
5353
private boolean forUpdate = false;
54+
private Table forUpdateTable = null;
5455

5556
/**
5657
* The {@link FromItem} in this query
@@ -221,6 +222,14 @@ public void setForUpdate(boolean forUpdate) {
221222
this.forUpdate = forUpdate;
222223
}
223224

225+
public Table getForUpdateTable() {
226+
return forUpdateTable;
227+
}
228+
229+
public void setForUpdateTable(Table forUpdateTable) {
230+
this.forUpdateTable = forUpdateTable;
231+
}
232+
224233
@Override
225234
public String toString() {
226235
StringBuilder sql = new StringBuilder("SELECT ");
@@ -278,6 +287,10 @@ public String toString() {
278287
}
279288
if (isForUpdate()) {
280289
sql.append(" FOR UPDATE");
290+
291+
if (forUpdateTable != null) {
292+
sql.append(" OF ").append(forUpdateTable);
293+
}
281294
}
282295
}
283296
return sql.toString();

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ public void visit(PlainSelect plainSelect) {
142142
}
143143
if (plainSelect.isForUpdate()) {
144144
buffer.append(" FOR UPDATE");
145+
if (plainSelect.getForUpdateTable() != null) {
146+
buffer.append(" OF ").append(plainSelect.getForUpdateTable());
147+
}
145148
}
146149

147150
}

src/main/javacc/net/sf/jsqlparser/parser/JSqlParserCC.jj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */
210210
| <K_WITHIN:"WITHIN">
211211
| <K_IF:"IF">
212212
| <K_RECURSIVE:"RECURSIVE">
213+
| <K_OF:"OF">
213214
}
214215

215216
TOKEN : /* Numeric Constants */
@@ -614,6 +615,7 @@ PlainSelect PlainSelect():
614615
Top top = null;
615616
OracleHierarchicalExpression oracleHierarchicalQueryClause = null;
616617
List<Table> intoTables = null;
618+
Table updateTable = null;
617619
}
618620
{
619621
<K_SELECT>
@@ -647,7 +649,8 @@ PlainSelect PlainSelect():
647649
[LOOKAHEAD(<K_OFFSET>) offset = Offset() { plainSelect.setOffset(offset); } ]
648650
[LOOKAHEAD(<K_FETCH>) fetch = Fetch() { plainSelect.setFetch(fetch); } ]
649651

650-
[ <K_FOR> <K_UPDATE> { plainSelect.setForUpdate(true); } ]
652+
[ <K_FOR> <K_UPDATE> { plainSelect.setForUpdate(true); }
653+
[ <K_OF> updateTable = Table() { plainSelect.setForUpdateTable(updateTable); } ] ]
651654

652655
{
653656
plainSelect.setSelectItems(selectItems);
@@ -946,7 +949,7 @@ FromItem FromItem():
946949
)
947950
|
948951
fromItem=Table()
949-
|
952+
|
950953
fromItem=LateralSubSelect()
951954
)
952955
[(LOOKAHEAD(2) pivot=PivotXml()|pivot=Pivot()) { fromItem.setPivot(pivot); } ]

src/test/java/net/sf/jsqlparser/test/select/SelectTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,4 +1708,8 @@ public void testSelectBrackets3() throws JSQLParserException {
17081708
public void testSelectBrackets4() throws JSQLParserException {
17091709
assertSqlCanBeParsedAndDeparsed("SELECT (1 / 2)::numeric");
17101710
}
1711+
1712+
public void testSelectForUpdateOfTable() throws JSQLParserException {
1713+
assertSqlCanBeParsedAndDeparsed("SELECT foo.*, bar.* FROM foo, bar WHERE foo.id = bar.foo_id FOR UPDATE OF foo");
1714+
}
17111715
}

src/test/java/net/sf/jsqlparser/test/select/SpecialOracleTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void testAllSqlsParseDeparse() throws IOException {
6868
}
6969

7070
LOG.log(Level.INFO, "tested {0} files. got {1} correct parse results", new Object[]{count, success});
71-
assertTrue(success>=116);
71+
assertTrue(success>=121);
7272
}
7373

7474
@Test

src/test/resources/net/sf/jsqlparser/test/oracle-tests/columns01.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ select a, b,
22
a d,
33
ddd as ddd,
44
ddd as "dfdf",
5-
x as
5+
x as x
66
from dual
77

0 commit comments

Comments
 (0)