Subject Re: [firebird-support] Dynamic SQL
Author Martijn Tonies
Hi,

> I apologise for these two simple questions but I'm not able to
> find answers in both the NG archive and the FB doc:
>
> 1. Can I create dynamic SQL statements (SELECT, INSERT, UPDATE,
> DELETE) inside the stored procedure or inside the trigger?
> Say I pass some values to the SP
> (say "table_name", "column_name", "col_value", "id_value") and inside
> the SP I want to execute statement:
>
> "UPDATE table_name SET column_name=col_value WHERE RowID=id_value"
>
> I know about the EXECUTE STATEMENT in the FB 1.5 but at this moment I
> have FB 1.0.3 only.

EXECUTE STATEMENT is new in Fb 1.5, so no, you cannot use
this in Fb 1.0.

> Can I perform these DSQLs in the FB 1.0?

No.

> 2. I want to create some stored procedures that do some functionality
> and I want to call these procedures from triggers - like this:
>
> CREATE TRIGGER TABLE1_BU0 FOR HLAVICKA1
> ACTIVE BEFORE UPDATE POSITION 0
> AS
> begin
> execute procedure sp_proc1( old, new );
> execute procedure sp_proc2( old, new );
> end
>
> Can I pass the "old" and "new" values into the SP (and "new"
> value "by reference" = as an output parameter (I need to change some
> col vals))?

No.

>Or is there another approach (I do not want to use the
> hardcoded way - to pass "old.col1", "new.col1", ...)?

OLD.Col1 etc is the only way.

With regards,

Martijn Tonies
Database Workbench - developer tool for InterBase, Firebird, MySQL & MS SQL
Server.
Upscene Productions
http://www.upscene.com