Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ public enum ForMode {

NO_KEY_UPDATE("NO KEY UPDATE"),

KEY_SHARE("KEY SHARE");
KEY_SHARE("KEY SHARE"),

// https://www.ibm.com/docs/en/db2-for-zos/13.0.0?topic=statement-read-only-clause
READ_ONLY("READ ONLY"), FETCH_ONLY("FETCH ONLY");

private final String value;

Expand Down
2 changes: 2 additions & 0 deletions src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -4247,6 +4247,8 @@ PlainSelect PlainSelect() #PlainSelect:
| <K_SHARE> { plainSelect.setForMode(ForMode.SHARE); }
| (<K_NO> <K_KEY> <K_UPDATE> { plainSelect.setForMode(ForMode.NO_KEY_UPDATE); })
| (<K_KEY> <K_SHARE> { plainSelect.setForMode(ForMode.KEY_SHARE); })
| (<K_READ> <K_ONLY> { plainSelect.setForMode(ForMode.READ_ONLY); })
| (<K_FETCH> <K_ONLY> { plainSelect.setForMode(ForMode.FETCH_ONLY); })
)
[ LOOKAHEAD(2) <K_OF> updateTable = Table() { plainSelect.setForUpdateTable(updateTable); } ]
[ LOOKAHEAD(<K_WAIT>) wait = Wait() { plainSelect.setWait(wait); } ]
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/net/sf/jsqlparser/statement/select/DB2Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import net.sf.jsqlparser.JSQLParserException;
import net.sf.jsqlparser.test.TestUtils;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

public class DB2Test {
@Test
Expand All @@ -20,4 +22,16 @@ void testDB2SpecialRegister() throws JSQLParserException {
"SELECT * FROM TABLE1 where COL_WITH_TIMESTAMP <= CURRENT TIMESTAMP - CURRENT TIMEZONE";
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
}

@ParameterizedTest
@ValueSource(strings = {
"SELECT * FROM table WITH UR",
"SELECT * FROM table WITH UR FOR READ ONLY",
"SELECT * FROM table FOR READ ONLY",
"SELECT * FROM table FOR FETCH ONLY",
"SELECT * FROM table FETCH FIRST 100 ROWS ONLY FOR READ ONLY"
})
void testWithIsolationLevelAndReadOnlyModes(String sqlStr) throws JSQLParserException {
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
}
}
Loading