Subject | Generic StoredProc for returning generator value |
---|---|
Author | sugi |
Post date | 2003-07-31T22:51:27Z |
Dear All,
After seeing the following bit in WHATSNEW.TXT (FB1.5 rc3):
...
* Improved EXECUTE STATEMENT.
Now it's possible to return values from the dynamic SQL.
Syntax:
EXECUTE STATEMENT <value> INTO <var_list>; (singleton form)
or
FOR EXECUTE STATEMENT <value> INTO <var_list> DO <stmt_list>;
Contributor(s):
Alexander Peshkoff <peshkoff@...>
...
I tried creating a generic storedproc that will return a generator's
value, something like this :
...
CREATE PROCEDURE GETNEXTGENVALUE (
GENNAME VARCHAR(30))
RETURNS (
GENVALUE BIGINT)
AS
begin
/* Procedure Text */
execute statement ( 'select gen_id(' || :genName || ', 1) from
rdb$Database' ) into :genvalue;
suspend;
end
...
So far so good, (although IBExpert's precompiler doesn't yet recognize
the EXECUTE..INTO.. statement). Now I can call them by name instead of
creating one storedproc for each generator :
...
Select getNextGenValue(MyGen) from rdb$Database;
...
I have two questions at this point:
1. What is the proper data type for values returned by generators?
From my test, GENVALUE has to be BIGINT. If I declare GENVALUE as
integer, then FB will output error about 'data type mismatch' or
something like that. Is this ok?
2. Is the above construct (procedure getNextGenValue()) safe to use? Any
caveats/pitfalls I should be aware of?
Thanks in advance,
sugi.
After seeing the following bit in WHATSNEW.TXT (FB1.5 rc3):
...
* Improved EXECUTE STATEMENT.
Now it's possible to return values from the dynamic SQL.
Syntax:
EXECUTE STATEMENT <value> INTO <var_list>; (singleton form)
or
FOR EXECUTE STATEMENT <value> INTO <var_list> DO <stmt_list>;
Contributor(s):
Alexander Peshkoff <peshkoff@...>
...
I tried creating a generic storedproc that will return a generator's
value, something like this :
...
CREATE PROCEDURE GETNEXTGENVALUE (
GENNAME VARCHAR(30))
RETURNS (
GENVALUE BIGINT)
AS
begin
/* Procedure Text */
execute statement ( 'select gen_id(' || :genName || ', 1) from
rdb$Database' ) into :genvalue;
suspend;
end
...
So far so good, (although IBExpert's precompiler doesn't yet recognize
the EXECUTE..INTO.. statement). Now I can call them by name instead of
creating one storedproc for each generator :
...
Select getNextGenValue(MyGen) from rdb$Database;
...
I have two questions at this point:
1. What is the proper data type for values returned by generators?
From my test, GENVALUE has to be BIGINT. If I declare GENVALUE as
integer, then FB will output error about 'data type mismatch' or
something like that. Is this ok?
2. Is the above construct (procedure getNextGenValue()) safe to use? Any
caveats/pitfalls I should be aware of?
Thanks in advance,
sugi.