Program type MAIN support for C and C++ procedures
Although the default PROGRAM TYPE clause value SUB is generally recommended for C procedures, the PROGRAM TYPE clause value MAIN is supported in CREATE PROCEDURE statements where the LANGUAGE clause value is C.
The PROGRAM TYPE clause value MAIN is required for routines with greater than ninety parameters.
When a PROGRAM TYPE MAIN clause is specified, procedures must be
implemented using a signature that is consistent with the default
style for a main routine in a C source code file. This does not mean
that the routine must be implemented by a function named main
,
but rather that the parameters be passed in the format generally associated
with a default type main routine application implementation that uses
typical C programming argc
and argv
arguments.
SQL_API_RC SQL_API_FN functionName(int argc, char **argv)
{
...
}
The total number of arguments to the function is specified by the value of argc. The argument values are passed as array elements within the argv array. The number and order of the arguments depends on the PARAMETER STYLE clause value specified in the CREATE PROCEDURE statement.
CREATE PROCEDURE MAIN_EXAMPLE (
IN job CHAR(8),
OUT salary DOUBLE)
SPECIFIC CPP_MAIN_EXAMPLE
DYNAMIC RESULT SETS 0
NOT DETERMINISTIC
LANGUAGE C
PARAMETER STYLE SQL
NO DBINFO
FENCED NOT THREADSAFE
READS SQL DATA
PROGRAM TYPE MAIN
EXTERNAL NAME 'spserver!MainExample'@
//*****************************************************
// Stored Procedure: MainExample
//
// SQL parameters:
// IN: argv[1] - job (char[8])
// OUT: argv[2] - salary (double)
//*****************************************************
SQL_API_RC SQL_API_FN MainExample(int argc, char **argv)
{
...
}
Because PARAMETER STYLE SQL is used, in addition to the SQL parameter values passed at procedure invocation time, the additional parameters required for that style are also passed to the routine.
argc : Number of argv array elements
argv[0]: The function name
argv[1]: Value of parameter job (char[8], input)
argv[2]: Value of parameter salary (double, output)
argv[3]: null indicator for parameter job
argv[4]: null indicator for parameter salary
argv[5]: sqlstate (char[6], output)
argv[6]: qualName (char[28], output)
argv[7]: specName (char[19], output)
argv[8]: diagMsg (char[71], output)