8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-02-02 09:20:39 +01:00

1. Added new EXECUTE BLOCK statement

2. Added 	default paremeters in stored procedures
This commit is contained in:
hvlad 2004-01-16 09:32:57 +00:00
parent 2d03929fdd
commit c0e9a56fc8
2 changed files with 163 additions and 0 deletions

View File

@ -0,0 +1,108 @@
SQL Language Extension: default paremeters in stored procedures
Function:
allow input parameters of stored procedures to have optional default values
Autor:
Vlad Horsun <horsun at kdb.dp.ua>
Syntax:
same as default value definition of column or domain, except that
you can use '=' in place of 'DEFAULT' keyword. Parameters with default values
must be last in parameter list i.e. not allowed to define parameter without
default value after parameter with default value. Caller must set first few
parameters, i.e. not allowed set param1, param2, miss param3, set param4...
Default values substitution occurs at run-time. If you define procedure with
defaults (say P1), call it from another procedure (say P2) and skip some last
parameters (with default value) then default values for P1 will be substituted
by the engine at time of the beginning of execution P1. Then if you change
default values for P1 it is not need to recompile P2. But it is still necessary
to disconnect all client connections, for more details see IB6 Beta documentation
"Data Definition Guide", section "Altering and dropping procedures in use"
Examples:
CONNECT ... ;
CREATE PROCEDURE P1 (X INTEGER = 123)
RETURNS (Y INTEGER)
AS
BEGIN
Y = X;
SUSPEND;
END;
COMMIT;
SELECT * FROM P1;
Y
============
123
EXECUTE PROCEDURE P1;
Y
============
123
CREATE PROCEDURE P2
RETURNS (Y INTEGER)
AS
BEGIN
FOR SELECT Y FROM P1 INTO :Y
DO SUSPEND;
END;
COMMIT;
SELECT * FROM P2;
Y
============
123
ALTER PROCEDURE P1 (X INTEGER = CURRENT_TRANSACTION)
RETURNS (Y INTEGER)
AS
BEGIN
Y = X;
SUSPEND;
END;
COMMIT;
SELECT * FROM P1;
Y
============
5875
SELECT * FROM P2;
Y
============
123
COMMIT;
CONNECT ... ;
SELECT * FROM P2;
Y
============
5880
Notes:
default sources and BLR's are kept in RDB$FIELDS

View File

@ -0,0 +1,55 @@
SQL Language Extension: EXECUTE BLOCK
Function:
Allow execute PL-SQL block as if it is stored procedure.
Supports input and output parameters
Autor:
Vlad Horsun <horsun@kdb.dp.ua>
Syntax:
EXECUTE BLOCK [ (param datatype = ?, param datatype = ?, ...) ]
[ RETURNS (param datatype, param datatype, ...) }
AS
[DECLARE VARIABLE var datatype; ...]
BEGIN
...
END
Client-side:
The call isc_dsql_sql_info with parameter isc_info_sql_stmt_type returns
- isc_info_sql_stmt_select, if block has output parameters.
Semantics of a call is similar to SELECT query - client has open cursor,
can fetch data from it, and must close it after use.
- isc_info_sql_stmt_exec_procedure, if block has no output parameters.
Semantics of a call is similar to EXECUTE query - client has no cursor,
execution runs until first SUSPEND or end of block
The client should preprocess only head of the SQL statement or use '?'
instead of ':' as parameter indicator because in a body of the block may be links
to local variables and \ or parameters with a colon ahead.
Example:
User SQL is
EXECUTE BLOCK (X INTEGER = :X) RETURNS (Y VARCHAR)
AS
DECLARE V INTEGER;
BEGIN
INSERT INTO T(...) VALUES (... :X ...);
SELECT ... FROM T INTO :Y;
SUSPEND;
END
Preprocessed SQL is
EXECUTE BLOCK (X INTEGER = ?) RETURNS (Y VARCHAR)
AS
DECLARE V INTEGER;
BEGIN
INSERT INTO T(...) VALUES (... :X ...);
SELECT ... FROM T INTO :Y;
SUSPEND;
END