Subject Re: [firebird-support] Call Generator in Stored Procedure
Author Helen Borrie
At 08:43 AM 30/05/2005 +0700, you wrote:
>Can I call generator in Stored procedure via input parameter ?
>example:
> insert into xxx values(gen_id(:par1,1),:par2);

Not this way. Reason, you can't pass metadata object identifiers (the name
of the generator and the table, for example) as parameters.

You can only do this with DSQL:

...
as
declare variable new_id BigInt;
begin
....
new_id = gen_id(KnownGeneratorName, 1);
...
end

However, you can take string inputs for the identifier names and use them
in a string for execution by EXECUTE STATEMENT, e.g.

create procedure get_gen_id (genname varchar(31), tblname varchar(31))
returns (gen_idval BigInt)
as
declare exestring varchar(75) 'INSERT INTO ';
begin
exestring = exestring || par2 || ' VALUES (GEN_ID (' || par1 || ', 1)';
EXECUTE STATEMENT exestring;
end

But your "generic syntax" would only work for tables with only one column!!

./heLen