INFORMIX
Informix Guide to SQL: Tutorial
Chapter 14: Creating and Using SPL Routines
Home Contents Index Master Index New Book

Debugging an SPL Routine

Once you successfully create and run an SPL routine, you can encounter logic errors. If the routine has logic errors, use the TRACE statement to help find them. You can trace the values of the following items:

To generate a listing of traced values, first use the SQL statement SET DEBUG FILE to name the file that is to contain the traced output. When you create the SPL routine, include a TRACE statement.

The following methods specify the form of TRACE output:

TRACE ON

traces all statements except SQL statements. The contents of variables are printed before they are used. Routine calls and returned values are also traced.

TRACE PROCEDURE

traces only the routine calls and returned values.

TRACE expression

prints a literal or an expression. If necessary, the value of the expression is calculated before it is sent to the file.

The following example shows how you can use the TRACE statement in an SPL function.

Figure 14-106

Figure 14-106 demonstrates how the TRACE statement can help you monitor how the function executes.

With the TRACE ON statement, each time you execute the traced routine, entries are added to the file you specified in the SET DEBUG FILE statement. To see the debug entries, view the output file with any text editor.

The following list contains some of the output generated by the function in Figure 14-106. Next to each traced statement is an explanation of its contents.

TRACE ON

echoes TRACE ON statement.

TRACE Foreach starts

traces expression, in this case, the literal string Foreach starts.

start select cursor

provides notification that a cursor is opened to handle a FOREACH loop.

select cursor iteration

provides notification of the start of each iteration of the select cursor.

expression: (+lcount, 1)

evaluates the encountered expression, (lcount+1), to 2.

let lcount = 2

echoes each LET statement with the value.




Informix Guide to SQL: Tutorial, version 9.1
Copyright © 1998, Informix Software, Inc. All rights reserved.