Functions
The syntax for an Embedded SQL/Pascal function is:
function function_name
[exec sql begin declare section;
(formal_parameters)
exec sql end declare section;]
: return_type_name;
[exec sql begin declare section;
declarations
exec sql end declare section;]
begin
[statements]
end;
or:
function function_name
[exec sql begin declare section;
(formal_parameters)
exec sql end declare section;]
: return_type_name;
exec sql label;
[exec sql begin declare section;
declarations
exec sql end declare section;]
begin
[statements]
exec sql end;
1. The function_name is not processed by Embedded SQL.
2. Formal parameters and variables declared in a function are globally visible to the end of the source file.
The following is an example of an Embedded SQL/Pascal function:
exec sql begin declare section;
var
errorbuf : varying[100] of char;
exec sql end declare section;
...
function wasdeadlock : boolean;
exec sql begin declare section;
const
EsqlDeadlock = -4700;
var
errnum : Integer;
exec sql end declare section;
begin
errnum := sqlca.sqlcode;
if errnum = EsqlDeadLock then
begin
SetErrorBuf( errnum, errorbuf );
WasDeadlock := TRUE;
end else
begin
errorbuf := ' ';
WasDeadlock := FALSE;
end;
end;