Wrong error number returned by SqlExtractArgs() when a user defined error is triggered

From Support Wiki

Jump to: navigation, search
Wrong error number returned by SqlExtractArgs() when a user defined error is triggered by ORACLE's raise_application_error()

by Jean-Marc Gemperle, May 29th 2002

Summary
To maintain portability and compatibility with SQLWindows a change was made to Team Developer 1.50 and it has introduced the above mentioned problem.

This document provides a workaround to this problem.

Environment
Team Developer 1.50 and above

Problem description
Execute an Oracle Stored procedure that raises an application error using the following line of code.

raise_application_error(-20111,'my message')

Then from Team Developer make the following call.

SqlExtractArgs(wParam, lParam, hSql, nSqlError, nErrorPos )

The function call will return a wrong value in variable nSqlError with Team Developer 1.50 and above. According to the above example the returned value will be -25425

Solution
Correct error number is stored in the LOWORD of nSqlError and can be extracted using the following function call.

SalNumberLow(nSqlError)

This function will return the right number 40111. Team Developer adds 20000 to Oracle error messages, so the actual Oracle error number returned will be
40111 - 20000 = 20111 and this is the error raised in the stored procedure with raise_application_error().