Skip to content

Commit d124de1

Browse files
committed
#933 Add support for parenthesized queries to StatementDetector
1 parent 91e1391 commit d124de1

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/docs/asciidoc/release_notes.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,7 @@ The change also lead to incompatible changes to protected methods in the various
666666
See also https://github.com/FirebirdSQL/jaybird/blob/master/devdoc/jdp/jdp-2026-01-additional-locking-for-sending-in-wire-protocol.adoc[jdp-2026-01: Additional locking for sending in wire protocol].
667667
* Upgraded `org.firebirdsql.extern.decimal` to https://github.com/FirebirdSQL/decimal-java[decimal-java 2.0.1^]
668668
* Support `USING` clause in generated keys detection (https://github.com/FirebirdSQL/jaybird/issues/932[#932])
669+
* Add support for parenthesized queries to `StatementDetector` (https://github.com/FirebirdSQL/jaybird/issues/933[#933])
669670
* ...
670671
671672
[#compatibility-changes]

src/main/org/firebirdsql/jaybird/parser/StatementDetector.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ public final class StatementDetector implements TokenVisitor {
4848
nextAfterStart.put("ROLLBACK",
4949
new StateAfterStart(ParserState.COMMIT_ROLLBACK, LocalStatementType.HARD_ROLLBACK));
5050
nextAfterStart.put("SET", new StateAfterStart(ParserState.SET, LocalStatementType.OTHER));
51+
// Firebird 5.0+ parenthesized query expression
52+
// NOTE: This is a shortcut, if parenthesis at the top-level are ever allowed for anything other than SELECT (or
53+
// SELECT-like statements), this needs to be reworked
54+
nextAfterStart.put("(", new StateAfterStart(ParserState.SELECT, LocalStatementType.SELECT));
5155
// Firebird 6.0+ USING ... DO; need to find end of the USING clause to detect actual statement type
5256
nextAfterStart.put("USING", new StateAfterStart(ParserState.FIND_USING_END, LocalStatementType.OTHER));
5357
NEXT_AFTER_START = unmodifiableMap(nextAfterStart);
@@ -176,7 +180,7 @@ private enum ParserState {
176180
START {
177181
@Override
178182
ParserState next(Token token, StatementDetector detector) {
179-
if (!(token instanceof ReservedToken)) {
183+
if (!(token instanceof ReservedToken || token instanceof ParenthesisOpen)) {
180184
return forceOther(detector);
181185
}
182186
StateAfterStart stateAfterStart =

src/test/org/firebirdsql/jaybird/parser/StatementDetectorTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,20 @@ static Stream<Arguments> detectionCases() {
4949
// SELECT
5050
detectReturning("select * from RDB$DATABASE", LocalStatementType.SELECT, false),
5151
noDetect("select * from RDB$DATABASE", LocalStatementType.SELECT, false),
52-
detectReturning("/* a comment */ select * from RDB$DATABASE", LocalStatementType.SELECT, false),
52+
detectReturning("/* a comment */ select * from RDB$DATABASE", LocalStatementType.SELECT, false),
5353
// Presence of select as first keyword is sufficient
5454
detectReturning("select", LocalStatementType.SELECT, true),
5555
detectReturning("with a as (select 1 as col from rdb$database) select * from a",
5656
LocalStatementType.SELECT, false),
5757
// Presence of with as first keyword is sufficient
5858
detectReturning("with", LocalStatementType.SELECT, true),
59+
detectReturning("(select * from RDB$DATABASE)", LocalStatementType.SELECT, false),
60+
61+
// SELECT: Parenthesized query expressions
62+
noDetect("(select * from RDB$DATABASE)", LocalStatementType.SELECT, false),
63+
noDetect("((select * from RDB$DATABASE))", LocalStatementType.SELECT, false),
64+
// Presence of only the open parenthesis is sufficient
65+
detectReturning("(", LocalStatementType.SELECT, true),
5966

6067
// EXECUTE PROCEDURE
6168
detectReturning("execute procedure test 'value1', 'value2'",

0 commit comments

Comments
 (0)