I have been trying to find some information that would help me better understand how to use the SQL Prepare/Declare statements in an rpgle program. My understanding is that there is a performance benefit to using prepare in scenarios where an sql query will be executed multiple times. However, I am writing a service program used in IWS and would like to execute the prepare/declare statements only once. In a simple program it is easy to execute the prepare and declare at the start of the program I can't seem to find any information that would help me determine the following:
1. Is there a keyword or function that I can call to determine if a cursor has been declared already. I would liken that to the if %open() function used on user open files to determine if it is necessary to open the file or not.
2. Does RPG recognize if a prepare/declare pair has already been executed and skip over it again if the same procedure in a service program is executed and the prepare and declare statements are a part of that procedure?
3. If my service program is set to close the SQL cursor when the activation group ends, can I simply set my own initialization routine in the service program that only executes once, or is there a timeout or a penalty to keeping that prepared statement opened indefinitely if that service program is always active? I'm a little fuzzy on when IWS might end the activation group for a service progam responding to restful requests.
Any information would be greatly appreciated.
1. Is there a keyword or function that I can call to determine if a cursor has been declared already. I would liken that to the if %open() function used on user open files to determine if it is necessary to open the file or not.
2. Does RPG recognize if a prepare/declare pair has already been executed and skip over it again if the same procedure in a service program is executed and the prepare and declare statements are a part of that procedure?
3. If my service program is set to close the SQL cursor when the activation group ends, can I simply set my own initialization routine in the service program that only executes once, or is there a timeout or a penalty to keeping that prepared statement opened indefinitely if that service program is always active? I'm a little fuzzy on when IWS might end the activation group for a service progam responding to restful requests.
Any information would be greatly appreciated.
Comment