DotNetFirebird.org DotNetFirebird
Using Firebird SQL in .NET.
Monday, February 14, 2005

EXECUTE STATEMENT

This statement executes SQL or DDL command specified as a (string) parameter. It is a great tool for stored procedures where you can dynamically create the SQL code to be executed.

Syntax:

/* For statements that return nothing or a single row */
EXECUTE STATEMENT statement [INTO variable_list];

/* For statements that return multiple rows */
FOR EXECUTE STATEMENT statement INTO variable_list DO
compound_statement

Example:

SET TERM ^ ;

CREATE PROCEDURE MYPROC 
RETURNS (
  ID INTEGER,
  MYTEXT VARCHAR(20) CHARACTER SET UNICODE_FSS)
AS
BEGIN
  FOR EXECUTE STATEMENT 'SELECT id, mytext FROM mytable' INTO :id, :mytext DO
  BEGIN
    SUSPEND;
  END
END
^

SET TERM ; ^ 

You see that this is a really dumb example. It doesn't create the SQL dynamically so there is no reason to call it using EXECUTE STATEMENT. Ability to create the SQL dynamically gives you much more power in your stored procedures.

EXECUTE STATEMENT can be used for example for:

  • Creating complex WHERE clauses
  • Creating a new table or user in a stored procedure
  • Modifying metadata
  • etc....

Comments:

Hello,
we are making a vb.net/MSDE software now that will be installed on hundreds of pc's, and because of the MSDE 2Gb limitation, well... we are thinking about another solution.

One of the main point point for us is the ability to create dynamically a database, and execute SP so this new database could be loaded with data. The name and location of the new database are variable.

With MSDE, big trouble : we HAVE TO create and use dynamic SP, because database name is not constant. Does Firebird have the same behviour ?

Eric - from Tunisia.
I see no problem with having variable database name in Firebird.

For creating the database structure dynamically you can run batch SQL/DDL scripts using FbScript class.
Blog comments are closed.



Previous

Archives