cancel
Showing results for 
Search instead for 
Did you mean: 

how to determine the envoker of a function

Baron
Participant
1,094

I have created a functionA in SQL Anywhere 17, and then set it to hidden.

I want to restrict the use of this function to a list of procedures (i.e. only ProcedureA & ProcedureB may make use of the functionA).

Is there a way to ask within functionA from which procedure am I called?

In the documentation I found only the SQL SECURITY clause which is not exactly what I want!

Accepted Solutions (1)

Accepted Solutions (1)

VolkerBarth
Contributor

Starting with v17, there are four new special values that will be of help:

Use INVOKING USER, SESSION USER, EXECUTING USER, and PROCEDURE OWNER to determine which users can execute, and are executing, procedures and user-defined functions.

Baron
Participant
0 Kudos

Thanks for the answer, but these four special values help me to determine the user, and not the name of the calling procedure.

But yes, I can I can create my UserA, and then create my ProcedureA & ProcedureB in the name of this UserA, so that it can work as I want.

Thank you

Answers (1)

Answers (1)

VolkerBarth
Contributor

Oops, sorry, apparently I misread your question...

You can probably include calls to the stack_trace() system function or the similar sa_strack_trace() system procedure to find out about invokers.

Say, something like:

message 'Function stack: ' || stack_trace('caller', 'stack+sql')  to log;
Baron
Participant
0 Kudos

I have tried STACK_TRACE and it worked and did exactly what I want! Thank you!