Skip to content

Commit 13c30a4

Browse files
committed
#909 JDBC 4.5 support: "disable escape processing" JDBC escape
1 parent d74cf02 commit 13c30a4

3 files changed

Lines changed: 416 additions & 41 deletions

File tree

src/docs/asciidoc/release_notes.adoc

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ This results in two minor breaking changes:
4848
+
4949
** Reserved words are no longer considered simple identifiers by `enquoteIdentifier` and `isSimpleIdentifier` and will be quoted (or -- for dialect 1 -- result in a `SQLFeatureNotSupportedException`)
5050
** Presence of the NUL character (U+0000) in an identifier passed to `enquoteIdentifier` will result in a `SQLSyntaxErrorException`
51+
* JDBC 4.5 support: implemented "`disable escape processing`" JDBC escape (`++{\...\}++`) (https://github.com/FirebirdSQL/jaybird/issues/909[#909])
52+
+
53+
See also <<jdbc-escape-disable-proc>>.
5154
* Fixed: JDBC escapes should not be parsed inside dialect 3 delimited identifiers or dialect 1 string literals (https://github.com/FirebirdSQL/jaybird/issues/921[#921])
5255
* Fixed: `IndexOutOfBoundsException` in `FBCachedBlob.getBytes(long, int)` for position or length beyond end of data (https://github.com/FirebirdSQL/jaybird/issues/923[#923])
5356
* Fixed: Using native client, password is limited to 255 bytes (https://github.com/FirebirdSQL/jaybird/issues/925[#925])
@@ -230,6 +233,7 @@ See <<native-plugin>> for more information.
230233
* <<no-close-after-last>>
231234
* <<scroll-rs-update-behavior>>
232235
* <<custom-socket-factory>>
236+
* <<jdbc-escape-disable-proc>> (since Jaybird 6.0.5)
233237
* ... and <<other-fixes-and-changes,other fixes and changes>>
234238

235239
Upgrading from Jaybird 5 should be straightforward, but please make sure to read <<compatibility-changes>> before using Jaybird 6.
@@ -1387,6 +1391,83 @@ The other properties -- here `user`, `password` and `socketFactory` -- are *not*
13871391

13881392
See also https://github.com/FirebirdSQL/jaybird/blob/master/devdoc/jdp/jdp-2024-09-custom-socket-factory-for-pure-java-connections.adoc[jdp-2024-09: Custom socket factory for pure Java connections]
13891393

1394+
[#jdbc-escape-disable-proc]
1395+
=== JDBC 4.5 support: JDBC escape to disable escape processing
1396+
1397+
JDBC 4.5 (Java 26) introduces a new JDBC escape to disable escape processing and parameter parsing within part of a statement text.
1398+
This JDBC escape has been implemented in Jaybird 5.0.12 (backported from Jaybird 6.0.5).
1399+
The escape is always parsed if escape processing is enabled (the default), no matter the Java version and the JDBC minor version reported by `DatabaseMetaData#getJDBCMinorVersion()`.
1400+
1401+
The "`disable escape processing`" escape starts with `++{\++` and ends with `++\}++`.
1402+
Within the escape, *all* occurrences of a backslash (`\`) *must* be escaped by doubling.
1403+
Unescaped backslashes inside the escape will result in a `FBSQLParseException`.
1404+
1405+
.Some examples
1406+
[listing]
1407+
----
1408+
-- Input:
1409+
select {\"N\\A"\} from SOME_TABLE
1410+
-- Sent to server:
1411+
select "N\A" from SOME_TABLE
1412+
1413+
-- Input:
1414+
select {\{fn EXP(2)}\} from SOME_TABLE
1415+
-- Sent to server (results in a syntax error)
1416+
select {fn EXP(2)} from SOME_TABLE
1417+
----
1418+
1419+
.Same examples, but as Java string literals
1420+
----
1421+
-- Input:
1422+
"select {\\\"N\\\\A\"\\} from SOME_TABLE"
1423+
-- Sent to server:
1424+
"select \"N\\A\" from SOME_TABLE"
1425+
1426+
-- Input:
1427+
"select {\\{fn EXP(2)}\\} from SOME_TABLE"
1428+
-- Sent to server (results in a syntax error)
1429+
"select {fn EXP(2)} from SOME_TABLE"
1430+
----
1431+
1432+
We think the use case for this escape is extremely limited, even non-existent, for Jaybird.
1433+
Jaybird always offloads parameter parsing to Firebird, and Firebird currently has no syntax that could conflict with the definition of JDBC escapes.
1434+
1435+
.Possible ambiguity for comments, literals, and delimited identifiers
1436+
[CAUTION]
1437+
====
1438+
Given the backslash must be escaped everywhere inside the escape, the definition in the JDBC 4.5 specification can be interpreted to mean that the escape can end inside a comment, literal, or delimited identifier (quoted identifier).
1439+
Allowing this would conflict with the fact that other JDBC escapes are not parsed inside comments, literals, and delimited identifiers.
1440+
Discussion with the JDBC spec lead and others did not resolve this ambiguity.
1441+
1442+
For Jaybird, we decide to reject attempts to end the escape in a comment, literal, or delimited identifier.
1443+
Attempts to do so (e.g. `++{\ends/*in\}comment*/++`) will raise a `FBSQLParseException`.
1444+
Valid alternatives would be:
1445+
1446+
* End it before the comment: +
1447+
`++{\ends\}/*in\}comment*/++`
1448+
* End it after the comment and escape the backslash in the comment: +
1449+
`++{\ends/*in\\}comment*/\}++`
1450+
* Or, don't use the escape: +
1451+
`++ends/*in\}comment*/++`
1452+
1453+
If a consensus is reached in the JDBC Expert Group, or a community consensus arises, we may revisit this decision.
1454+
1455+
Further details can be found in https://github.com/FirebirdSQL/jaybird/blob/master/devdoc/jdp/jdp-2026-03-jdbc-escape-to-disable-escape-processing.adoc[jdp-2026-03: JDBC escape to disable escape processing]
1456+
====
1457+
1458+
Given above ambiguity, and the lack of a real need to use it for Jaybird/Firebird, we recommend avoiding use of this escape unless absolutely necessary.
1459+
If it is used, we recommend only using it for the shortest substring needed.
1460+
1461+
For example, the last example (passing the `++{fn EXP(2)}++` to the server) could also be achieved by only disabling escape processing for the braces:
1462+
1463+
[listing]
1464+
----
1465+
-- Input:
1466+
select {\{\}fn EXP(2){\}\} from SOME_TABLE
1467+
-- Sent to server (results in a syntax error)
1468+
select {fn EXP(2)} from SOME_TABLE
1469+
----
1470+
13901471
[#other-fixes-and-changes]
13911472
=== Other fixes and changes
13921473

0 commit comments

Comments
 (0)