ASA SQL User's Guide
Debugging Logic in the Database
Tutorial: Getting started with the debugger
Lesson 2: Debug a stored procedure
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
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.
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 top_value greater than 3000.
Disable the breakpoint and execute the procedure.
Click the breakpoint so that it turns gray (disabled).
Press F5 to complete execution of the procedure.
The Interactive SQL window appears again. It shows the correct results.
top_company | top_value |
---|---|
Chadwicks | 8076 |
The hypothesis is confirmed. The problem is that the top_value is not initialized.
To fix the bug
From the Task menu, choose Design to leave Debug mode.
Immediately after the line containing the following text
open cur_this_cust;
Create a new line that initializes the top_value variable:
set top_value = 0;
Press Ctrl+S to save the modified procedure.
Execute the procedure again, and confirm that Interactive SQL displays the correct results.
You have now completed the lesson. Close down Sybase Central and any open Interactive SQL windows.