Dynamic SQL protocol

NoteThe precompiler does not generate stored procedures for dynamic SQL statements because the statements are not complete until runtime. At runtime, Adaptive Server stores them as temporary stored procedures in the tempdb database. The tempdb database must contain the user name "guest", which in turn must have create procedure permission. Otherwise, attempting to execute one of these temporary stored procedures generates the error message, "Server user id user_id is not a valid user in database database_name," where user_id is the user’s user ID, and database_name is the name of the user’s database.

The dynamic SQL prepare statement sends the actual SQL statement, which can be any Data Definition Language(DDL) or Data Manipulation Language (DML) statements, or any Transact-SQL statement except create procedure.

The dynamic SQL facility performs these actions:

  1. Translates the input data into a SQL statement.

  2. Verifies that the SQL statement can execute dynamically.

  3. Prepares the SQL statement for execution, sending it to Adaptive Server, which compiles and saves it as a temporary stored procedure (for methods 2, 3, and 4).

  4. Binds all input parameters or descriptor (for methods 2, 3, and 4).

  5. Executes the statement.

    For a varying-list select, it uses a descriptor to reference the data items and rows returned (for method 4).

  6. Binds the output parameters or descriptor (for methods 2, 3, and 4).

  7. Obtains results.

  8. Drops the statement (for methods 2, 3, and 4) by deactivating the stored procedure in Adaptive Server.

  9. Handles all error and warning conditions from Adaptive Server and Client-Library.