From e17bff156b9cdb6de8b9556121cf403efc2bc557 Mon Sep 17 00:00:00 2001 From: hvlad Date: Wed, 6 Mar 2019 13:37:50 +0200 Subject: [PATCH] Improvement CORE-5658 : Execute statement with excess parameters Documentation --- doc/sql.extensions/README.execute_statement2 | 37 ++++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/doc/sql.extensions/README.execute_statement2 b/doc/sql.extensions/README.execute_statement2 index 49acd52096..072012d52b 100644 --- a/doc/sql.extensions/README.execute_statement2 +++ b/doc/sql.extensions/README.execute_statement2 @@ -42,11 +42,13 @@ Syntax and notes : | , ::= - := + [EXCESS] := Syntax above introduced new parameter value binding operator ":=" to avoid - clashes with future boolean expressions. - This syntax may be changed in release version. + clashes with boolean expressions. + Optional "EXCESS" mark indicates that given parameter allows to be not + mentioned at query text. Note, all non-excess input parameters must be used + by a query. - if ON EXTERNAL DATA SOURCE clause is omitted then a) statement will be executed against current (local) database @@ -259,3 +261,32 @@ BEGIN SUSPEND; END + + +4. Using EXCESS input parameters + +CREATE PROCEDURE P_EXCESS (A_ID INT, A_TRAN INT = NULL, A_CONN INT = NULL) + RETURNS (ID INT, TRAN INT, CONN INT) +AS +DECLARE S VARCHAR(255); +DECLARE W VARCHAR(255) = ''; +BEGIN + S = 'SELECT * FROM TTT WHERE ID = :ID'; + + IF (A_TRAN IS NOT NULL) + THEN W = W || ' AND TRAN = :a'; + + IF (A_CONN IS NOT NULL) + THEN W = W || ' AND CONN = :b'; + + IF (W <> '') + THEN S = S || W; + + -- could raise error if TRAN or CONN is null + -- FOR EXECUTE STATEMENT (:S) (a := :A_TRAN, b := A_CONN, id := A_ID) + + -- OK in all cases + FOR EXECUTE STATEMENT (:S) (EXCESS a := :A_TRAN, EXCESS b := A_CONN, id := A_ID) + INTO :ID, :TRAN, :CONN + DO SUSPEND; +END