SPL name from within SPL?
Posted in 2015
A user on Informix 12.10 asked whether an SPL routine can discover its own name at runtime (something like C's argv[0]), to avoid hardcoded names being wrongly copy-pasted into logging code across 1000+ procedures. No built-in feature exists. Suggestions: parse the executing statement from sysmaster:sysconblock using dbinfo('sessionid') (may return multiple rows), set/clear a global variable with the routine name at the start/end of each SPL (possibly with push-pop for nesting), embed an SCCS/RCS string, or use SQLTRACE at HIGH level / onstat -g sql for SPL stack traces. Art suggested filing an IBM RFE; the user hit form problems submitting it. No built-in solution was found.
Auto-generated by DrWatson from the posts below — may be imperfect; read the full thread.
Topics: Stored Procedures & SPL
Informix 12.10 Is there a way to determine the name of the stored procedure, from within the stored procedure? Thank you. DG
AFAIK, only indirectly by getting the session id and parsing the command
that executed it from the sysmaster:sysconblock "WHERE cbl_sessionid =
dbinfo('sessionid') and (cbl_stmt matches'*[Ee][Xx][Ee][Cc][Uu][Tt][Ee]*'. But that may get you multiple results if
the session has recently executed multiple SPL routines.
The best way is to standardize on setting a global variable to the name of
the function in the SPL code itself at the beginning and clearing it at the
end. That way it is even possible to query the name of the running
procedure within a FETCH loop outside the function. If you want multiple
layers of names of callers and called procs, you can work out a push-pop
functionality to handle it.
Art
Art S. Kagel, President and Principal Consultant
ASK Database Management
www.askdbmgt.com
Blog: http://informix-myview.blogspot.com/
Disclaimer: Please keep in mind that my own opinions are my own opinions
and do not reflect on the IIUG, nor any other organization with which I am
associated either explicitly, implicitly, or by inference. Neither do
those opinions reflect those of other individuals affiliated with any
entity with which I am affiliated nor those of the entities themselves.
On Thu, Oct 22, 2015 at 4:07 PM, DAVID GROVE <david.grove@alaska.gov> wrote:
> Informix 12.10
>
> Is there a way to determine the name of the stored procedure, from within
> the
> stored procedure?
>
> Thank you.
>
> DG
>
>
>
>
*******************************************************************************
> Forum Note: Use "Reply" to post a response in the discussion forum.
>
>
--001a114220acabca400522b7410d
I gotta ask...Why is this piece of information needed? Madison Pruet Retired from IBM On Thursday, October 22, 2015 3:08 PM, DAVID GROVE <david.grove@alaska.gov> wrote: Informix 12.10 Is there a way to determine the name of the stored procedure, from within the stored procedure? Thank you. DG ******************************************************************************* Forum Note: Use "Reply" to post a response in the discussion forum.
We've put it in a sccs/rcs string within the Spl before now
Cheers
Paul
Paul Watson
Oninit www.oninit.com
+1 913 387 7529
Oninit® is a Registered Trademark of Oninit LLC
> On Oct 22, 2015, at 15:22, Art Kagel <art.kagel@gmail.com> wrote:
>
> AFAIK, only indirectly by getting the session id and parsing the command
> that executed it from the sysmaster:sysconblock "WHERE cbl_sessionid =
> dbinfo('sessionid') and (cbl_stmt matches> '*[Ee][Xx][Ee][Cc][Uu][Tt][Ee]*'. But that may get you multiple results if
> the session has recently executed multiple SPL routines.
>
> The best way is to standardize on setting a global variable to the name of
> the function in the SPL code itself at the beginning and clearing it at the
> end. That way it is even possible to query the name of the running
> procedure within a FETCH loop outside the function. If you want multiple
> layers of names of callers and called procs, you can work out a push-pop
> functionality to handle it.
>
> Art
>
> Art S. Kagel, President and Principal Consultant
> ASK Database Management
> www.askdbmgt.com
>
> Blog: http://informix-myview.blogspot.com/
>
> Disclaimer: Please keep in mind that my own opinions are my own opinions
> and do not reflect on the IIUG, nor any other organization with which I am
> associated either explicitly, implicitly, or by inference. Neither do
> those opinions reflect those of other individuals affiliated with any
> entity with which I am affiliated nor those of the entities themselves.
>
>> On Thu, Oct 22, 2015 at 4:07 PM, DAVID GROVE <david.grove@alaska.gov> wrote:
>>
>> Informix 12.10
>>
>> Is there a way to determine the name of the stored procedure, from within
>> the
>> stored procedure?
>>
>> Thank you.
>>
>> DG
>
*******************************************************************************
>> Forum Note: Use "Reply" to post a response in the discussion forum.
>
> --001a114220acabca400522b7410d
>
>
>
*******************************************************************************
> Forum Note: Use "Reply" to post a response in the discussion forum.
To facilitate logging. In the immediate case, I plan to create a table whose PK is SPL name. Other columns will contain info that will be populated dynamically, from inside the SPL. I'd like to be able to retrieve the SPL name, without error, to use in building the INSERT statement. In the past, we have written desired info to a text file. This desired info includes the name of the SPL. However, we have >1000 SPLs, and, you can guess what occasionally happens, when the SPL name is hardcoded into such a reporting mechanism. Someone does a copy-and-paste and neglects to edit the name to the current SPL. Then you get information ascribed to the wrong SPL. This can be serious. It would be a great aid to be able to know, for sure, that the name being used to refer to the current SPL is (guaranteed) to be correct. So, probably the best way to avoid errors from having to manually code the SPL name inside the SPL, would seem to be along the lines Art suggests. (a dynamic solution.) Thank you all for your helpful comments. Regards, DG
P.S. Something comparable to C's argv[0] would be the kind of thing we would find useful.
Thank you, Art. Think I'll try it. Maybe I can use "FIRST" (assuming I can determine a usable "ORDER BY") to guarantee the single, correct answer. DG
Go to the IBM RFE (Request For Enhancement) site and put in a request. Then post the request # here so people can vote for it if they also think it would be useful. The URL is: https://www.ibm.com/developerworks/rfe/execute?use_case=changeRequestLanding Art Art S. Kagel, President and Principal Consultant ASK Database Management www.askdbmgt.com Blog: http://informix-myview.blogspot.com/ Disclaimer: Please keep in mind that my own opinions are my own opinions and do not reflect on the IIUG, nor any other organization with which I am associated either explicitly, implicitly, or by inference. Neither do those opinions reflect those of other individuals affiliated with any entity with which I am affiliated nor those of the entities themselves. On Thu, Oct 22, 2015 at 5:26 PM, DAVID GROVE <david.grove@alaska.gov> wrote: > P.S. Something comparable to C's argv[0] would be the kind of thing we > would > find useful. > > > > ******************************************************************************* > Forum Note: Use "Reply" to post a response in the discussion forum. > > --089e0103e366d45b530522b84d92
Adding to Art's idea, you can turn on SQLTRACE with level
set to HIGH will provide the stack trace for SPL procedures.
Also onstat -g sql will provide the procedure stack trace.
John F. Miller III
STSM, Lead Architect
miller3@us.ibm.com
503-747-1366
IBM Informix Dynamic Server (IDS)
ids-bounces@iiug.org wrote on 10/22/2015 01:22:43 PM:
> From: "Art Kagel" <art.kagel@gmail.com>
> To: ids@iiug.org
> Date: 10/22/2015 01:23 PM
> Subject: Re: SPL name from within SPL? [35931]
> Sent by: ids-bounces@iiug.org
>
> AFAIK, only indirectly by getting the session id and parsing the command
> that executed it from the sysmaster:sysconblock "WHERE cbl=5Fsessionid =3D
> dbinfo('sessionid') and (cbl=5Fstmt matches> '*[Ee][Xx][Ee][Cc][Uu][Tt][Ee]*'. But that may get you multiple results
if
> the session has recently executed multiple SPL routines.
>
> The best way is to standardize on setting a global variable to the name
of
> the function in the SPL code itself at the beginning and clearing it at
the
> end. That way it is even possible to query the name of the running
> procedure within a FETCH loop outside the function. If you want multiple
> layers of names of callers and called procs, you can work out a push-pop
> functionality to handle it.
>
> Art
>
> Art S. Kagel, President and Principal Consultant
> ASK Database Management
> www.askdbmgt.com
>
> Blog: http://informix-myview.blogspot.com/
>
> Disclaimer: Please keep in mind that my own opinions are my own opinions
> and do not reflect on the IIUG, nor any other organization with which I
am
> associated either explicitly, implicitly, or by inference. Neither do
> those opinions reflect those of other individuals affiliated with any
> entity with which I am affiliated nor those of the entities themselves.
>
> On Thu, Oct 22, 2015 at 4:07 PM, DAVID GROVE <david.grove@alaska.gov>
wrote:
>
> > Informix 12.10
> >
> > Is there a way to determine the name of the stored procedure, from
within
> > the
> > stored procedure?
> >
> > Thank you.
> >
> > DG
> >
> >
> >
> >
>
***************************************************************************=
****
> > Forum Note: Use "Reply" to post a response in the discussion forum.
> >
> >
>
> --001a114220acabca400522b7410d
>
>
>
***************************************************************************=
****
> Forum Note: Use "Reply" to post a response in the discussion forum.
>
Thank you for the suggestion, Art. I tried to, but, the "Component" and "Operating system" are both required fields. Unfortunately, they are greyed out, and I am not permitted either to make a selection from the dropdown (dropdown disabled) or to type information (greyed out). Of course, clicking "Submit" results in the rejection message informing me that I need to complete the required fields. It's the old "Can't get there from here" problem. DG
I assume you are referring to the RFE Community page (I use the Forums email gateway which doesn't give me any threading). Ahh, you need to login with an IBM ID first. If you don't have one you can register for one, it's free. Just click on either <Sign In> or <Register> at the top right of the landing page. Once you are signed in you can enter RFEs. Art Art S. Kagel, President and Principal Consultant ASK Database Management www.askdbmgt.com Blog: http://informix-myview.blogspot.com/ Disclaimer: Please keep in mind that my own opinions are my own opinions and do not reflect on the IIUG, nor any other organization with which I am associated either explicitly, implicitly, or by inference. Neither do those opinions reflect those of other individuals affiliated with any entity with which I am affiliated nor those of the entities themselves. On Fri, Oct 23, 2015 at 12:29 PM, DAVID GROVE <david.grove@alaska.gov> wrote: > Thank you for the suggestion, Art. > > I tried to, but, the "Component" and "Operating system" are both required > fields. Unfortunately, they are greyed out, and I am not permitted either > to > make a selection from the dropdown (dropdown disabled) or to type > information > (greyed out). Of course, clicking "Submit" results in the rejection message > informing me that I need to complete the required fields. > > It's the old "Can't get there from here" problem. > > DG > > > > ******************************************************************************* > Forum Note: Use "Reply" to post a response in the discussion forum. > > --001a1140421a0bcd800522c8a7e3
Thank you, Art. I did login with my IBM ID. I have successfully submitted RFEs in the past. This is the first time it hasn't worked for me. I'll try again. DG