version 11
In 4D, there are two main possibilities for tracing and correcting your code: either using the Debugger to trace and correct any errors, or calling the ON ERR CALL command to catch the error and initiate the appropriate action. We can use both of these techniques to solve problems encountered with the SQL code.
Here is an example where a right parenthesis is missing intentionally: instead of HAVING SUM(Sold_Tickets <:$MinSoldTickets), we have HAVING SUM(Sold_Tickets <:$MinSoldTickets.
As you can see in the window below, the application detects the error and opens the Syntax Error Window which provides more detailed information about the error and the place where it occurred. It is then easy to fix by simply pressing the Edit button.
If the error is more complex, the application provides more information including the stack content, which can be displayed by pressing the Details button.
To test the above example, in the main window of the "4D SQL Code Samples" database, press the Debugging SQL code button.
The second main possibility for tracking SQL errors is using the ON ERR CALL command.
Here is an example that sets the SQL_Error_Handler method to catch errors encountered in the SQL code.
The SQL_Error_Handler method is as follows:
To test the above example, in the main window of the "4D SQL Code Samples" database, press the Using ON ERR CALL button.