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

SAP Sybase SQL Anywhere 16.0 » SQL Anywhere Server - SQL Usage » The SQL Anywhere debugger » Tutorial: Getting started with the debugger


Lesson 2: Diagnosing the bug

Diagnose the bug in the debugger_tutorial stored procedure by setting breakpoints and then stepping through the code, watching the value of the variables as the procedure executes.


This lesson assumes that you have the roles and privileges listed in the Privileges section at the start of this tutorial: Tutorial: Getting started with the debugger.

This lesson assumes that you have completed all preceding lessons. See Lesson 1: Starting the debugger and finding the bug.

  1. In the right pane, in the SQL tab for the debugger_tutorial (GROUPO), locate the following statement:

    OPEN cursor_this_customer;
  2. Add a breakpoint by clicking the vertical gray area to the left of the statement. The breakpoint appears as a red circle.

  3. In the left pane, right-click debugger_tutorial (GROUPO) and click Execute from Interactive SQL.

    In the right pane of Sybase Central, a yellow arrow appears on top of the breakpoint.

  4. In the Debugger Details window, click the Local tab to display a list of local variables in the procedure, along with their current values and data types. The Top_Company, Top_Value, This_Value, and This_Company variables are all uninitialized and are therefore NULL.

  5. Press F11 to scroll through the procedure. The values of the variables change when you reach the following line:

    IF SQLSTATE = error_not_found THEN
  6. Press F11 twice more to determine which branch the execution takes. The yellow arrow moves back to the following text:

    customer_loop: loop

    The IF test did not return true. The test failed because a comparison of any value to NULL returns NULL. A value of NULL fails the test and the code inside the IF...END IF statement is not executed.

    At this point, you may realize that the problem is that Top_Value is not initialized.

  7. Test the hypothesis that the problem is the lack of initialization for Top_Value without changing the procedure code:

    1. In the Debugger Details window, click the Local tab.

    2. Click the Top_Value variable and type 3000 in the Value field, and then press Enter.

    3. Press F11 repeatedly until the Value field of the This_Value variable is greater than 3000.

    4. Click the breakpoint so that it turns gray.

    5. Press F5 to execute the procedure.

      The Interactive SQL window appears again and shows the correct results:

      top_company top_value
      Chadwicks 8076
    6. Close any open Interactive SQL windows.


The hypothesis is confirmed. The problem is that the Top_Value variable is not initialized.


Proceed to Lesson 3: Fixing the bug.

 See also