Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 10.0.1 » SQL Anywhere Server - SQL Usage » Debugging Procedures, Functions, Triggers, and Events » Tutorial: Getting started with the debugger » Lesson 2: Debug a stored procedure

Diagnose the bug Next Page

Confirm the diagnosis and fix the bug

You can test the hypothesis that the problem is the lack of initialization for top_value right in the debugger, without changing the procedure code.

To test the hypothesis
  1. Set a value for top_value.

    In the Local window, click the Value field of the top_value variable, and enter a value of 3000.

  2. Step through the loop again.

    Press F11 to step through the instructions to the IF statement and check the values of this_value and top_value. You may have to step through several loops until you get a value of this_value greater than 3000.

  3. Disable the breakpoint and execute the procedure.

    1. Click the breakpoint so that it turns gray (disabled).

    2. Press F5 to complete execution of the procedure.

      The Interactive SQL window appears again. It shows the correct results.


    The hypothesis is confirmed. The problem is that the top_value is not initialized.

To fix the bug
  1. From the Mode menu, choose Design mode.

  2. Immediately after the line containing the following text

    OPEN cursor_this_customer;

    Create a new line that initializes the top_value variable:

    SET top_value = 0;
  3. Press Ctrl+S to save the modified procedure.

  4. Execute the procedure again, and confirm that Interactive SQL displays the correct results.

You have now completed the lesson. Close any open Interactive SQL windows.