Oninit® SQLMorph — Calling Other Functions
CALL and nested calls
CALL tax(amount) RETURNING t, and a call inside an expression, are turned into a call through the engine’s
function dispatch (Fastpath). The converter works out the callee’s signature from the argument types, so the callee
is found by name and parameter types exactly as it would be from SQL. The callee may be another converted function, an
SPL routine or any C UDR with that signature.
An argument that is a computed value, including a DATETIME or INTERVAL expression, is passed with its derived type. An
argument whose type cannot be determined — a bare NULL or the result of another call — is
refused (SEM026); assign it to a typed variable first.
RETURN f(x) takes its type from f when f is in the same file and returns one
value, and so does arithmetic or || over such calls (RETURN f(x) + 1,
RETURN -f(x) / 4, RETURN f(x), f(x) * 2), with the usual numeric promotion. Recursion, several
values passed on (RETURN f(x) where f returns two), calls to functions in another file and
dates or intervals inside the expression still need a typed variable (SEM031).
Recursion
A function may call itself. Each level has its own state, and the depth is limited to 10,000 calls, after which the call fails with an error instead of exhausting the stack.
Several return values
RETURN a, b, c installs the function with the first value as its result and the others as OUT
parameters. CALL f() RETURNING x, y, z reads them back. Up to eight values are supported. Such a function can be
called from SPL or from another converted function, but not from a plain SELECT, because SQL has no way to
receive the extra values.
Functions that return rows
A routine that returns a set (RETURN ... WITH RESUME) is read through a cursor over
EXECUTE FUNCTION, which is also how 4GL does it:
DECLARE c CURSOR FOR EXECUTE FUNCTION list_orders(cust)
FOREACH c INTO oid, amt
...
END FOREACH
CALL cannot drive such a routine: the engine’s function dispatch returns one row at most.
Missing callees
The manifest and <name>_check.sql list every callee. If one is not installed the first call fails with a
clear “routine not found” error.