Subject | Re: [firebird-support] Generic StoredProc for returning generator value |
---|---|
Author | Mahesh Ishwar |
Post date | 2003-08-02T04:49:34Z |
Hi,
A generator generate values from -(2^64) to (2^64)-1.
This range of numbers can't be accomodated in INTEGER. U can use Numeric(18). It works fine.
As for pitfalls, as of now I can see anything.
Thanx.
Meghansh
sugi <truesaint@...> wrote:
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.
Yahoo! Groups SponsorADVERTISEMENT
To unsubscribe from this group, send an email to:
firebird-support-unsubscribe@yahoogroups.com
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
---------------------------------
Yahoo! Plus - For a better Internet experience
[Non-text portions of this message have been removed]
A generator generate values from -(2^64) to (2^64)-1.
This range of numbers can't be accomodated in INTEGER. U can use Numeric(18). It works fine.
As for pitfalls, as of now I can see anything.
Thanx.
Meghansh
sugi <truesaint@...> wrote:
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.
Yahoo! Groups SponsorADVERTISEMENT
To unsubscribe from this group, send an email to:
firebird-support-unsubscribe@yahoogroups.com
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
---------------------------------
Yahoo! Plus - For a better Internet experience
[Non-text portions of this message have been removed]