Hello,
Is there a better way to return an OPEN-QUERY error ???
Not sure is what I have below is the best way. This code is running on an app server.
Without the IF error-status statement, if there is a problem with the vQuery it will continually post error log messages into our log file.
With the IF error-status statement, it randomly returns an error even though there is no problem with the query.
Thanks.
...
CREATE QUERY hdlRadioQuery.
hdlRadioQuery:
SET-BUFFERS(BUFFER cl3gComm:HANDLE, BUFFER cl3gDevice:HANDLE).
hdlRadioQuery:
QUERY-PREPARE(vQuery).
hdlRadioQuery:
QUERY-OPEN.
IF ERROR-STATUS:ERROR THEN DO:
RETURN ERROR 'Error opening query.'.
END.
...
Append NO-ERROR to your statements. You need to do that anyway since ERROR-STATUS returns the status of your last NO-ERROR. Since you don't have any you are getting unexpected results in this code. In addition you have error conditions that are not caught.
If you are on 10.1C+ you could also use structured error handling (CATCH).
ERROR-STATUS is only set for the last statement that was called with NO-ERROR. You don't have any NO-ERROR statements in your sample, so I imagine the the reason it appears random is because prior code has statements with NO-ERROR that may or may not be setting ERROR-STATUS:ERROR to true. A built-in method such as QUERY-OPEN will not set ERROR-STATUS:ERROR to true, but it will set messages, so you need to use the trick of checking NUM-MESSAGES instead of ERROR.
Of course you could use structured error handling and write a CATCH block to handle your error condition too.
Works great now!
Thanks.
Alternately, you can also code something like:
DEF VAR lOK AS LOG NO-UNDO.
lOK = hdlRadioQuery:QUERY-PREPARE(vQuery) NO-ERROR.
IF NOT lOK THEN...
or
IF ERROR-STATUS:ERROR THEN...
In other words (as mentioned in the "OpenEdge Reference Help" on QUERY-PREPARE() method):
You are absolutely right.