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.
Prerequisites
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.
In the right pane, in the SQL tab for the debugger_tutorial (GROUPO), locate the following statement:
OPEN cursor_this_customer; |
Add a breakpoint by clicking the vertical gray area to the left of the statement. The breakpoint appears as a red circle.
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.
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.
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 |
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.
Test the hypothesis that the problem is the lack of initialization for Top_Value without changing the procedure code:
In the Debugger Details window, click the Local tab.
Click the Top_Value variable and type 3000 in the Value field, and then press Enter.
Press F11 repeatedly until the Value field of the This_Value variable is greater than 3000.
Click the breakpoint so that it turns gray.
Press F5 to execute the procedure.
The Interactive SQL window appears again and shows the correct results:
top_company | top_value |
---|---|
Chadwicks | 8076 |
Close any open Interactive SQL windows.
![]() |
Discuss this page in DocCommentXchange.
|
Copyright © 2014, SAP AG or an SAP affiliate company. - SAP Sybase SQL Anywhere 16.0 |