-- Copyright © Oracle Corporation 1995. All Rights Reserved. -- sql_dynamic_ada.sqlmod -- -- This SQL module provides the SQL procedures needed by the sql_dynamic.ada -- program. -- -- The module shows how to use SQL module language to process SQL -- statements generated dynamically by an Ada program. -- -- In order to compile the generated Ada package that lets you use this -- module with an Ada program, you must supply the /PACKAGE_COMPILATION -- qualifier on the module language command line. ------------------------------------------------------------------------------- -- Header Information Section ------------------------------------------------------------------------------- MODULE SQL_DYNAMIC -- Module name LANGUAGE ADA -- Language of calling program AUTHORIZATION SQL_SAMPLE -- Provides default authorization identifier PARAMETER COLONS -- Parameters are prefixed by colons ------------------------------------------------------------------------------- -- DECLARE Statements Section ------------------------------------------------------------------------------- -- Declare a cursor to process dynamic SELECT statements. DECLARE SEL CURSOR FOR DYN_STMT ------------------------------------------------------------------------------- -- Procedure Section ------------------------------------------------------------------------------- -- This procedure prepares a statement for dynamic execution from the string -- passed to it. PROCEDURE PREPARE_STMT (SQLCA, :STMT CHAR(1024)); PREPARE DYN_STMT FROM :STMT; -- This procedure writes information to an SQLDA (specifically, -- the sqlda_out SQLDA passed to the procedure by the calling program) -- about the number and data type of SELECT list items. PROCEDURE DESCRIBE_SELECT (SQLCA, SQLDA); DESCRIBE DYN_STMT SELECT LIST INTO SQLDA; -- This procedure writes information to an SQLDA (specifically, -- the sqlda_in SQLDA passed to the procedure by the calling program) -- about the number and data type of any parameter markers in the -- prepared dynamic statement. Note that SELECT statements may also -- have parameter markers. PROCEDURE DESCRIBE_PARM (SQLCA, SQLDA); DESCRIBE DYN_STMT MARKERS INTO SQLDA; -- This procedure dynamically executes a non-SELECT statement. -- SELECT statements are processed by DECLARE CURSOR, OPEN CURSOR, -- and FETCH statements. -- -- The EXECUTE statement specifies an SQLDA (specifically, -- the sqlda_in SQLDA passed to the procedure by the calling program) -- as the source of addresses for any parameter markers in the dynamic -- statement. -- -- Note that the EXECUTE statement with the USING DESCRIPTOR clause -- also handles statement strings that contain no parameter markers. -- If a statement string contains no parameter markers, SQL sets -- the SQLD field of the SQLDA to zero. PROCEDURE EXECUTE_STMT (SQLCA, SQLDA); EXECUTE DYN_STMT USING DESCRIPTOR SQLDA; -- This procedure opens the cursor SEL already declared. It specifies -- an SQLDA (specifically, the sqlda_in SQLDA passed to the procedure -- by the calling program) as the source of addresses for any parameter -- markers in the cursor's SELECT statement. PROCEDURE OPEN_CURSOR (SQLCA, SQLDA); OPEN SEL USING DESCRIPTOR SQLDA; -- This procedure fetches a row from the opened cursor and writes it to -- the addresses specified in an SQLDA (specifically, the sqlda_out SQLDA -- passed to the procedure by the calling program). PROCEDURE FETCH_ROW (SQLCA, SQLDA); FETCH SEL USING DESCRIPTOR SQLDA; -- This procedure closes the cursor. PROCEDURE CLOSE_CURSOR (SQLCA); CLOSE SEL; -- The procedure releases the prepared statement. It frees all resources -- for the statement. PROCEDURE RELEASE_STMT (SQLCA); RELEASE DYN_STMT; -- This procedure commits the transaction. PROCEDURE COMMIT_TRANSACTION (SQLCA); COMMIT; -- This procedure rolls back the transaction. PROCEDURE ROLLBACK_TRANSACTION (SQLCA); ROLLBACK;