Skip to content

Commit e400444

Browse files
authored
[feat] Support for FOR READ ONLY/FOR FETCH ONLY (#2325)
* [feat] Support for FOR READ ONLY/FOR FETCH ONLY * [chore] Spotless
1 parent c60ff73 commit e400444

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ public enum ForMode {
2020

2121
NO_KEY_UPDATE("NO KEY UPDATE"),
2222

23-
KEY_SHARE("KEY SHARE");
23+
KEY_SHARE("KEY SHARE"),
24+
25+
// https://www.ibm.com/docs/en/db2-for-zos/13.0.0?topic=statement-read-only-clause
26+
READ_ONLY("READ ONLY"), FETCH_ONLY("FETCH ONLY");
2427

2528
private final String value;
2629

src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4248,6 +4248,8 @@ PlainSelect PlainSelect() #PlainSelect:
42484248
| <K_SHARE> { plainSelect.setForMode(ForMode.SHARE); }
42494249
| (<K_NO> <K_KEY> <K_UPDATE> { plainSelect.setForMode(ForMode.NO_KEY_UPDATE); })
42504250
| (<K_KEY> <K_SHARE> { plainSelect.setForMode(ForMode.KEY_SHARE); })
4251+
| (<K_READ> <K_ONLY> { plainSelect.setForMode(ForMode.READ_ONLY); })
4252+
| (<K_FETCH> <K_ONLY> { plainSelect.setForMode(ForMode.FETCH_ONLY); })
42514253
)
42524254
[ LOOKAHEAD(2) <K_OF> updateTable = Table() { plainSelect.setForUpdateTable(updateTable); } ]
42534255
[ LOOKAHEAD(<K_WAIT>) wait = Wait() { plainSelect.setWait(wait); } ]

src/test/java/net/sf/jsqlparser/statement/select/DB2Test.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import net.sf.jsqlparser.JSQLParserException;
1313
import net.sf.jsqlparser.test.TestUtils;
1414
import org.junit.jupiter.api.Test;
15+
import org.junit.jupiter.params.ParameterizedTest;
16+
import org.junit.jupiter.params.provider.ValueSource;
1517

1618
public class DB2Test {
1719
@Test
@@ -20,4 +22,16 @@ void testDB2SpecialRegister() throws JSQLParserException {
2022
"SELECT * FROM TABLE1 where COL_WITH_TIMESTAMP <= CURRENT TIMESTAMP - CURRENT TIMEZONE";
2123
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
2224
}
25+
26+
@ParameterizedTest
27+
@ValueSource(strings = {
28+
"SELECT * FROM table WITH UR",
29+
"SELECT * FROM table WITH UR FOR READ ONLY",
30+
"SELECT * FROM table FOR READ ONLY",
31+
"SELECT * FROM table FOR FETCH ONLY",
32+
"SELECT * FROM table FETCH FIRST 100 ROWS ONLY FOR READ ONLY"
33+
})
34+
void testWithIsolationLevelAndReadOnlyModes(String sqlStr) throws JSQLParserException {
35+
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
36+
}
2337
}

0 commit comments

Comments
 (0)