You can use host variables as parameters to functions.
You must precede the name of the host variable with the parameter keyword
to declare it as a function parameter.
For example, the following figure shows a code fragment
with a Kernighan and Ritchie-style prototype declaration that expects
three parameters, two of which are host variables. Figure 1: Using EXEC SQL to declare host
variables as parameters to a Kernighan and Ritchie-Style function
declaration
f(s, id, s_size)
EXEC SQL BEGIN DECLARE SECTION;
PARAMETER char s[20];
PARAMETER int id;
EXEC SQL END DECLARE SECTION;
int s_size;
{
select fname into :s from customer
where customer_num = :id;
;
}
f(s, id, s_size)
$parameter char s[20];
$parameter int id;
int s_size;
You can declare parameters in an ANSI-style prototype
function declaration as host variables as well. You can also put all
parameters to a prototype function declaration inside the EXEC SQL
declare section, even if some of the parameters cannot be used as
host variables. The following figure shows that the function pointer f can
be included in the EXEC SQL declare section, even though it is not
a valid host-variable type and cannot be used as a host variable. Figure 3: Using EXEC SQL
to declare host variables as parameters to ANSI-style function declaration
int * foo(
EXEC SQL BEGIN DECLARE SECTION;
PARAMETER char s[20],
PARAMETER int id,
PARAMETER int (*f) (double)
EXEC SQL END DECLARE SECTION;
)
{
select fname into :s from customer
where customer_num = :id;
;
}
The functionality that allows inclusion of function parameters
inside of the EXEC SQL declare section is in compliance with the requirement
that any valid C declaration syntax must be allowed inside the EXEC
SQL declare sections to use common header files for C and source
files. For more information about how to use common header files between
C and source
files, see ids_esqlc_0091.html#ids_esqlc_0091.
Important: If you want to define host
variables that are ANSI-style parameters, you must use the EXEC SQL
BEGIN DECLARE SECTION and the EXEC SQL END DECLARE SECTION syntax.
You cannot use the $BEGIN DECLARE and $END DECLARE syntax. This restriction
is because SQL statements that begin with the dollar sign ($) notion
must end with a semicolon (;). However, ANSI syntax requires that
each parameter in a parameter list does not end with a semicolon terminator,
but with a comma (,) delimiter.
The following limitations apply to using host variables
as function parameters:
You cannot declare a parameter variable inside a block of C code.
You cannot use the parameter keyword in declarations of
host variables that are not part of a function header. If you do,
you receive unpredictable results.