README.execute_block 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. SQL Language Extension: EXECUTE BLOCK
  2. Function:
  3. Allow execute PL-SQL block as if it is stored procedure.
  4. Supports input and output parameters
  5. Autor:
  6. Vlad Khorsun <hvlad at users.sourceforge.net>
  7. Syntax:
  8. EXECUTE BLOCK [ (param datatype = ?, param datatype = ?, ...) ]
  9. [ RETURNS (param datatype, param datatype, ...) }
  10. AS
  11. [DECLARE VARIABLE var datatype; ...]
  12. BEGIN
  13. ...
  14. END
  15. Client-side:
  16. The call isc_dsql_sql_info with parameter isc_info_sql_stmt_type returns
  17. - isc_info_sql_stmt_select, if block has output parameters.
  18. Semantics of a call is similar to SELECT query - client has open cursor,
  19. can fetch data from it, and must close it after use.
  20. - isc_info_sql_stmt_exec_procedure, if block has no output parameters.
  21. Semantics of a call is similar to EXECUTE query - client has no cursor,
  22. execution runs until first SUSPEND or end of block
  23. The client should preprocess only head of the SQL statement or use '?'
  24. instead of ':' as parameter indicator because in a body of the block may be links
  25. to local variables and \ or parameters with a colon ahead.
  26. Example:
  27. User SQL is
  28. EXECUTE BLOCK (X INTEGER = :X) RETURNS (Y VARCHAR)
  29. AS
  30. DECLARE V INTEGER;
  31. BEGIN
  32. INSERT INTO T(...) VALUES (... :X ...);
  33. SELECT ... FROM T INTO :Y;
  34. SUSPEND;
  35. END
  36. Preprocessed SQL is
  37. EXECUTE BLOCK (X INTEGER = ?) RETURNS (Y VARCHAR)
  38. AS
  39. DECLARE V INTEGER;
  40. BEGIN
  41. INSERT INTO T(...) VALUES (... :X ...);
  42. SELECT ... FROM T INTO :Y;
  43. SUSPEND;
  44. END