call db procedure a, alias b,c,d,e,f

Calls a stored procedure of a database. Parameter a contains the stored procedure call, b the database alias. Parameter c expects the name of a list containing the values for the input parameters of the stored procedure call. The input parameters in the stored procedure call in a are to be specified in the form of @index:type@, e.g. @0:s@,@1:f@. The index starts at 0.

Note: We talk about parameters of this function here and input parameters and output parameters of the stored procedure.

Parameter types in parameter "a"


i

Integer.

l

Long.

f

Float.

r

Double or Real.

d

Date.

t

Timestamp.

s

Varchar or String.

b

BLOB.

Parameter d is a comma-separated list of indexes (index begins with 1), defining which values are taken from the resultset as output parameter values of the stored procedure. Parameter e (index begins with 1) specifies which value of the list generated in d is used as the return value of the function.

Note: Some databases return the input parameters and output parameters of the stored procedure in the result set (for example MySQL, see example below). Other databases, on the other hand, only return the output parameters of the stored procedure in the result set. Parameter e must be adjusted accordingly.

Parameters


Parameter

Description

a

SQL for the call of the stored procedure.

b

Database alias.

c

Name of the list that contains the input parameter values for the stored procedure.

Note: The values should be added to the list in a type-safe manner, e.g. - regarding the previous example - plus as String, the other two parameters as Integer.

d

Comma-separated list of positions that define which columns of the result set of the procedure call are interpreted as output parameter values of the stored procedure. As a result, a list of output parameter values is generated. The index begins with 1.

Note: If d is left empty, no output parameter is defined.

e

Position in the list of output parameter values generated in d. The value of this position is returned as the result of the function. The index begins with 1.

If set to -1, the function returns true if the statement executed successfully, false otherwise. The latter would otherwise lead to an exception.

f

Maximum number of rows to be read. Default: 1.

Note: Some databases perform data-changing statements (UPDATE, DELETE) only on a limited number of rows. In that case, use 0 (unlimited), otherwise, to make sure that more than one row is getting updated/deleted.


If the parameters have been added to list c in a type-specific manner, you can use placeholder (@columns@) in parameter a instead of syntax…(@0:s@,@1:f@)… The placeholder will be resolved within the function. The placeholder has to be specified without blanks.

Example: If you add a String, two Integers and an Double to list c (in that order), the placeholder (@columns@) in parameter a will be replaced by (@0:s@,@1:i@,@2:i@,@3:r@) before calling the procedure.

In order to detect errors due to an incorrect number of list items, the placeholder can also specify the number of call parameters: (@columns[4]@). If more than 4 values are in the list, the extra ones are ignored. If there are fewer values in the list than the required number, the function terminates with an error message.

Examples


Assume the following stored procedure (using MySQL).


CREATE PROCEDURE `adding_test`
(INOUT p1 VARCHAR(10), IN p2 INTEGER, IN p3 INTEGER, OUT p4 REAL)
BEGIN
DECLARE answer VARCHAR(10);
DECLARE result REAL;
IF p1 = 'plus' THEN
SET answer = 'added';
SET result = p2 + p3;
ELSE
SET answer = 'subtracted';
SET result = p2 - p3;
END IF;
select answer into p1;
select result into p4;
END


The list c used for the function call is created with function "add to list()" with the following parameters.


Parameter a

Parameter b

plus

paramList

1

paramList

2

paramList

Now the stored procedure is called. The examples apply to a call in a MySQL database. Note: If the executing database is an MSSQL, embed the actual statements in brackets, e.g. {call adding_test(@0:s@,@1:i@,@2:i@,@3:r@)} (so put the SQL statement in curly brackets). If the database is connected via a connector, the command execute must be used instead of call. For other databases, please refer to the documentation of the respective manufacturer for the correct syntax.


Parameter a

Parameter b

Parameter c

Parameter d

Parameter e

Parameter f

Result

call adding_test(@0:s@,@1:i@,@2:i@,@3:r@)

hub

paramList

1,4

(Note: Positions 1 and 4 are taken from the resultset (added,1,2,3.0) and thereby create the list (added,3.0))

2

(Note: The second position from the list (added,3.0) is taken.)


3.0

call adding_test(@0:s@,@1:i@,@2:i@,@3:r@)

hub

paramList

1,4

1


added

call adding_test(@0:s@,@1:i@,@2:i@,@3:r@)

hub

paramList

1,4

-1


true

call nonexist(@0:s@,@1:i@,@2:i@,@3:r@)

hub

paramList

1,4

1


Leads to an exception, because there is no stored procedure with that name.

call nonexist(@0:s@,@1:i@,@2:i@,@3:r@)

hub

paramList

1,4

-1


false