Subject Re: [firebird-support] Using "twice-dynamic" SQL in a stored procedure
Author Alexandre Benson Smith
mizbrodin wrote:
> I have a set of tables having the same structure like "CREATE TABLE
> tables_list1 (tblname VARCHAR(128))" (let's call them "list tables").
> These list tables contain the names of some other tables (let's call
> them "referenced tables"). I need to implement a stored procedure,
> which would accept the name of a list table via an input parameter and
> perform some actions on the referenced tables (granting different
> permissions on these tables, to be more precise). I would use a query
> like "FOR SELECT ... DO", but such a query requires the usage of a
> static table name, while in my case the table name is a variable (a
> parameter passed to my stored procedure). Is anybody aware of any
> solutions or workarounds for this problem?
>
> Note, that I could do it using dynamic SQL generated in the code of my
> application without any problems, but for performance reasons I have
> to perform these operations using a stored procedure. So, the usage of
> a stored procedure is a mandatory requirement. I already implemented
> such kind of stored procedures for both SQL Server and Oracle, but
> have been stuck with Firebird.
>
> Thanks a lot in advance for any help.
>
> (I'm using Firebird 2.1)
>

You could use EXECUTE STATEMENT but since it's not pre-compiled the
performance will be equal to a client's generated SQL I think.

If you wish th best performance I think the only way to go is to use
nested if's and in each if a separated SP or the code to execute the
desired query.

see you !

--
Alexandre Benson Smith
Development
THOR Software e Comercial Ltda
Santo Andre - Sao Paulo - Brazil
www.thorsoftware.com.br