-- ABSTRACT: -- -- This module is the first in a series of two that demonstrates the -- dynamic interface of SQL using SQL module language and Ada. The -- second Ada module is named sql_dynamic. -- -- This module accepts a string that contains an SQL statement -- and then calls the other module to process it. -- -- You can adapt the modules to your own needs. For example, you can -- substitute your own module for this driver. Instead of prompting -- the user for an SQL statement, your module could use -- other methods to generate SQL statements to pass to sql_dynamic: -- -- - Construct an SQL statement from parameters passed by a -- calling module. -- - Parse a non-SQL statement from a calling module and -- build an SQL statement from it. -- -- However the module generates an SQL statement, it can be passed to -- a module similar to sql_dynamic for processing. with CONDITION_HANDLING; with TEXT_IO; use TEXT_IO; procedure SQL_DYNAMIC_DRIVER is -- Declare the parameters for the SQL statement input by the user. MAX_STRLNG : constant integer := 1024; subtype ST is string(1..max_strlng); STMT : st := (others => ' '); -- Parameters for parsing the statement: PART_STMT : string (1..64) := (others => ' '); BEGIN_POS,END_POS,POS : integer; LAST : natural; -- Declare the subunit that will handle the statement processing. procedure sql_dynamic(sql_stmt : in st) is separate; ------------------------------------------------------------------------------- -- Main program for SQL_DYNAMIC_DRIVER ------------------------------------------------------------------------------- begin -- Prompt the user to enter an SQL statement. new_line(24); put("Enter any valid dynamic SQL statement, "); put_line("continuing it on successive lines."); put_line("Terminate the statement with a semicolon."); put_line("Use or to exit."); new_line; -- The main loop. It executes until the user enters . -- in the get_line call generates an end_error that -- will be handled by a null exception. loop begin_pos := 1; stmt := (others => ' '); put("SQL_STATEMENT> "); -- This inner loop accepts partial lines and prompts for continuation until -- the user enters a semicolon. loop get_line(part_stmt,last); if last > 0 then end_pos := (begin_pos + last) - 1; stmt(begin_pos..end_pos) := part_stmt(1..last); stmt(end_pos + 1) := ' '; begin_pos := (begin_pos + last) + 1; if part_stmt(last) = ascii.semicolon then stmt(end_pos) := ' '; exit; end if; end if; put("Cont> "); end loop; -- Pass the STMT parameter containing the SQL statement to -- the SQL_DYNAMIC procedure in the sql_dynamic module for processing. sql_dynamic(stmt); end loop; exception when end_error => null; end SQL_DYNAMIC_DRIVER;