@@ -60,14 +60,17 @@ public final class FBEscapedParser implements JdbcEscapeParser {
6060
6161 private final AbstractVersion firebirdVersion ;
6262 private final QuoteStrategy quoteStrategy ;
63+ private final CallEscapeHandling callEscapeHandling ;
6364
64- private FBEscapedParser (AbstractVersion firebirdVersion , QuoteStrategy quoteStrategy ) {
65+ private FBEscapedParser (AbstractVersion firebirdVersion , QuoteStrategy quoteStrategy ,
66+ CallEscapeHandling callEscapeHandling ) {
6567 this .firebirdVersion = firebirdVersion ;
6668 this .quoteStrategy = quoteStrategy ;
69+ this .callEscapeHandling = callEscapeHandling ;
6770 }
6871
6972 /**
70- * Get an instance of the escape parser for the specified Firebird version and quote strategy.
73+ * Instance of the escape parser for the specified Firebird version and quote strategy, processing call escapes .
7174 *
7275 * @param firebirdVersion
7376 * Firebird version
@@ -76,8 +79,32 @@ private FBEscapedParser(AbstractVersion firebirdVersion, QuoteStrategy quoteStra
7679 * @since 7
7780 */
7881 public static FBEscapedParser of (AbstractVersion firebirdVersion , QuoteStrategy quoteStrategy ) {
79- assert !(firebirdVersion instanceof OdsVersion ) : "Do not pass OdsVersion to FBEscapedParser.of(...)" ;
80- return new FBEscapedParser (firebirdVersion , quoteStrategy );
82+ return of (firebirdVersion , quoteStrategy , CallEscapeHandling .TO_EXECUTE_PROCEDURE );
83+ }
84+
85+ /**
86+ * Instance of the escape parser for the specified Firebird version, quote strategy, and escape handling.
87+ *
88+ * @param firebirdVersion
89+ * Firebird version
90+ * @param quoteStrategy
91+ * quote strategy
92+ * @param callEscapeHandling
93+ * call escape handling
94+ * @since 7
95+ */
96+ public static FBEscapedParser of (AbstractVersion firebirdVersion , QuoteStrategy quoteStrategy ,
97+ CallEscapeHandling callEscapeHandling ) {
98+ assert !(firebirdVersion instanceof OdsVersion ) : "Do not pass OdsVersion to FBEscapedParser.of(...)" ;
99+ return new FBEscapedParser (firebirdVersion , quoteStrategy , callEscapeHandling );
100+ }
101+
102+ @ Override
103+ public FBEscapedParser with (CallEscapeHandling callEscapeHandling ) {
104+ if (this .callEscapeHandling == callEscapeHandling ) {
105+ return this ;
106+ }
107+ return new FBEscapedParser (firebirdVersion , quoteStrategy , callEscapeHandling );
81108 }
82109
83110 AbstractVersion firebirdVersion () {
@@ -89,6 +116,11 @@ QuoteStrategy quoteStrategy() {
89116 return quoteStrategy ;
90117 }
91118
119+ @ SuppressWarnings ("unused" )
120+ CallEscapeHandling callEscapeHandling () {
121+ return callEscapeHandling ;
122+ }
123+
92124 /**
93125 * Check if the target SQL contains at least one of the escaped syntax commands. This method performs a simple regex
94126 * match, so it may report that SQL contains escaped syntax when the <code>"{"</code> is followed by
@@ -97,7 +129,7 @@ QuoteStrategy quoteStrategy() {
97129 *
98130 * @param sql
99131 * to test
100- * @return {@code true} if the {@code sql} is suspected to contain escaped syntax.
132+ * @return {@code true} if the {@code sql} seems to contain escaped syntax
101133 */
102134 private static boolean checkForEscapes (String sql ) {
103135 return CHECK_ESCAPE_PATTERN .matcher (sql ).find ();
@@ -281,14 +313,22 @@ private static void toTimestampString(final StringBuilder target, final CharSequ
281313 * Converts the escaped procedure call syntax into the native procedure call.
282314 *
283315 * @param target
284- * Target StringBuilder to append native procedure call to.
316+ * target StringBuilder to append native procedure call to
285317 * @param procedureCall
286- * part of {call proc_name(...)} without curly braces and "call"
287- * word.
318+ * part of {call proc_name(...)} including curly braces and "call" keyword
288319 */
289- private void convertProcedureCall (final StringBuilder target , final String procedureCall ) throws SQLException {
320+ private void convertProcedureCall (StringBuilder target , String procedureCall ) throws SQLException {
321+ if (callEscapeHandling == CallEscapeHandling .IGNORED ) {
322+ target .append (procedureCall );
323+ } else {
324+ convertProcedureCall0 (target , procedureCall );
325+ }
326+ }
327+
328+ private void convertProcedureCall0 (StringBuilder target , String procedureCall ) throws SQLException {
290329 var tempParser = new FBEscapedCallParser (this );
291330 FBProcedureCall call = tempParser .parseCall (procedureCall );
331+ // TODO Should this be called? It result in exceptions, see FBEscapedParserTest#testCallEscapeHandling
292332 call .checkParameters ();
293333 target .append (call .getSQL (quoteStrategy ));
294334 }
0 commit comments