7. Embedded SQL for Pascal : Pascal Variables and Data Types : Embedded SQL/Pascal Declarations : Functions
 
Share this page                  
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.
3. For a description of formal parameters and their syntax, see Formal Parameter Declarations in this chapter.
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;